'Tests the logount AjaxItem on_success parameter in four different conditions:
* published page: no redirect
* unpublished page: redirect to the home page
* published page with login_required: redirect to the home page
* published page with view permissions: redirect to the home page'

@override_settings(CMS_PERMISSION=True)
def test_toolbar_logout_redirect(self):

    superuser = self.get_superuser()
    page0 = create_page('home', 'nav_playground.html', 'en', published=True)
    page1 = create_page('internal', 'nav_playground.html', 'en', published=True, parent=page0)
    page2 = create_page('unpublished', 'nav_playground.html', 'en', published=False, parent=page0)
    page3 = create_page('login_restricted', 'nav_playground.html', 'en', published=True, parent=page0, login_required=True)
    page4 = create_page('view_restricted', 'nav_playground.html', 'en', published=True, parent=page0)
    PagePermission.objects.create(page=page4, can_view=True, user=superuser)
    page4.publish('en')
    page4 = page4.get_public_object()
    self.get_page_request(page4, superuser, '/')
    with self.login_user_context(superuser):
        response = self.client.get((page1.get_absolute_url('en') + ('?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))))
        toolbar = response.context['request'].toolbar
        menu_name = (_(u'Logout    %s') % self.get_username(superuser))
        admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
        self.assertTrue(admin_menu.find_first(AjaxItem, name=menu_name).item.on_success)
        response = self.client.get((page2.get_absolute_url('en') + ('?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))))
        toolbar = response.context['request'].toolbar
        admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
        self.assertEquals(admin_menu.find_first(AjaxItem, name=menu_name).item.on_success, '/')
        response = self.client.get((page3.get_absolute_url('en') + ('?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))))
        toolbar = response.context['request'].toolbar
        admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
        self.assertEquals(admin_menu.find_first(AjaxItem, name=menu_name).item.on_success, '/')
        response = self.client.get((page4.get_absolute_url('en') + ('?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))))
        toolbar = response.context['request'].toolbar
        admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
        self.assertEquals(admin_menu.find_first(AjaxItem, name=menu_name).item.on_success, '/')
