'Tests language_fallback placeholder configuration for nested plugins'

def test_nested_plugins_language_fallback(self):

    page_en = create_page('page_en', 'col_two.html', 'en')
    title_de = create_title('de', 'page_de', page_en)
    placeholder_en = page_en.placeholders.get(slot='col_left')
    placeholder_de = title_de.page.placeholders.get(slot='col_left')
    link_en = add_plugin(placeholder_en, 'LinkPlugin', 'en', name='en    name', external_link='http://example.com/en')
    add_plugin(placeholder_en, 'TextPlugin', 'en', target=link_en, body='en    body')
    context_en = SekizaiContext()
    context_en['request'] = self.get_request(language='en', page=page_en)
    context_de = SekizaiContext()
    context_de['request'] = self.get_request(language='de', page=page_en)
    conf = {'col_left': {'language_fallback': True}}
    with self.settings(CMS_PLACEHOLDER_CONF=conf):
        content_de = _render_placeholder(placeholder_de, context_de)
        self.assertRegexpMatches(content_de, '<a    href="http://example.com/en"')
        self.assertRegexpMatches(content_de, 'en    body')
        context_de2 = SekizaiContext()
        request = self.get_request(language='de', page=page_en)
        request.user = self.get_superuser()
        request.toolbar = CMSToolbar(request)
        request.toolbar.edit_mode = True
        context_de2['request'] = request
        del placeholder_de._plugins_cache
        cache.clear()
        content_de2 = _render_placeholder(placeholder_de, context_de2)
        self.assertFalse(('en    body' in content_de2))
        del placeholder_de._plugins_cache
        cache.clear()
        link_de = add_plugin(placeholder_en, 'LinkPlugin', language='de', name='de    name', external_link='http://example.com/de')
        add_plugin(placeholder_en, 'TextPlugin', 'de', target=link_de, body='de    body')
        content_de = _render_placeholder(placeholder_de, context_de)
        self.assertRegexpMatches(content_de, '<a    href="http://example.com/de"')
        self.assertRegexpMatches(content_de, 'de    body')
