Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -32,11 +32,11 @@
margin-right: 0.3em;
}
.shortcut-action__message {
background: #000000;
background: #000;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
padding: 0 5px;
color: #ffffff;
color: #fff;
display: inline-block;
margin-left: 0.3em; /* LTR */
opacity: 0;

View file

@ -2,6 +2,7 @@ id: d7_shortcut
label: Shortcut links
migration_tags:
- Drupal 7
- Content
source:
plugin: d7_shortcut
constants:

View file

@ -2,6 +2,7 @@ id: d7_shortcut_set
label: Shortcut sets
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_shortcut_set
process:

View file

@ -2,6 +2,7 @@ id: d7_shortcut_set_users
label: Shortcut set user mapping
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_shortcut_set_users
process:

View file

@ -6,4 +6,4 @@ version: VERSION
core: 8.x
configure: entity.shortcut_set.collection
dependencies:
- link
- drupal:link

View file

@ -5,7 +5,7 @@
* Allows users to manage customizable lists of shortcut links.
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\RouteMatchInterface;
@ -356,7 +356,7 @@ function shortcut_preprocess_page_title(&$variables) {
],
],
'#type' => 'link',
'#title' => SafeMarkup::format('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', ['@text' => $link_text]),
'#title' => new FormattableMarkup('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', ['@text' => $link_text]),
'#url' => Url::fromRoute($route_name, $route_parameters),
'#options' => ['query' => $query],
'#attributes' => [

View file

@ -40,10 +40,10 @@ class ShortcutController extends ControllerBase {
try {
$shortcut->delete();
drupal_set_message($this->t('The shortcut %title has been deleted.', ['%title' => $label]));
$this->messenger()->addStatus($this->t('The shortcut %title has been deleted.', ['%title' => $label]));
}
catch (\Exception $e) {
drupal_set_message($this->t('Unable to delete the shortcut for %title.', ['%title' => $label]), 'error');
$this->messenger()->addStatus($this->t('Unable to delete the shortcut for %title.', ['%title' => $label]), 'error');
}
return $this->redirect('<front>');

View file

@ -65,10 +65,10 @@ class ShortcutSetController extends ControllerBase {
try {
$shortcut->save();
drupal_set_message($this->t('Added a shortcut for %title.', ['%title' => $shortcut->label()]));
$this->messenger()->addStatus($this->t('Added a shortcut for %title.', ['%title' => $shortcut->label()]));
}
catch (\Exception $e) {
drupal_set_message($this->t('Unable to add a shortcut for %title.', ['%title' => $shortcut->label()]), 'error');
$this->messenger()->addError($this->t('Unable to add a shortcut for %title.', ['%title' => $shortcut->label()]));
}
return $this->redirect('<front>');

View file

@ -18,6 +18,14 @@ use Drupal\shortcut\ShortcutInterface;
* @ContentEntityType(
* id = "shortcut",
* label = @Translation("Shortcut link"),
* label_collection = @Translation("Shortcut links"),
* label_singular = @Translation("shortcut link"),
* label_plural = @Translation("shortcut links"),
* label_count = @PluralTranslation(
* singular = "@count shortcut link",
* plural = "@count shortcut links",
* ),
* bundle_label = @Translation("Shortcut set"),
* handlers = {
* "access" = "Drupal\shortcut\ShortcutAccessControlHandler",
* "form" = {

View file

@ -12,6 +12,13 @@ use Drupal\shortcut\ShortcutSetInterface;
* @ConfigEntityType(
* id = "shortcut_set",
* label = @Translation("Shortcut set"),
* label_collection = @Translation("Shortcut sets"),
* label_singular = @Translation("shortcut set"),
* label_plural = @Translation("shortcut sets"),
* label_count = @PluralTranslation(
* singular = "@count shortcut set",
* plural = "@count shortcut sets",
* ),
* handlers = {
* "storage" = "Drupal\shortcut\ShortcutSetStorage",
* "access" = "Drupal\shortcut\ShortcutSetAccessControlHandler",

View file

@ -8,6 +8,8 @@ use Drupal\Core\Render\Element;
/**
* Builds the shortcut set customize form.
*
* @internal
*/
class SetCustomize extends EntityForm {
@ -104,7 +106,7 @@ class SetCustomize extends EntityForm {
$shortcut->setWeight($weight);
$shortcut->save();
}
drupal_set_message(t('The shortcut set has been updated.'));
$this->messenger()->addStatus($this->t('The shortcut set has been updated.'));
}
}

View file

@ -7,6 +7,8 @@ use Drupal\Core\Url;
/**
* Builds the shortcut link deletion form.
*
* @internal
*/
class ShortcutDeleteForm extends ContentEntityDeleteForm {

View file

@ -10,6 +10,8 @@ use Drupal\Core\Database\Connection;
/**
* Builds the shortcut set deletion form.
*
* @internal
*/
class ShortcutSetDeleteForm extends EntityDeleteForm {

View file

@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Builds the shortcut set switch form.
*
* @internal
*/
class SwitchShortcutSet extends FormBase {
@ -186,10 +188,10 @@ class SwitchShortcutSet extends FormBase {
if ($account_is_user) {
// Only administrators can create new shortcut sets, so we know they have
// access to switch back.
drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href=":switch-url">switch back to a different one.</a>', $replacements));
$this->messenger()->addStatus($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href=":switch-url">switch back to a different one.</a>', $replacements));
}
else {
drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
$this->messenger()->addStatus($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
}
$form_state->setRedirect(
'entity.shortcut_set.customize_form',
@ -204,7 +206,7 @@ class SwitchShortcutSet extends FormBase {
'%user' => $this->user->getDisplayName(),
'%set_name' => $set->label(),
];
drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
$this->messenger()->addStatus($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
}
// Assign the shortcut set to the provided user account.

View file

@ -9,7 +9,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d7_shortcut",
* source_provider = "shortcut"
* source_module = "shortcut"
* )
*/
class Shortcut extends DrupalSqlBase {

View file

@ -9,7 +9,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d7_shortcut_set",
* source_provider = "shortcut"
* source_module = "shortcut"
* )
*/
class ShortcutSet extends DrupalSqlBase {

View file

@ -9,7 +9,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d7_shortcut_set_users",
* source_provider = "shortcut"
* source_module = "shortcut"
* )
*/
class ShortcutSetUsers extends DrupalSqlBase {

View file

@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Form handler for the shortcut entity forms.
*
* @internal
*/
class ShortcutForm extends ContentEntityForm {
@ -40,7 +42,7 @@ class ShortcutForm extends ContentEntityForm {
else {
$message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
}
drupal_set_message($message);
$this->messenger()->addStatus($message);
$form_state->setRedirect(
'entity.shortcut_set.customize_form',

View file

@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Form handler for the shortcut set entity edit forms.
*
* @internal
*/
class ShortcutSetForm extends BundleEntityFormBase {
@ -51,10 +53,10 @@ class ShortcutSetForm extends BundleEntityFormBase {
$entity->save();
if ($is_new) {
drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', ['%set_name' => $entity->label()]));
$this->messenger()->addStatus($this->t('The %set_name shortcut set has been created. You can edit it from this page.', ['%set_name' => $entity->label()]));
}
else {
drupal_set_message(t('Updated set name to %set-name.', ['%set-name' => $entity->label()]));
$this->messenger()->addStatus($this->t('Updated set name to %set-name.', ['%set-name' => $entity->label()]));
}
$form_state->setRedirectUrl($this->entity->urlInfo('customize-form'));
}

View file

@ -3,6 +3,7 @@
namespace Drupal\shortcut;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityTypeInterface;
@ -36,9 +37,11 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
* The module handler.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
* The memory cache.
*/
public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) {
parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager);
public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) {
parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager, $memory_cache);
$this->moduleHandler = $module_handler;
}
@ -52,7 +55,8 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
$container->get('config.factory'),
$container->get('uuid'),
$container->get('module_handler'),
$container->get('language_manager')
$container->get('language_manager'),
$container->get('entity.memory_cache')
);
}

View file

@ -2,6 +2,8 @@
namespace Drupal\shortcut\Tests;
@trigger_error(__NAMESPACE__ . '\ShortcutTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\shortcut\Functional\ShortcutTestBase, see https://www.drupal.org/node/2906736.', E_USER_DEPRECATED);
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\shortcut\ShortcutSetInterface;
@ -9,6 +11,11 @@ use Drupal\simpletest\WebTestBase;
/**
* Defines base class for shortcut test cases.
*
* @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\shortcut\Functional\ShortcutTestBase.
*
* @see https://www.drupal.org/node/2906736
*/
abstract class ShortcutTestBase extends WebTestBase {

View file

@ -0,0 +1,74 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\shortcut\Functional\Rest\ShortcutResourceTestBase;
/**
* @group hal
*/
class ShortcutHalJsonAnonTest extends ShortcutResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/admin/config/user-interface/shortcut/link/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/shortcut/default',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/shortcut/default',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
// The 'url.site' cache context is added for '_links' in the response.
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['url.site']);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class ShortcutHalJsonBasicAuthTest extends ShortcutHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,18 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class ShortcutHalJsonCookieTest extends ShortcutHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\shortcut\Functional\Rest\ShortcutSetResourceTestBase;
/**
* @group hal
*/
class ShortcutSetHalJsonAnonTest extends ShortcutSetResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class ShortcutSetHalJsonBasicAuthTest extends ShortcutSetHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,19 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class ShortcutSetHalJsonCookieTest extends ShortcutSetHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class ShortcutJsonAnonTest extends ShortcutResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class ShortcutJsonBasicAuthTest extends ShortcutResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class ShortcutJsonCookieTest extends ShortcutResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,168 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* ResourceTestBase for Shortcut entity.
*/
abstract class ShortcutResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'shortcut'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'shortcut';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* The Shortcut entity.
*
* @var \Drupal\shortcut\ShortcutInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
case 'POST':
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole(['access shortcuts', 'customize shortcut links']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create shortcut.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Comments'),
'weight' => -20,
'link' => [
'uri' => 'internal:/admin/content/comment',
'options' => [
'fragment' => 'new',
],
],
]);
$shortcut->save();
return $shortcut;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'uuid' => [
[
'value' => $this->entity->uuid(),
],
],
'id' => [
[
'value' => (int) $this->entity->id(),
],
],
'title' => [
[
'value' => 'Comments',
],
],
'shortcut_set' => [
[
'target_id' => 'default',
'target_type' => 'shortcut_set',
'target_uuid' => ShortcutSet::load('default')->uuid(),
],
],
'link' => [
[
'uri' => 'internal:/admin/content/comment',
'title' => NULL,
'options' => [
'fragment' => 'new',
],
],
],
'weight' => [
[
'value' => -20,
],
],
'langcode' => [
[
'value' => 'en',
],
],
'default_langcode' => [
[
'value' => TRUE,
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'title' => [
[
'value' => 'Comments',
],
],
'link' => [
[
'uri' => 'internal:/',
],
],
'shortcut_set' => [
[
'target_id' => 'default',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
case 'POST':
case 'PATCH':
case 'DELETE':
return "The shortcut set must be the currently displayed set for the user and the user must have 'access shortcuts' AND 'customize shortcut links' permissions.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class ShortcutSetJsonAnonTest extends ShortcutSetResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class ShortcutSetJsonBasicAuthTest extends ShortcutSetResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class ShortcutSetJsonCookieTest extends ShortcutSetResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,88 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* ResourceTestBase for ShortcutSet entity.
*/
abstract class ShortcutSetResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['shortcut'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'shortcut_set';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* The ShortcutSet entity.
*
* @var \Drupal\shortcut\ShortcutSetInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access shortcuts']);
break;
case 'POST':
case 'PATCH':
$this->grantPermissionsToTestedRole(['access shortcuts', 'customize shortcut links']);
break;
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer shortcuts']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$set = ShortcutSet::create([
'id' => 'llama_set',
'label' => 'Llama Set',
]);
$set->save();
return $set;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'id' => 'llama_set',
'uuid' => $this->entity->uuid(),
'label' => 'Llama Set',
'status' => TRUE,
'langcode' => 'en',
'dependencies' => [],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutSetXmlAnonTest extends ShortcutSetResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutSetXmlBasicAuthTest extends ShortcutSetResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutSetXmlCookieTest extends ShortcutSetResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutXmlAnonTest extends ShortcutResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutXmlBasicAuthTest extends ShortcutResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\shortcut\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class ShortcutXmlCookieTest extends ShortcutResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -4,7 +4,7 @@ namespace Drupal\Tests\shortcut\Functional;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;

View file

@ -1,13 +1,13 @@
<?php
namespace Drupal\shortcut\Tests;
namespace Drupal\Tests\shortcut\Functional;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\Tests\block\Functional\AssertBlockAppearsTrait;
use Drupal\views\Entity\View;
/**
@ -17,6 +17,8 @@ use Drupal\views\Entity\View;
*/
class ShortcutLinksTest extends ShortcutTestBase {
use AssertBlockAppearsTrait;
/**
* Modules to enable.
*
@ -62,6 +64,11 @@ class ShortcutLinksTest extends ShortcutTestBase {
'/admin/config/system/site-information',
];
// Test the add shortcut form UI. Test that the base field description is
// there.
$this->drupalGet('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link');
$this->assertRaw('The location this shortcut points to.');
// Check that each new shortcut links where it should.
foreach ($test_cases as $test_path) {
$title = $this->randomMachineName();
@ -77,10 +84,10 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->assertTrue(in_array('internal:' . $test_path, $paths), 'Shortcut created: ' . $test_path);
if (in_array($test_path, $test_cases_non_access)) {
$this->assertNoLink($title, SafeMarkup::format('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
$this->assertNoLink($title, new FormattableMarkup('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
}
else {
$this->assertLink($title, 0, SafeMarkup::format('Shortcut link %url found on the page.', ['%url' => $test_path]));
$this->assertLink($title, 0, new FormattableMarkup('Shortcut link %url found on the page.', ['%url' => $test_path]));
}
}
$saved_set = ShortcutSet::load($set->id());
@ -368,15 +375,15 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types']));
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
$this->assertEqual((string) $shortcuts[0], 'Add content');
$this->assertEqual((string) $shortcuts[1], 'All content');
$this->assertEqual($shortcuts[0]->getText(), 'Add content');
$this->assertEqual($shortcuts[1]->getText(), 'All content');
foreach ($this->set->getShortcuts() as $shortcut) {
$shortcut->setWeight($shortcut->getWeight() * -1)->save();
}
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
$this->assertEqual((string) $shortcuts[0], 'All content');
$this->assertEqual((string) $shortcuts[1], 'Add content');
$this->assertEqual($shortcuts[0]->getText(), 'All content');
$this->assertEqual($shortcuts[1]->getText(), 'Add content');
}
/**
@ -455,7 +462,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
protected function assertShortcutQuickLink($label, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]);
$message = ($message ? $message : SafeMarkup::format('Shortcut quick link with label %label found.', ['%label' => $label]));
$message = ($message ? $message : new FormattableMarkup('Shortcut quick link with label %label found.', ['%label' => $label]));
return $this->assert(isset($links[$index]), $message, $group);
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\shortcut\Tests;
namespace Drupal\Tests\shortcut\Functional;
use Drupal\shortcut\Entity\ShortcutSet;
@ -68,7 +68,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
// Test the contents of each th cell.
$expected_items = [t('Name'), t('Weight'), t('Operations')];
foreach ($elements as $key => $element) {
$this->assertEqual((string) $element[0], $expected_items[$key]);
$this->assertEqual($element->getText(), $expected_items[$key]);
}
// Look for test shortcuts in the table.

View file

@ -0,0 +1,133 @@
<?php
namespace Drupal\Tests\shortcut\Functional;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\shortcut\ShortcutSetInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Defines base class for shortcut test cases.
*/
abstract class ShortcutTestBase extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'toolbar', 'shortcut'];
/**
* User with permission to administer shortcuts.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* User with permission to use shortcuts, but not administer them.
*
* @var \Drupal\user\UserInterface
*/
protected $shortcutUser;
/**
* Generic node used for testing.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* Site-wide default shortcut set.
*
* @var \Drupal\shortcut\ShortcutSetInterface
*/
protected $set;
protected function setUp() {
parent::setUp();
if ($this->profile != 'standard') {
// Create Basic page and Article node types.
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
// Populate the default shortcut set.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
'link' => [
'uri' => 'internal:/node/add',
],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
'link' => [
'uri' => 'internal:/admin/content',
],
]);
$shortcut->save();
}
// Create users.
$this->adminUser = $this->drupalCreateUser(['access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content']);
$this->shortcutUser = $this->drupalCreateUser(['customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content']);
// Create a node.
$this->node = $this->drupalCreateNode(['type' => 'article']);
// Log in as admin and grab the default shortcut set.
$this->drupalLogin($this->adminUser);
$this->set = ShortcutSet::load('default');
\Drupal::entityManager()->getStorage('shortcut_set')->assignUser($this->set, $this->adminUser);
}
/**
* Creates a generic shortcut set.
*/
public function generateShortcutSet($label = '', $id = NULL) {
$set = ShortcutSet::create([
'id' => isset($id) ? $id : strtolower($this->randomMachineName()),
'label' => empty($label) ? $this->randomString() : $label,
]);
$set->save();
return $set;
}
/**
* Extracts information from shortcut set links.
*
* @param \Drupal\shortcut\ShortcutSetInterface $set
* The shortcut set object to extract information from.
* @param string $key
* The array key indicating what information to extract from each link:
* - 'title': Extract shortcut titles.
* - 'link': Extract shortcut paths.
* - 'id': Extract the shortcut ID.
*
* @return array
* Array of the requested information from each link.
*/
public function getShortcutInformation(ShortcutSetInterface $set, $key) {
$info = [];
\Drupal::entityManager()->getStorage('shortcut')->resetCache();
foreach ($set->getShortcuts() as $shortcut) {
if ($key == 'link') {
$info[] = $shortcut->link->uri;
}
else {
$info[] = $shortcut->{$key}->value;
}
}
return $info;
}
}

View file

@ -1,8 +1,8 @@
<?php
namespace Drupal\shortcut\Tests;
namespace Drupal\Tests\shortcut\Functional;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Language\Language;
@ -28,7 +28,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
'content_translation',
'link',
'shortcut',
'toolbar'
'toolbar',
];
/**

View file

@ -52,7 +52,7 @@ class ShortcutTest extends MigrateSqlSourceTestBase {
'p8' => '0',
'p9' => '0',
'updated' => '0',
]
],
];
// The expected results.