def test_viewlet_render(self):
        """Validate that the alternate languages viewlet renders correctly."""
        try:
            from plone.app.multilingual.setuphandlers import (
                enable_translatable_behavior,
            )
        except ImportError:
            pass
        else:
            enable_translatable_behavior(self.portal)

        sample_en = self.portal['en']['sample-folder']
        sample_de = translate(sample_en, 'de')
        viewlet_orig = AlternateLanguagesViewlet(
            sample_de,
            self.app.REQUEST,
            None,
            None,
        )
        viewlet_orig.update()

        viewlet = CustomAlternateLanguagesViewlet(
            sample_de,
            self.app.REQUEST,
            None,
            None,
        )
        viewlet.update()
        self.assertTrue(len(viewlet.alternates), 3)
    def test_alternates(self):
        # Create
        a_ca = createContentInContainer(
            self.portal['ca'], 'Document', title=u"Test document")

        # Translate
        a_en = api.translate(a_ca, 'en')

        # Get the viewlet
        viewlet = AlternateLanguagesViewlet(a_en, self.request, None, None)
        viewlet.update()

        # Get translations
        translations = ITranslationManager(a_ca).get_translations()

        # Check translations
        self.assertEqual(len(viewlet.alternates), 2)
        for item in viewlet.alternates:
            self.assertIn(item['lang'], translations)
            self.assertEqual(
                "{0}/{1}/{2}".format(
                    self.portal.absolute_url(),
                    item['lang'],
                    item['url']),
                translations[item['lang']].absolute_url()
            )
    def _validate_alternates(self, context):

        # Get the viewlet
        viewlet = AlternateLanguagesViewlet(context, self.request, None, None)
        viewlet.update()

        # Get translations
        translations = ITranslationManager(context).get_translations()

        for item in viewlet.alternates:
            self.assertIn(item['lang'], translations)
            self.assertEqual("{0}/{1}".format(viewlet.site_url, item['url']),
                             translations[item['lang']].absolute_url())