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)
    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)
    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)
    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