'Tests page_language_url templatetag behavior when used on a page
without the requested translation, both when CMS_HIDE_UNTRANSLATED is
True and False.
When True it should return the root page URL if the current page is
untranslated (PR #1125)'

def test_untranslated_language_url(self):

    page_1 = create_page('Page    1', 'nav_playground.html', 'en', published=True, in_navigation=True, reverse_id='page1')
    create_title('de', 'Seite    1', page_1, slug='seite-1')
    page_1.publish('en')
    page_1.publish('de')
    page_2 = create_page('Page    2', 'nav_playground.html', 'en', page_1, published=True, in_navigation=True, reverse_id='page2')
    create_title('de', 'Seite    2', page_2, slug='seite-2')
    page_2.publish('en')
    page_2.publish('de')
    page_3 = create_page('Page    3', 'nav_playground.html', 'en', page_2, published=True, in_navigation=True, reverse_id='page3')
    tpl = "{%    load    menu_tags    %}{%    page_language_url    'de'    %}"
    lang_settings = deepcopy(get_cms_setting('LANGUAGES'))
    lang_settings[1][1]['hide_untranslated'] = False
    with self.settings(CMS_LANGUAGES=lang_settings):
        context = self.get_context(page_2.get_absolute_url())
        context['request'].current_page = page_2
        res = self.render_template_obj(tpl, context.__dict__, context['request'])
        self.assertEqual(res, '/de/seite-2/')
        context = self.get_context(page_2.get_absolute_url())
        context['request'].current_page = page_2.publisher_public
        res = self.render_template_obj(tpl, context.__dict__, context['request'])
        self.assertEqual(res, '/de/seite-2/')
        context = self.get_context(page_3.get_absolute_url())
        context['request'].current_page = page_3.publisher_public
        res = self.render_template_obj(tpl, context.__dict__, context['request'])
        self.assertEqual(res, '/de/page-3/')
    lang_settings[1][1]['hide_untranslated'] = True
    with self.settings(CMS_LANGUAGES=lang_settings):
        context = self.get_context(page_2.get_absolute_url())
        context['request'].current_page = page_2.publisher_public
        res = self.render_template_obj(tpl, context.__dict__, context['request'])
        self.assertEqual(res, '/de/seite-2/')
        context = self.get_context(page_3.get_absolute_url())
        context['request'].current_page = page_3.publisher_public
        res = self.render_template_obj(tpl, context.__dict__, context['request'])
        self.assertEqual(res, '/de/')
