diff --git a/core/modules/shortcut/src/Plugin/views/argument_default/CurrentShortcutSet.php b/core/modules/shortcut/src/Plugin/views/argument_default/CurrentShortcutSet.php index 658db52..c0af122 100644 --- a/core/modules/shortcut/src/Plugin/views/argument_default/CurrentShortcutSet.php +++ b/core/modules/shortcut/src/Plugin/views/argument_default/CurrentShortcutSet.php @@ -11,9 +11,7 @@ use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; /** - * Default argument plugin to extract the current shortcut - * - * This plugin actually has no options so it does not need to do a great deal. + * Default argument plugin to extract the shortcut set assigned to current user. * * @ViewsArgumentDefault( * id = "current_shortcut_set", @@ -22,6 +20,9 @@ */ class CurrentShortcutSet extends ArgumentDefaultPluginBase implements CacheablePluginInterface { + /** + * {@inheritdoc} + */ public function getArgument() { /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */ $shortcut_set = shortcut_current_displayed_set(); diff --git a/core/modules/simpletest/src/BlockCreationTrait.php b/core/modules/simpletest/src/BlockCreationTrait.php new file mode 100644 index 0000000..18165f3 --- /dev/null +++ b/core/modules/simpletest/src/BlockCreationTrait.php @@ -0,0 +1,77 @@ +drupalPlaceBlock('system_powered_by_block', array( + * 'label' => t('Hello, world!'), + * )); + * @endcode + * The following defaults are provided: + * - label: Random string. + * - ID: Random string. + * - region: 'sidebar_first'. + * - theme: The default theme. + * - visibility: Empty array. + * - cache: array('max_age' => Cache::PERMANENT). + * + * @return \Drupal\block\Entity\Block + * The block entity. + * + * @todo + * Add support for creating custom block instances. + */ + protected function drupalPlaceBlock($plugin_id, array $settings = array()) { + $config = \Drupal::configFactory(); + $settings += array( + 'plugin' => $plugin_id, + 'region' => 'sidebar_first', + 'id' => strtolower($this->randomMachineName(8)), + 'theme' => $config->get('system.theme')->get('default'), + 'label' => $this->randomMachineName(8), + 'visibility' => array(), + 'weight' => 0, + 'cache' => array( + 'max_age' => Cache::PERMANENT, + ), + ); + $values = []; + foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) { + $values[$key] = $settings[$key]; + // Remove extra values that do not belong in the settings array. + unset($settings[$key]); + } + foreach ($values['visibility'] as $id => $visibility) { + $values['visibility'][$id]['id'] = $id; + } + $values['settings'] = $settings; + $block = Block::create($values); + $block->save(); + return $block; + } + +} diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index 1a18a52..7fa089f 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -53,6 +53,7 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase { use SessionTestTrait; + use BlockCreationTrait; /** * Class loader. @@ -1339,64 +1340,4 @@ protected function drupalUserIsLoggedIn(UserInterface $account) { return $logged_in; } - /** - * Creates a block instance based on default settings. - * - * @param string $plugin_id - * The plugin ID of the block type for this block instance. - * @param array $settings - * (optional) An associative array of settings for the block entity. - * Override the defaults by specifying the key and value in the array, for - * example: - * @code - * $this->drupalPlaceBlock('system_powered_by_block', array( - * 'label' => t('Hello, world!'), - * )); - * @endcode - * The following defaults are provided: - * - label: Random string. - * - ID: Random string. - * - region: 'sidebar_first'. - * - theme: The default theme. - * - visibility: Empty array. - * - cache: array('max_age' => Cache::PERMANENT). - * - * @return \Drupal\block\Entity\Block - * The block entity. - * - * @todo - * Add support for creating custom block instances. - */ - protected function drupalPlaceBlock($plugin_id, array $settings = array()) { - $config = $this->container->get('config.factory'); - $settings += array( - 'plugin' => $plugin_id, - 'region' => 'sidebar_first', - 'id' => strtolower($this->randomMachineName(8)), - 'theme' => $config->get('system.theme')->get('default'), - 'label' => $this->randomMachineName(8), - 'visibility' => array(), - 'weight' => 0, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), - ); - $values = []; - foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) { - $values[$key] = $settings[$key]; - // Remove extra values that do not belong in the settings array. - unset($settings[$key]); - } - foreach ($values['visibility'] as $id => $visibility) { - $values['visibility'][$id]['id'] = $id; - } - $values['settings'] = $settings; - $block = $this->container - ->get('entity.manager') - ->getStorage('block') - ->create($values); - $block->save(); - return $block; - } - } diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 64f909b..e8c3e39 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -40,7 +40,7 @@ abstract class WebTestBase extends TestBase { use AssertContentTrait; - + use BlockCreationTrait; use UserCreationTrait { createUser as drupalCreateUser; createRole as drupalCreateRole; @@ -365,62 +365,6 @@ protected function drupalBuildEntityView(EntityInterface $entity, $view_mode = ' } /** - * Creates a block instance based on default settings. - * - * @param string $plugin_id - * The plugin ID of the block type for this block instance. - * @param array $settings - * (optional) An associative array of settings for the block entity. - * Override the defaults by specifying the key and value in the array, for - * example: - * @code - * $this->drupalPlaceBlock('system_powered_by_block', array( - * 'label' => t('Hello, world!'), - * )); - * @endcode - * The following defaults are provided: - * - label: Random string. - * - ID: Random string. - * - region: 'sidebar_first'. - * - theme: The default theme. - * - visibility: Empty array. - * - cache: array('max_age' => Cache::PERMANENT). - * - * @return \Drupal\block\Entity\Block - * The block entity. - * - * @todo - * Add support for creating custom block instances. - */ - protected function drupalPlaceBlock($plugin_id, array $settings = array()) { - $settings += array( - 'plugin' => $plugin_id, - 'region' => 'sidebar_first', - 'id' => strtolower($this->randomMachineName(8)), - 'theme' => $this->config('system.theme')->get('default'), - 'label' => $this->randomMachineName(8), - 'visibility' => array(), - 'weight' => 0, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), - ); - $values = []; - foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) { - $values[$key] = $settings[$key]; - // Remove extra values that do not belong in the settings array. - unset($settings[$key]); - } - foreach ($values['visibility'] as $id => $visibility) { - $values['visibility'][$id]['id'] = $id; - } - $values['settings'] = $settings; - $block = entity_create('block', $values); - $block->save(); - return $block; - } - - /** * Checks to see whether a block appears on the page. * * @param \Drupal\block\Entity\Block $block