[1674] | 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 -*- |
---|
[1820] | 52 | Test 'SEO Properties' action |
---|
[1674] | 53 | =============================== |
---|
| 54 | |
---|
[1895] | 55 | Define some general objects: |
---|
[1849] | 56 | |
---|
[1895] | 57 | >>> qi = self.portal.portal_quickinstaller |
---|
| 58 | >>> object_tabs = self.portal.portal_actions.object |
---|
| 59 | >>> ps = self.portal.portal_setup |
---|
[1833] | 60 | |
---|
[1895] | 61 | Test is 'SEO Properties' action present for a Page before |
---|
| 62 | seoptimizer installed |
---|
[1833] | 63 | |
---|
[1820] | 64 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 65 | >>> "SEO Properties" in browser.contents |
---|
| 66 | False |
---|
[1895] | 67 | |
---|
| 68 | Now install the product for following testing, and add |
---|
| 69 | |
---|
| 70 | >>> qi.installProduct(PROJECT_NAME) |
---|
[1820] | 71 | 'Ran all install steps.' |
---|
[1895] | 72 | >>> sp = self.portal.portal_properties.seo_properties |
---|
| 73 | |
---|
| 74 | And check is SEOProperties added to object tabs |
---|
| 75 | |
---|
| 76 | >>> object_tabs.get('SEOProperties', None) is not None |
---|
[1820] | 77 | True |
---|
| 78 | |
---|
| 79 | Test visibility 'SEO Properties' action after installation |
---|
| 80 | |
---|
[1895] | 81 | >>> sp.content_types_with_seoproperties = ('Document',) |
---|
[1820] | 82 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 83 | >>> "SEO Properties" in browser.contents |
---|
| 84 | True |
---|
| 85 | >>> browser.getLink('SEO Properties').url |
---|
| 86 | 'http://nohost/plone/front-page/@@seo-context-properties' |
---|
| 87 | |
---|
| 88 | Test invisibility 'SEO Properties' action after installation |
---|
| 89 | |
---|
[1895] | 90 | >>> sp.content_types_with_seoproperties = ('File',) |
---|
[1820] | 91 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 92 | >>> "SEO Properties" in browser.contents |
---|
| 93 | False |
---|
| 94 | |
---|
| 95 | Test reinstallation 'SEO Properties' action |
---|
[1849] | 96 | For perform all upgrade steps on re-installation, earlier version of profile must be set. |
---|
[1820] | 97 | |
---|
| 98 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 99 | >>> "SEO Properties" in browser.contents |
---|
| 100 | False |
---|
[1895] | 101 | >>> ps.setLastVersionForProfile('quintagroup.seoptimizer:default', '2.0.0') |
---|
| 102 | >>> qi.reinstallProducts((PROJECT_NAME,)) |
---|
[1820] | 103 | >>> self.portal.portal_actions.object.get('SEOProperties', None) is not None |
---|
| 104 | True |
---|
| 105 | |
---|
| 106 | Test visibility 'SEO Properties' action after reinstallation |
---|
| 107 | |
---|
[1895] | 108 | >>> sp.content_types_with_seoproperties = ('Document',) |
---|
[1820] | 109 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 110 | >>> "SEO Properties" in browser.contents |
---|
| 111 | True |
---|
| 112 | >>> browser.getLink('SEO Properties').url |
---|
| 113 | 'http://nohost/plone/front-page/@@seo-context-properties' |
---|
| 114 | |
---|
| 115 | Test invisibility 'SEO Properties' action after reinstallation |
---|
| 116 | |
---|
[1895] | 117 | >>> sp.content_types_with_seoproperties = ('File',) |
---|
[1820] | 118 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 119 | >>> "SEO Properties" in browser.contents |
---|
| 120 | False |
---|
| 121 | |
---|
| 122 | Test uninstallation 'SEO Properties' action |
---|
| 123 | |
---|
[1895] | 124 | >>> sp.content_types_with_seoproperties = ('Document',) |
---|
[1820] | 125 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 126 | >>> "SEO Properties" in browser.contents |
---|
| 127 | True |
---|
[1895] | 128 | >>> qi.uninstallProducts((PROJECT_NAME,)) |
---|
| 129 | >>> object_tabs.get('SEOProperties', None) is not None |
---|
[1820] | 130 | False |
---|
| 131 | |
---|
| 132 | Test visibility 'SEO Properties' action after uninstallation |
---|
| 133 | |
---|
[1895] | 134 | >>> sp.content_types_with_seoproperties = ('Document',) |
---|
[1820] | 135 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 136 | >>> "SEO Properties" in browser.contents |
---|
| 137 | False |
---|