Back to index

plone3  3.1.7
test_kss_attributes.py
Go to the documentation of this file.
00001 from Testing import ZopeTestCase as ztc
00002 from Products.PloneTestCase import PloneTestCase as ptc
00003 from Products.PloneTestCase.layer import PloneSite
00004 from kss.core.BeautifulSoup import BeautifulSoup
00005 from Products.Five.testbrowser import Browser
00006 
00007 # XXX should not this be like this?
00008 #from plone.app.kss.tests.kss_and_plone_layer import KSSAndPloneTestCase
00009 #class TestKSSAttributes(KSSAndPloneTestCase, ptc.FunctionalTestCase):
00010 class TestKSSAttributes(ptc.FunctionalTestCase):
00011     
00012     BeautifulSoup = BeautifulSoup
00013 
00014     def afterSetUp(self):
00015         self.folder.invokeFactory('Document', 'page')
00016         self.page = self.folder.page
00017         self.page.setTitle('My title')
00018         self.page.setDescription('My description')
00019         self.page.setText('<p>My text</p>')
00020         self.user = ptc.default_user
00021         self.password = ptc.default_password
00022         self.browser = Browser()
00023 
00024 class TestForKSSInlineEditing:
00025       
00026     def test_notLogged():
00027         r"""
00028        
00029         We publish the page.
00030 
00031             >>> self.portal.portal_workflow.doActionFor(self.page, 'submit')
00032             >>> self.loginAsPortalOwner()
00033             >>> self.portal.portal_workflow.doActionFor(self.page, 'publish')
00034             >>> self.logout()
00035 
00036         We call it.
00037         
00038             >>> self.browser.open(self.page.absolute_url())
00039             >>> soup = self.BeautifulSoup(self.browser.contents)
00040         
00041         We find the title tag.
00042         
00043             >>> title = soup.find(id='parent-fieldname-title')
00044             >>> title is not None
00045             True
00046         
00047         We see that the KSS hooks shouldn't be there because we're not
00048         logged in!
00049         
00050             >>> 'kssattr-atfieldname-' in title['class']
00051             False
00052             >>> 'kssattr-templateId-' in title['class']
00053             False
00054             >>> 'kssattr-macro-' in title['class']
00055             False
00056             >>> 'inlineEditable' in title['class']
00057             False
00058         """
00059 
00060     def test_logged():
00061         r"""
00062         
00063         Okay, we don't go straight away for the page but we actually
00064         do authenticate
00065         
00066             >>> self.browser.addHeader(
00067             ...    'Authorization', 'Basic %s:%s' % (self.user, self.password))
00068             >>> self.browser.open(self.page.absolute_url())
00069             >>> soup = self.BeautifulSoup(self.browser.contents)
00070         
00071         We find the title
00072         
00073             >>> title = soup.find(id='parent-fieldname-title')
00074             >>> title is not None
00075             True
00076         
00077         We check everything is in now, especially that
00078         ``kssattr-fieldname-`` matched the right field, and is not
00079         only there, but actually makes some sense
00080         Also, we check that the class is ``inlineEditable`` because our KSS
00081         hooks there (look at at.kss for details)
00082         
00083             >>> 'kssattr-atfieldname-title' in title['class']
00084             True
00085             >>> 'kssattr-templateId-' in title['class']
00086             True
00087             >>> 'kssattr-macro-' in title['class']
00088             True
00089             >>> 'inlineEditable' in title['class']
00090             True
00091 
00092         Rerun, description now! (which is not a Francis Ford Coppola's
00093         movie)
00094         
00095             >>> description = soup.find(
00096             ...    id='parent-fieldname-description')
00097             >>> description is not None
00098             True
00099             >>> 'kssattr-atfieldname-description' in description['class']
00100             True
00101             >>> 'kssattr-templateId-' in description['class']
00102             True
00103             >>> 'kssattr-macro-' in description['class']
00104             True
00105             >>> 'inlineEditable' in description['class']
00106             True
00107         
00108         Now, time for the text
00109         
00110             >>> text = soup.find(id='parent-fieldname-text')
00111             >>> text is not None
00112             True
00113             >>> 'kssattr-atfieldname-text' in text['class']
00114             True
00115             >>> 'kssattr-templateId-' in text['class']
00116             True
00117             >>> 'kssattr-macro-' in text['class']
00118             True
00119             >>> 'inlineEditable' in text['class']
00120             True
00121         """
00122 
00123 class TestContentsTabs:
00124     def test_tab_ids():
00125         r"""
00126         Okay, we don't go straight away for the page but we actually
00127         do authenticate
00128         
00129             >>> self.browser.addHeader(
00130             ...    'Authorization', 'Basic %s:%s' % (self.user, self.password))
00131             >>> self.browser.open(self.page.absolute_url())
00132             >>> soup = self.BeautifulSoup(self.browser.contents)
00133         
00134         The content tabs must have li tags with special ids:
00135 
00136             >>> soup.find('li', dict(id='contentview-view')) is not None
00137             True
00138             >>> soup.find('li', dict(id='contentview-edit')) is not None
00139             True
00140             >>> soup.find('li', dict(id='contentview-local_roles')) is not None
00141             True
00142             >>> soup.find('li', dict(id='contentview-history')) is not None
00143             True
00144         """
00145 
00146     def test_ul_id():
00147         r"""
00148         We actually authenticate and we'll doing some tests about ul id (which it should be present)
00149         
00150             >>> self.browser.addHeader(
00151             ...    'Authorization', 'Basic %s:%s' % (self.user, self.password))
00152             >>> self.browser.open(self.page.absolute_url())
00153             >>> soup = self.BeautifulSoup(self.browser.contents)
00154         
00155         The content tabs must have li tags with special ids:
00156         Checking for the correct ul tag class
00157 
00158             >>> content_ul_tag = soup.find('ul', {'class':'contentViews'})
00159             >>> content_ul_tag is not None
00160             True 
00161           
00162         a tags inside of the li tags shouldn't have ids; li tags should have id attributes
00163 
00164             >>> [a.get('id') for a in content_ul_tag.findAll('a')]
00165             [None, None, None, None]
00166             >>> [li.get('id') for li in content_ul_tag.findAll('li')]
00167             [u'contentview-view', u'contentview-edit', u'contentview-local_roles', u'contentview-history']
00168 
00169         """
00170     
00171 class TestContentMenu:
00172     def test_menu_presence():
00173         r"""
00174         We must authenticate because content menu is only present for logged in users
00175         
00176             >>> self.browser.addHeader(
00177             ...  'Authorization', 'Basic %s:%s' % (self.user, self.password))
00178             >>> self.browser.open(self.page.absolute_url())
00179             >>> soup = self.BeautifulSoup(self.browser.contents)
00180           
00181         We are in a page so we must have the "change workflow" menu.
00182         
00183             >>> contentmenu_dl_tag = soup.find('dl', {'id':'plone-contentmenu-workflow'})
00184             >>> contentmenu_dl_tag is not None
00185             True
00186 
00187             >>> contentmenu_dl_tag.find('dd',{'class':'actionMenuContent'}) is not None
00188             True  
00189           
00190         Then you must have the copy and cut links
00191         
00192             >>> soup.find('a', {'class':'actionicon-object_buttons-cut'}) is not None
00193             True
00194             
00195             >>> soup.find('a', {'class':'actionicon-object_buttons-copy'}) is not None
00196             True
00197         
00198         Now we go to the folder, so we must have the "change view" menu.
00199             
00200             >>> self.browser.open(self.folder.absolute_url())
00201             >>> soup = self.BeautifulSoup(self.browser.contents)    
00202             >>> contentmenu_dl_tag = soup.find('dl', {'id':'plone-contentmenu-display'})
00203             >>> contentmenu_dl_tag is not None
00204             True
00205 
00206             >>> contentmenu_dl_tag.find('dd',{'class':'actionMenuContent'}) is not None
00207             True
00208           
00209         A couple of things again, basically the stuff we hook on with kss, which are, the 
00210         external div and the inner ul (one is used for content replacement through innerHTML,
00211         the other used to hook events on load)
00212             
00213             >>> self.browser.open(self.folder.absolute_url())
00214             >>> soup = self.BeautifulSoup(self.browser.contents)
00215             
00216         Ok let's see if we have the hook to replace the content
00217             
00218             >>> content_td = soup.find('td', {'id': 'portal-column-content'})
00219             >>> content_td is not None
00220             True
00221             >>> content_actions = content_td.find('div', {'class': 'contentActions'})
00222             >>> content_actions is not None
00223             True
00224             
00225         This is great, now let's check if we have the bind load stuff in place too
00226             
00227             >>> content_actions_ul = content_actions.find('ul', {'id': 'contentActionMenus'})
00228             >>> content_actions_ul is not None
00229             True
00230 
00231         """
00232 
00233 def test_suite():
00234     suite = ztc.FunctionalDocTestSuite(test_class=TestKSSAttributes)
00235     suite.layer = PloneSite
00236     return suite