Esempio n. 1
0
    def test_render_mobile_override(self):
        """ Render a document with mobile overrides enabled.

        """

        self.setDiscriminateMode("mobile")

        self.create_doc()
        doc = self.portal.doc
        doc.setTitle("Not reached") # This title should not be visible in mobile mode
        overrider = IOverrider(doc)
        storage = IOverrideStorage(doc)
        storage.enabled_overrides = ["Title"]
        storage.Title = u"Foobar"

        self.portal.portal_workflow.doActionFor(doc, "submit")
        self.portal.portal_workflow.doActionFor(doc, "publish")


        browser = self.browser
        browser.open(self.portal.doc.absolute_url())
        html = browser.contents

        self.assertTrue(MOBILE_HTML_MARKER in html, "Got page:" + html)
        assert "Foobar" in html
    def test_has_overrides(self):
        """ Document object overrides are enabled by default
        """
        self.create_doc()
        doc = self.portal.doc
        overrider = IOverrider(doc)
        assert overrider != None

        assert overrider.schema != None
        self.assertEqual(overrider._getOverrideFieldNames(), ["Title", "Description", "getText"])

        # Set one override enabled and check it is read properly
        storage = IOverrideStorage(doc)

        storage.enabled_overrides = ["Title"]
        self.assertEqual(overrider._isOverrideEnabled("Title", storage), True)
        self.assertEqual(overrider._isOverrideEnabled("Description", storage), False)

        # Set overriden title
        storage.Title = u"Foobar"

        # Call title accessor by emulator IOverrider steps
        # and see each microstep completes
        self.assertTrue(overrider._isOverride("Title"))
        storage = IOverrideStorage(self.portal.doc)
        self.assertTrue(overrider._isOverrideEnabled("Title", storage))
        self.assertEqual(overrider._getOverrideOrOrignal("Title")(), u"Foobar")

        assert overrider.Title() == u"Foobar"
Esempio n. 3
0
    def test_cooked_mobile_template(self):
        """ Check that mobile specific template is rendered for mobile.
        """
        self.create_doc()
        doc = self.portal.doc


        overrider = IOverrider(doc)

        doc.setTitle("Foobar")

        storage = IOverrideStorage(doc)
        storage.enabled_overrides = ["getUnfilteredTemplate"]
        storage.getUnfilteredTemplate = u"Title {{ context.Title() }}"

        self.setDiscriminateMode("mobile")
        zope.interface.alsoProvides(self.portal.REQUEST, IMobileLayer)

        # This should be views.EasyTemplateMobileView
        self.browser.open(self.portal.doc.absolute_url())
        html = self.browser.contents

        if "The page structure contains errors" in html:

            messages = IStatusMessage(self.portal.REQUEST).showStatusMessages()

            if messages:
                for m in messages: print str(m.message)


            raise RuntimeError("Bad templated page")

        self.assertTrue(MOBILE_HTML_MARKER in html) # See that we are rendering mobile mode
        self.assertTrue("Title Foobar" in html)
Esempio n. 4
0
    def test_override_template(self):
        """
        """
        self.create_doc()
        doc = self.portal.doc
        overrider = IOverrider(doc)

        doc.setTitle("Foobar")

        template = u"Title {{ context.Title() }}"
        storage = IOverrideStorage(doc)
        storage.enabled_overrides = ["getUnfilteredTemplate"]
        storage.getUnfilteredTemplate = template

        self.assertEqual(overrider.getUnfilteredTemplate(), template)
Esempio n. 5
0
    def test_override_not_enabled(self):
        """ Do not enable override, but have the field filled in
        """

        self.setDiscriminateMode("web")

        self.create_doc()
        doc = self.portal.doc
        overrider = IOverrider(doc)

        doc.setTitle("Foobar")

        template = u"Title {{context.Title()}}"
        storage = IOverrideStorage(doc)
        storage.getUnfilteredTemplate = template

        self.assertNotEqual(overrider.getUnfilteredTemplate(), template)
Esempio n. 6
0
    def test_helper_view_web(self):
        """
        See that we get proper proxy object through helper view.
        """
        self.setDiscriminateMode(MobileRequestType.WEB)
        self.create_doc()
        doc = self.portal.doc
        doc.setTitle("Not reached")
        overrider = IOverrider(doc)
        storage = IOverrideStorage(doc)
        storage.enabled_overrides = ["Title"]
        storage.Title = u"Foobar"

        helper = doc.restrictedTraverse("multichannel_overrider")
        context = helper() # Return mobile proxy object with overriden values

        # In web mode, you dont get override
        self.assertEqual(context.Title(), "Not reached")
Esempio n. 7
0
    def test_cooked_mobile_template_should_not_appear_web(self):
        """
        Even if we set mobile override template, it should not affect web viewing any how.
        """
        self.create_doc()
        doc = self.portal.doc
        overrider = IOverrider(doc)

        doc.setTitle("Foobar")

        storage = IOverrideStorage(doc)
        storage.getUnfilteredTemplate = u"Title {{ context.Title() }}"

        self.setDiscriminateMode("web")
        self.browser.open(self.portal.doc.absolute_url())
        html = self.browser.contents # This should be document_view.pt
        print html
        self.assertFalse(MOBILE_HTML_MARKER in html) # See that we are rendering mobile mode
        self.assertFalse("Title Foobar" in html) # In web we do not run the snippet