diff --git a/trac/tests/functional/tester.py b/trac/tests/functional/tester.py
index b983e1b..24a06e5 100755
--- a/trac/tests/functional/tester.py
+++ b/trac/tests/functional/tester.py
@@ -176,6 +176,7 @@ class FunctionalTester(object):
             tc.formvalue('attachment', 'replace', True)
         tc.submit()
         tc.url(self.url + '/attachment/ticket/%s/$' % ticketid)
+        return tempfilename
 
     def clone_ticket(self, ticketid):
         """Create a clone of the given ticket id using the clone button."""
@@ -232,6 +233,7 @@ class FunctionalTester(object):
         tc.formvalue('attachment', 'description', random_sentence())
         tc.submit()
         tc.url(self.url + '/attachment/wiki/%s/$' % name)
+        return tempfilename
 
     def create_milestone(self, name=None, due=None):
         """Creates the specified milestone, with a random name if none is
diff --git a/trac/wiki/tests/functional.py b/trac/wiki/tests/functional.py
index bd85ec8..07a290e 100755
--- a/trac/wiki/tests/functional.py
+++ b/trac/wiki/tests/functional.py
@@ -12,6 +12,66 @@ class TestWiki(FunctionalTwillTestCaseSetup):
         self._tester.attach_file_to_wiki(pagename)
 
 
+class TestWikiRename(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for simple wiki rename"""
+        pagename = random_unique_camel()
+        self._tester.create_wiki_page(pagename)
+        self._tester.rename_wiki_page(pagename)
+        attachment = self._tester.attach_file_to_wiki(pagename)
+        base_url = self._tester.url
+        page_url = base_url + "/wiki/" + pagename
+        
+        def click_rename():
+            tc.formvalue('rename', 'action', 'rename')
+            tc.submit()
+            tc.url(page_url+r'\?action=rename')
+            tc.find("New name:")
+        
+        tc.go(page_url)
+        tc.find("Rename page")
+        click_rename()
+        # attempt to rename the page to the current page name ...        
+        tc.formvalue(page_url, 'new_name', 'rename')
+        tc.submit('rename')
+        tc.url(page_url)
+        tc.find("New name must be different from old name.")
+        # attempt to rename the page to an existing page name ...
+        tc.formvalue(page_url, 'new_name', 'WikiStart')
+        tc.submit('rename')
+        tc.url(page_url)
+        tc.find("Trac Error")
+        tc.find("Can't rename to existing WikiStart page")
+        # correct rename to new page name (old page replaced by a redirection)
+        tc.go(page_url)
+        click_rename()
+        newpagename = pagename+'Renamed'
+        tc.formvalue(page_url, 'new_name', newpagename)
+        tc.formvalue(page_url, 'leave_redirection', True) # the default
+        tc.submit('rename')
+        # check redirection page
+        tc.url(page_url)
+        tc.find("See.*/wiki/"+newpagename)
+        # check whether attachment exists on the new page but not on old page
+        tc.go(base_url+'/attachment/wiki/'+newpagename+'/'+attachment)
+        tc.notfind("Error: Invalid Attachment")
+        tc.go(base_url+'/attachment/wiki/'+pagename+'/'+attachment)
+        tc.find("Error: Invalid Attachment")
+        # rename again to another new page name (this time, no redirection)
+        tc.go(page_url)
+        click_rename()
+        newpagename = pagename+'RenamedAgain'
+        tc.formvalue(page_url, 'new_name', newpagename)
+        tc.formvalue(page_url, 'leave_redirection', False)
+        tc.submit('rename')
+        tc.url(base_url + "/wiki/" + newpagename)
+        # this time, the original page is gone
+        tc.go(page_url)
+        tc.url(page_url)
+        tc.find("Describe %s here" % pagename)
+        
+
+
 class RegressionTestTicket4812(FunctionalTwillTestCaseSetup):
     def runTest(self):
         """Test for regression of http://trac.edgewall.org/ticket/4812"""

