Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -0,0 +1,44 @@
<?php
/**
* @file
* Contains \Drupal\toolbar\Ajax\SetSubtreesCommand.
*/
namespace Drupal\toolbar\Ajax;
use Drupal\Core\Ajax\CommandInterface;
/**
* Defines an AJAX command that sets the toolbar subtrees.
*/
class SetSubtreesCommand implements CommandInterface {
/**
* The toolbar subtrees.
*
* @var array
*/
protected $subtrees;
/**
* Constructs a SetSubtreesCommand object.
*
* @param array $subtrees
* The toolbar subtrees that will be set.
*/
public function __construct($subtrees) {
$this->subtrees = $subtrees;
}
/**
* {@inheritdoc}
*/
public function render() {
return [
'command' => 'setToolbarSubtrees',
'subtrees' => array_map('strval', $this->subtrees),
];
}
}

View file

@ -8,8 +8,9 @@
namespace Drupal\toolbar\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\toolbar\Ajax\SetSubtreesCommand;
/**
* Defines a controller for the toolbar module.
@ -17,14 +18,14 @@ use Symfony\Component\HttpFoundation\JsonResponse;
class ToolbarController extends ControllerBase {
/**
* Returns the rendered subtree of each top-level toolbar link.
* Returns an AJAX response to render the toolbar subtrees.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @return \Drupal\Core\Ajax\AjaxResponse
*/
public function subtreesJsonp() {
$subtrees = toolbar_get_rendered_subtrees();
$response = new JsonResponse($subtrees);
$response->setCallback('Drupal.toolbar.setSubtrees.resolve');
public function subtreesAjax() {
list($subtrees, $cacheability) = toolbar_get_rendered_subtrees();
$response = new AjaxResponse();
$response->addCommand(new SetSubtreesCommand($subtrees));
// The Expires HTTP header is the heart of the client-side HTTP caching. The
// additional server-side page cache only takes effect when the client
@ -46,14 +47,12 @@ class ToolbarController extends ControllerBase {
*
* @param string $hash
* The hash of the toolbar subtrees.
* @param string $langcode
* The langcode of the requested site, NULL if none given.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function checkSubTreeAccess($hash, $langcode) {
return AccessResult::allowedIf($this->currentUser()->hasPermission('access toolbar') && $hash == _toolbar_get_subtrees_hash($langcode))->cachePerPermissions();
public function checkSubTreeAccess($hash) {
return AccessResult::allowedIf($this->currentUser()->hasPermission('access toolbar') && $hash == _toolbar_get_subtrees_hash()[0])->cachePerPermissions();
}
}

View file

@ -9,6 +9,7 @@ namespace Drupal\toolbar\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
@ -118,7 +119,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
// Enable a module.
$edit = array();
$edit['modules[Core][taxonomy][enable]'] = TRUE;
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->rebuildContainer();
// Assert that the subtrees hash has been altered because the subtrees
@ -209,98 +210,11 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->assertEqual($admin_user_2_hash, $new_subtree_hash, 'The user-specific subtree menu hash has not been updated.');
}
/**
* Tests that all toolbar cache entries for a user are cleared with a cache
* tag for that user, i.e. cache entries for all languages for that user.
*/
function testCacheClearByCacheTag() {
// Test that the toolbar admin menu subtrees cache is invalidated for a user
// across multiple languages.
$this->drupalLogin($this->adminUser);
$toolbarCache = $this->container->get('cache.toolbar');
$admin_user_id = $this->adminUser->id();
$admin_user_2_id = $this->adminUser2->id();
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'en');
$this->assertEqual(in_array('user:' . $admin_user_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "en".');
// Assert that no toolbar cache exists for adminUser against the
// language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
// Install a second language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
// Request a page in 'fr' to update the cache.
$this->drupalGet('fr/test-page');
$this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
$this->assertEqual(in_array('user:' . $admin_user_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "fr".');
// Log in the adminUser2 user. We will use this user as a control to
// verify that clearing a cache tag for adminUser does not clear the cache
// for adminUser2.
$this->drupalLogin($this->adminUser2);
// Request a page in 'en' to create the cache.
$this->drupalGet('test-page');
$this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser2 against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
$this->assertEqual(in_array('user:' . $admin_user_2_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
// Request a page in 'fr' to create the cache.
$this->drupalGet('fr/test-page');
$this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
$this->assertEqual(in_array('user:' . $admin_user_2_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
// Log in the admin user and clear the caches for this user using a tag.
$this->drupalLogin($this->adminUser);
Cache::invalidateTags(array('user:' . $admin_user_id));
// Assert that no toolbar cache exists for adminUser against the
// language "en".
$cache = $toolbarCache->get($admin_user_id . ':' . 'en');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "en".');
// Assert that no toolbar cache exists for adminUser against the
// language "fr".
$cache = $toolbarCache->get($admin_user_id . ':' . 'fr');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
// Log in adminUser2 and verify that this user's caches still exist.
$this->drupalLogin($this->adminUser2);
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser2 against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
$this->assertEqual(in_array('user:' . $admin_user_2_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser2 against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
$this->assertEqual(in_array('user:' . $admin_user_2_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
}
/**
* Tests that changes to a user account by another user clears the changed
* account's toolbar cached, not the user's who took the action.
*/
function testNonCurrentUserAccountUpdates() {
$toolbarCache = $this->container->get('cache.toolbar');
$admin_user_id = $this->adminUser->id();
$admin_user_2_id = $this->adminUser2->id();
$this->hash = $this->getSubtreesHash();
@ -337,9 +251,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
* Tests that toolbar cache is cleared when string translations are made.
*/
function testLocaleTranslationSubtreesHashCacheClear() {
$toolbarCache = $this->container->get('cache.toolbar');
$admin_user = $this->adminUser;
$admin_user_id = $this->adminUser->id();
// User to translate and delete string.
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
@ -373,11 +285,6 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->drupalGet($langcode . '/test-page');
$this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists
// for adminUser against the language "xx".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . $langcode);
$this->assertEqual(in_array('user:' . $admin_user_id, $cache->tags), 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "xx".');
// Get a baseline hash for the admin menu subtrees before translating one
// of the menu link items.
$original_subtree_hash = $this->getSubtreesHash();
@ -425,7 +332,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
}
/**
* Tests that the 'toolbar/subtrees/{hash}' is reachable.
* Tests that the 'toolbar/subtrees/{hash}' is reachable and correct.
*/
function testSubtreesJsonRequest() {
$admin_user = $this->adminUser;
@ -433,30 +340,10 @@ class ToolbarAdminMenuTest extends WebTestBase {
// Request a new page to refresh the drupalSettings object.
$subtrees_hash = $this->getSubtreesHash();
$this->drupalGetJSON('toolbar/subtrees/' . $subtrees_hash);
$this->assertResponse('200');
// Test that the subtrees hash changes with a different language code and
// that JSON is returned when a language code is specified.
// Create a new language with the langcode 'xx'.
$langcode = 'xx';
// The English name for the language. This will be translated.
$name = $this->randomMachineName(16);
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
);
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Get a page with the new language langcode in the URL.
$this->drupalGet('xx/test-page');
// Request a new page to refresh the drupalSettings object.
$subtrees_hash = $this->getSubtreesHash();
$this->drupalGetJSON('toolbar/subtrees/' . $subtrees_hash . '/' . $langcode);
$ajax_result = $this->drupalGetAjax('toolbar/subtrees/' . $subtrees_hash);
$this->assertResponse('200');
$this->assertEqual($ajax_result[0]['command'], 'setToolbarSubtrees', 'Subtrees response uses the correct command.');
$this->assertEqual(array_keys($ajax_result[0]['subtrees']), ['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], 'Correct subtrees returned.');
}
/**
@ -493,6 +380,26 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->assertTrue($back_link);
}
/**
* Tests that external links added to the menu appear in the toolbar.
*/
public function testExternalLink() {
$edit = [
'title[0][value]' => 'External URL',
'link[0][uri]' => 'http://example.org',
'menu_parent' => 'admin:system.admin',
];
$this->drupalPostForm('admin/structure/menu/manage/admin/add', $edit, 'Save');
// Assert that the new menu link is shown on the menu link listing.
$this->drupalGet('admin/structure/menu/manage/admin');
$this->assertText('External URL');
// Assert that the new menu link is shown in the toolbar on a regular page.
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertText('External URL');
}
/**
* Get the hash value from the admin menu subtrees route path.
*