[3008] | 1 | Introduction |
---|
| 2 | ============ |
---|
| 3 | |
---|
| 4 | This is a full-blown functional test. The emphasis here is on testing what |
---|
| 5 | the user may input and see, and the system is largely tested as a black box. |
---|
| 6 | We use PloneTestCase to set up this test as well, so we have a full Plone site |
---|
| 7 | to play with. We *can* inspect the state of the portal, e.g. using |
---|
| 8 | self.portal and self.folder, but it is often frowned upon since you are not |
---|
| 9 | treating the system as a black box. Also, if you, for example, log in or set |
---|
| 10 | roles using calls like self.setRoles(), these are not reflected in the test |
---|
| 11 | browser, which runs as a separate session. |
---|
| 12 | |
---|
| 13 | Being a doctest, we can tell a story here. |
---|
| 14 | |
---|
| 15 | First, we must perform some setup. We use the testbrowser that is shipped |
---|
| 16 | with Five, as this provides proper Zope 2 integration. Most of the |
---|
| 17 | documentation, though, is in the underlying zope.testbrower package. |
---|
| 18 | |
---|
| 19 | >>> from Products.Five.testbrowser import Browser |
---|
| 20 | >>> browser = Browser() |
---|
| 21 | >>> portal_url = self.portal.absolute_url() |
---|
| 22 | |
---|
| 23 | The following is useful when writing and debugging testbrowser tests. It lets |
---|
| 24 | us see all error messages in the error_log. |
---|
| 25 | |
---|
| 26 | >>> self.portal.error_log._ignored_exceptions = () |
---|
| 27 | |
---|
| 28 | With that in place, we can go to the portal front page and log in. We will |
---|
| 29 | do this using the default user from PloneTestCase: |
---|
| 30 | |
---|
| 31 | >>> from Products.PloneTestCase.setup import portal_owner, default_password |
---|
| 32 | >>> browser.open(portal_url) |
---|
| 33 | |
---|
| 34 | We have the login portlet, so let's use that. |
---|
| 35 | |
---|
| 36 | >>> browser.open('http://nohost/plone/login_form') |
---|
| 37 | >>> browser.getLink('Log in').click() |
---|
| 38 | >>> browser.url |
---|
| 39 | 'http://nohost/plone/login_form' |
---|
| 40 | >>> browser.getControl('Login Name').value = portal_owner |
---|
| 41 | >>> browser.getControl('Password').value = default_password |
---|
| 42 | >>> browser.getControl('Log in').click() |
---|
| 43 | >>> "You are now logged in" in browser.contents |
---|
| 44 | True |
---|
| 45 | >>> "Login failed" in browser.contents |
---|
| 46 | False |
---|
| 47 | >>> browser.url |
---|
| 48 | 'http://nohost/plone/login_form' |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | -*- extra stuff goes here -*- |
---|
| 52 | Test 'SEO Properties' in action |
---|
| 53 | =============================== |
---|
| 54 | |
---|
| 55 | Let's define some helpfull variables: |
---|
| 56 | |
---|
| 57 | >>> page = self.portal["front-page"] |
---|
| 58 | >>> page_url = page.absolute_url() |
---|
| 59 | >>> seoprops_url = page_url + "/@@seo-context-properties" |
---|
| 60 | |
---|
| 61 | Test wheter 'SEO Properties' tab is visible on front page or not. |
---|
| 62 | |
---|
| 63 | >>> browser.open(page_url) |
---|
| 64 | >>> "SEO Properties" in browser.contents |
---|
| 65 | True |
---|
| 66 | |
---|
| 67 | Now, let's go to the "SEO Properties" page, make some changes |
---|
| 68 | and click on "Cansel" button. |
---|
| 69 | |
---|
| 70 | >>> browser.open(seoprops_url) |
---|
| 71 | >>> browser.getControl(name="seo_description_override").value = True |
---|
| 72 | >>> descr_ctrl = browser.getControl(name="seo_description") |
---|
| 73 | >>> descr_ctrl.value = "Test change of SEO description" |
---|
| 74 | >>> browser.getControl("Cancel").click() |
---|
| 75 | >>> cancel_page = browser.contents |
---|
| 76 | >>> file("/tmp/seo_props.cancel.html","wb").write(cancel_page) |
---|
| 77 | |
---|
| 78 | Clicking on "Cancel" button should lead us to the front-page view. |
---|
| 79 | |
---|
| 80 | >>> browser.url == page_url |
---|
| 81 | True |
---|
| 82 | |
---|
| 83 | No changes must be applied. |
---|
| 84 | |
---|
| 85 | >>> not "Test change of SEO description" in cancel_page |
---|
| 86 | True |
---|
| 87 | |
---|
| 88 | Check whether status message is correct or not? |
---|
| 89 | |
---|
| 90 | >>> "No content SEO properties have been changed." in cancel_page |
---|
| 91 | True |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | Let's review other situation. Go to the "SEO Properties" page, make some changes |
---|
| 95 | and click on "Save" button. |
---|
| 96 | |
---|
| 97 | >>> browser.open(seoprops_url) |
---|
| 98 | >>> browser.getControl(name="seo_description_override").value = True |
---|
| 99 | >>> descr_ctrl = browser.getControl(name="seo_description") |
---|
| 100 | >>> descr_ctrl.value = "Test change of SEO description" |
---|
| 101 | >>> browser.getControl("Save").click() |
---|
| 102 | >>> save_page = browser.contents |
---|
| 103 | |
---|
| 104 | No changes must be applied. |
---|
| 105 | |
---|
| 106 | >>> "Test change of SEO description" in save_page |
---|
| 107 | True |
---|
| 108 | |
---|
| 109 | Check whether status message is correct or not? |
---|
| 110 | |
---|
| 111 | >>> "Content SEO properties have been saved" in save_page |
---|
| 112 | True |
---|