From b12a323acd7b6e09a0e11ee39a25493c5953dd8b Mon Sep 17 00:00:00 2001 From: Antonio De Marco <antonio@nuvole.org> Date: Sun, 15 Apr 2018 15:37:34 +0200 Subject: [PATCH] Fix tests for Drupal 8.5 (#183) --- .travis.yml | 5 +- composer.json | 37 +++++++++------ docker-compose.yml | 4 -- .../src/FieldTemplateProcessor.php | 22 ++++----- .../src/FieldTemplateProcessorInterface.php | 4 +- .../src/Plugin/DsFieldTemplate/Pattern.php | 18 ++++---- modules/ui_patterns_ds/ui_patterns_ds.module | 4 +- .../FieldGroupFormatter/PatternFormatter.php | 12 ++--- .../ui_patterns_field_group.module | 2 +- .../src/Plugin/Layout/PatternLayout.php | 6 ++- .../Controller/PatternsLibraryController.php | 2 +- .../src/Plugin/Deriver/LibraryDeriver.php | 10 ++-- .../UiPatterns/Pattern/LibraryPattern.php | 14 +++--- .../src/Plugin/views/row/Pattern.php | 10 ++-- .../ui_patterns_views.module | 2 +- phpunit.xml.dist | 4 +- runner.yml.dist | 8 ++++ src/Annotation/UiPatternsSource.php | 4 +- src/Definition/PatternDefinition.php | 18 ++++---- src/Definition/PatternDefinitionField.php | 2 +- src/Definition/PatternSourceField.php | 5 +- src/Element/Pattern.php | 12 ++--- src/Element/PatternContext.php | 16 +++---- src/Element/PatternPreview.php | 2 +- src/Form/PatternDisplayFormTrait.php | 46 +++++++++---------- .../Deriver/AbstractPatternsDeriver.php | 10 ++-- .../Deriver/PatternsDeriverInterface.php | 2 +- .../Deriver/YamlPatternsDeriverInterface.php | 2 +- src/Plugin/PatternBase.php | 14 +++--- src/Plugin/PatternInterface.php | 4 +- src/Plugin/PatternSourceInterface.php | 12 ++--- src/Template/TwigExtension.php | 12 ++--- src/TypedData/PatternDataDefinition.php | 4 +- src/UiPatterns.php | 10 ++-- src/UiPatternsManager.php | 4 +- src/UiPatternsSourceManager.php | 12 ++--- tests/features/overview.feature | 5 +- ui_patterns.api.php | 4 +- 38 files changed, 188 insertions(+), 176 deletions(-) diff --git a/.travis.yml b/.travis.yml index 070b57013..854a802e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,13 +8,12 @@ env: global: - DOCKER_COMPOSE_VERSION=1.17.1 matrix: - - DRUPAL_VERSION=8.3.x-dev - - DRUPAL_VERSION=8.4.x-dev - DRUPAL_VERSION=8.5.x-dev + - DRUPAL_VERSION=8.6.x-dev matrix: allow_failures: - - env: DRUPAL_VERSION=8.5.x-dev + - env: DRUPAL_VERSION=8.6.x-dev before_install: - docker-compose up -d diff --git a/composer.json b/composer.json index 9daf853e6..db58d06ce 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "drupal-module", "description": "UI Patterns.", "keywords": ["drupal", "web", "ui"], - "minimum-stability": "dev", "license": "GPL-2.0+", + "minimum-stability": "dev", "prefer-stable": true, "authors": [ { @@ -13,12 +13,13 @@ } ], "require-dev": { - "nuvoleweb/drupal-component-scaffold": "*", + "cweagans/composer-patches": "~1.0", + "drupal-composer/drupal-scaffold": "^2.2", "drupal/config_installer": "1.3.0", "drupal/console": "~1", "drush/drush": "*", - "drupal/coder": "8.2.8", - "drupal/core": "8.4.x-dev", + "drupal/core": "8.5.x-dev", + "webflo/drupal-core-require-dev": "^8.5", "drupal/ds": "~3", "drupal/field_group": "~1", "drupal/coffee": "~1", @@ -28,13 +29,10 @@ "drupal/paragraphs": "~1", "drupal/token": "~1", "drupal/bootstrap": "3.1", - "phpunit/phpunit": "5.5.*", "nuvoleweb/drupal-behat": "~1.1.0", - "mikey179/vfsStream": "*", "phpro/grumphp": "0.11.4", - "squizlabs/php_codesniffer": "~2.9", "peridot-php/leo": "^1.6", - "ec-europa/oe-task-runner": "^0.3" + "openeuropa/task-runner": "^0.4" }, "repositories": [ { @@ -43,17 +41,28 @@ } ], "autoload": { + "psr-4": {"Drupal\\ui_patterns\\": "src" + } + }, + "autoload-dev": { "psr-4": { - "Drupal\\ui_patterns\\": "src", "Drupal\\Tests\\ui_patterns\\": "tests/src" } }, + "scripts": { + "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold" + }, "extra": { - "installer-paths": { - "build/core": ["type:drupal-core"], - "build/modules/contrib/{$name}": ["type:drupal-module"], - "build/profiles/contrib/{$name}": ["type:drupal-profile"], - "build/themes/contrib/{$name}": ["type:drupal-theme"] + "patches": { + "drupal/core": { + "https://www.drupal.org/project/drupal/issues/2943172": "https://www.drupal.org/files/issues/2018-04-15/2943172-kernel-test-base-2.patch" } + }, + "installer-paths": { + "build/core": ["type:drupal-core"], + "build/modules/contrib/{$name}": ["type:drupal-module"], + "build/profiles/contrib/{$name}": ["type:drupal-profile"], + "build/themes/contrib/{$name}": ["type:drupal-theme"] + } } } diff --git a/docker-compose.yml b/docker-compose.yml index fa87d3b0e..f22ff5f55 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,12 +25,8 @@ services: PHP_XDEBUG_REMOTE_HOST: "10.254.254.254" PHP_XDEBUG_IDEKEY: "PHPSTORM" PHP_IDE_CONFIG: "serverName=ui_patterns" - COMPOSER_HOME: "/composer" volumes: - ./:/var/www/html - - ~/.bash_history:/root/.bash_history - - ~/.bashrc.aliases:/root/.bashrc - - ~/.composer/cache:/composer/cache nginx: image: wodby/drupal-nginx:8-1.13-3.0.1 diff --git a/modules/ui_patterns_ds/src/FieldTemplateProcessor.php b/modules/ui_patterns_ds/src/FieldTemplateProcessor.php index a1304d755..85d655136 100644 --- a/modules/ui_patterns_ds/src/FieldTemplateProcessor.php +++ b/modules/ui_patterns_ds/src/FieldTemplateProcessor.php @@ -21,7 +21,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { /** * {@inheritdoc} */ - public function process(&$variables) { + public function process(array &$variables) { $this->variables = $variables; $content = []; @@ -47,12 +47,12 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get source value. * * @param array $mapping - * Mapping array. + * Mapping array. * @param int $delta - * Field delta. + * Field delta. * * @return mixed - * Source value. + * Source value. */ public function getSourceValue(array $mapping, $delta) { $value = $this->variables['items'][$delta]['content']; @@ -68,7 +68,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get field parent entity. * * @return \Drupal\Core\Entity\ContentEntityBase - * Parent entity. + * Parent entity. */ protected function getEntity() { return $this->variables['element']['#object']; @@ -78,7 +78,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get Pattern ID. * * @return string - * Pattern ID. + * Pattern ID. */ protected function getPatternId() { return $this->variables['ds-config']['settings']['pattern']; @@ -88,7 +88,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get mapping settings. * * @return mixed - * Mapping settings. + * Mapping settings. */ protected function getMapping() { return $this->variables['ds-config']['settings']['pattern_mapping']; @@ -98,7 +98,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get field name. * * @return string - * Field name. + * Field name. */ protected function getFieldName() { return $this->variables['field_name']; @@ -108,10 +108,10 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Extract column name from a source name. * * @param string $source - * Source name. + * Source name. * * @return string - * Column name. + * Column name. */ protected function getColumnName($source) { return str_replace($this->getFieldName() . '__', '', $source); @@ -121,7 +121,7 @@ class FieldTemplateProcessor implements FieldTemplateProcessorInterface { * Get pattern context. * * @return array - * Pattern context. + * Pattern context. */ protected function getContext() { $element = $this->variables['element']; diff --git a/modules/ui_patterns_ds/src/FieldTemplateProcessorInterface.php b/modules/ui_patterns_ds/src/FieldTemplateProcessorInterface.php index 6bc67a4fb..a926bb2fc 100644 --- a/modules/ui_patterns_ds/src/FieldTemplateProcessorInterface.php +++ b/modules/ui_patterns_ds/src/FieldTemplateProcessorInterface.php @@ -13,10 +13,10 @@ interface FieldTemplateProcessorInterface { * Process field template variables. * * @param array $variables - * Variables array. + * Variables array. * * @see template_preprocess_field__pattern_ds_field_template() */ - public function process(&$variables); + public function process(array &$variables); } diff --git a/modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php b/modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php index 3a2757837..f9f479675 100644 --- a/modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php +++ b/modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php @@ -62,13 +62,13 @@ class Pattern extends DsFieldTemplateBase implements ContainerFactoryPluginInter * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\ui_patterns\UiPatternsManager $patterns_manager - * UI Patterns manager. + * UI Patterns manager. * @param \Drupal\ui_patterns\UiPatternsSourceManager $source_manager - * UI Patterns source manager. + * UI Patterns source manager. * @param \Symfony\Component\HttpFoundation\RequestStack $parameters - * Current $_POST parameters. + * Current $_POST parameters. * @param \Drupal\Core\Entity\EntityFieldManager $field_manager - * Field manager. + * Field manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, UiPatternsManager $patterns_manager, UiPatternsSourceManager $source_manager, RequestStack $parameters, EntityFieldManager $field_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -110,7 +110,7 @@ class Pattern extends DsFieldTemplateBase implements ContainerFactoryPluginInter * Get source field plugin context. * * @return array - * Context array. + * Context array. */ protected function getContext() { $fields = $this->parameters->get('fields'); @@ -139,7 +139,7 @@ class Pattern extends DsFieldTemplateBase implements ContainerFactoryPluginInter * Get name of field currently being edited. * * @return string - * Name of field currently being edited. + * Name of field currently being edited. */ protected function getCurrentField() { $fields = array_filter($this->parameters->get('fields'), function ($field) { @@ -160,12 +160,12 @@ class Pattern extends DsFieldTemplateBase implements ContainerFactoryPluginInter * Pattern Display Suite field template plugin only supports actual fields. * * @param array $context - * Current context. + * Current context. * * @return bool - * TRUE if supported, FALSE otherwise. + * TRUE if supported, FALSE otherwise. */ - protected function isSupportedField($context) { + protected function isSupportedField(array $context) { /** @var \Drupal\field\Entity\FieldConfig $field */ $field = $this->fieldManager->getFieldDefinitions($context['entity_type'], $context['bundle']); return isset($field[$context['field_name']]); diff --git a/modules/ui_patterns_ds/ui_patterns_ds.module b/modules/ui_patterns_ds/ui_patterns_ds.module index 45e98d08c..a73efb840 100644 --- a/modules/ui_patterns_ds/ui_patterns_ds.module +++ b/modules/ui_patterns_ds/ui_patterns_ds.module @@ -35,7 +35,7 @@ function ui_patterns_ds_form_entity_view_display_edit_form_alter(&$form, FormSta * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ -function ui_patterns_ds_field_overview_submit($form, FormStateInterface $form_state) { +function ui_patterns_ds_field_overview_submit(array $form, FormStateInterface $form_state) { /* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */ /* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */ @@ -57,7 +57,7 @@ function ui_patterns_ds_field_overview_submit($form, FormStateInterface $form_st * Preprocess hook. * * @param array $variables - * Theme variables. + * Theme variables. */ function template_preprocess_field__pattern_ds_field_template(array &$variables) { \Drupal::service('ui_patterns_ds.field_template_processor')->process($variables); diff --git a/modules/ui_patterns_field_group/src/Plugin/field_group/FieldGroupFormatter/PatternFormatter.php b/modules/ui_patterns_field_group/src/Plugin/field_group/FieldGroupFormatter/PatternFormatter.php index 1f52e9b3f..f385f97b3 100644 --- a/modules/ui_patterns_field_group/src/Plugin/field_group/FieldGroupFormatter/PatternFormatter.php +++ b/modules/ui_patterns_field_group/src/Plugin/field_group/FieldGroupFormatter/PatternFormatter.php @@ -50,11 +50,11 @@ class PatternFormatter extends FieldGroupFormatterBase implements ContainerFacto * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\ui_patterns\UiPatternsManager $patterns_manager - * UI Patterns manager. + * UI Patterns manager. * @param \Drupal\ui_patterns\UiPatternsSourceManager $source_manager - * UI Patterns source manager. + * UI Patterns source manager. */ - public function __construct($configuration, $plugin_id, $plugin_definition, UiPatternsManager $patterns_manager, UiPatternsSourceManager $source_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, UiPatternsManager $patterns_manager, UiPatternsSourceManager $source_manager) { parent::__construct($plugin_id, $plugin_definition, $configuration['group'], $configuration['settings'], $configuration['label']); $this->configuration = $configuration; $this->patternsManager = $patterns_manager; @@ -105,10 +105,10 @@ class PatternFormatter extends FieldGroupFormatterBase implements ContainerFacto * Look for entity object in fields array. * * @param array $fields - * Fields array. + * Fields array. * * @return \Drupal\Core\Entity\ContentEntityBase|null - * Entity object or NULL if none found. + * Entity object or NULL if none found. */ protected function findEntity(array $fields) { foreach ($fields as $field) { @@ -126,7 +126,7 @@ class PatternFormatter extends FieldGroupFormatterBase implements ContainerFacto * Get field group name. * * @return string - * Field group name. + * Field group name. */ protected function getFieldGroupName() { return $this->configuration['group']->group_name; diff --git a/modules/ui_patterns_field_group/ui_patterns_field_group.module b/modules/ui_patterns_field_group/ui_patterns_field_group.module index 4ea513dee..593a9224b 100644 --- a/modules/ui_patterns_field_group/ui_patterns_field_group.module +++ b/modules/ui_patterns_field_group/ui_patterns_field_group.module @@ -23,7 +23,7 @@ function ui_patterns_field_group_form_entity_view_display_edit_form_alter(&$form * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ -function ui_patterns_field_group_field_group_field_overview_submit($form, FormStateInterface $form_state) { +function ui_patterns_field_group_field_group_field_overview_submit(array $form, FormStateInterface $form_state) { $field_group_form_state = $form_state->get('field_group'); if (!empty($field_group_form_state)) { diff --git a/modules/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php b/modules/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php index 534a10d3a..d2804ad00 100644 --- a/modules/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php +++ b/modules/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php @@ -41,8 +41,10 @@ class PatternLayout extends LayoutDefault implements PluginFormInterface, Contai * The plugin_id for the plugin instance. * @param \Drupal\Core\Layout\LayoutDefinition $plugin_definition * The plugin implementation definition. + * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info + * Element info object. * @param \Drupal\ui_patterns\UiPatternsManager $pattern_manager - * Pattern manager service. + * Pattern manager service. */ public function __construct(array $configuration, $plugin_id, LayoutDefinition $plugin_definition, ElementInfoManagerInterface $element_info, UiPatternsManager $pattern_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -145,7 +147,7 @@ class PatternLayout extends LayoutDefault implements PluginFormInterface, Contai * Remove default field template if "Only content" option has been selected. * * @param array $regions - * Layout regions. + * Layout regions. */ protected function processOnlyContentFields(array &$regions) { foreach ($regions as $region_name => $region) { diff --git a/modules/ui_patterns_library/src/Controller/PatternsLibraryController.php b/modules/ui_patterns_library/src/Controller/PatternsLibraryController.php index 9559141ed..132d26630 100644 --- a/modules/ui_patterns_library/src/Controller/PatternsLibraryController.php +++ b/modules/ui_patterns_library/src/Controller/PatternsLibraryController.php @@ -48,7 +48,7 @@ class PatternsLibraryController extends ControllerBase { * Render pattern library page. * * @param string $name - * Plugin ID. + * Plugin ID. * * @return array * Return render array. diff --git a/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php b/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php index a7c2f05b2..88e34399f 100644 --- a/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php +++ b/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php @@ -81,9 +81,9 @@ class LibraryDeriver extends AbstractYamlPatternsDeriver { * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager * Typed data manager service. * @param string $root - * Application root directory. + * Application root directory. * @param array $extensions - * File extensions. + * File extensions. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * Module handler service. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler @@ -172,10 +172,10 @@ class LibraryDeriver extends AbstractYamlPatternsDeriver { * Get extension name that hosts the given YAML definition file. * * @param string $pathname - * YAML definition file full path. + * YAML definition file full path. * * @return bool|string - * Either extension machine name or FALSE if not found. + * Either extension machine name or FALSE if not found. */ protected function getHostExtension($pathname) { $extensions = $this->getExtensionLocations(); @@ -194,7 +194,7 @@ class LibraryDeriver extends AbstractYamlPatternsDeriver { * Get extension locations. * * @return array - * Array of extensions keyed by their path location. + * Array of extensions keyed by their path location. */ protected function getExtensionLocations() { /** @var \Drupal\Core\Extension\Extension[] $extensions */ diff --git a/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php b/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php index bb3750650..f57aad219 100644 --- a/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php +++ b/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php @@ -66,10 +66,10 @@ class LibraryPattern extends PatternBase { * Process 'custom hook theme' definition property. * * @param \Drupal\ui_patterns\Definition\PatternDefinition $definition - * Pattern definition array. + * Pattern definition array. * * @return array - * Processed hook definition portion. + * Processed hook definition portion. */ protected function processCustomThemeHookProperty(PatternDefinition $definition) { /** @var \Drupal\Core\Extension\Extension $module */ @@ -88,12 +88,12 @@ class LibraryPattern extends PatternBase { * Weather template exists in given directory. * * @param string $directory - * Directory full path. + * Directory full path. * @param string $template - * Template name, without default Twig extension. + * Template name, without default Twig extension. * * @return bool - * Weather template exists in given directory. + * Weather template exists in given directory. */ protected function templateExists($directory, $template) { return file_exists($directory . DIRECTORY_SEPARATOR . $template . '.html.twig'); @@ -103,10 +103,10 @@ class LibraryPattern extends PatternBase { * Process 'template' definition property. * * @param \Drupal\ui_patterns\Definition\PatternDefinition $definition - * Pattern definition array. + * Pattern definition array. * * @return array - * Processed hook definition portion. + * Processed hook definition portion. */ protected function processTemplateProperty(PatternDefinition $definition) { $return = []; diff --git a/modules/ui_patterns_views/src/Plugin/views/row/Pattern.php b/modules/ui_patterns_views/src/Plugin/views/row/Pattern.php index 029330844..918d377c5 100644 --- a/modules/ui_patterns_views/src/Plugin/views/row/Pattern.php +++ b/modules/ui_patterns_views/src/Plugin/views/row/Pattern.php @@ -51,9 +51,9 @@ class Pattern extends Fields { * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\ui_patterns\UiPatternsManager $patterns_manager - * UI Patterns manager. + * UI Patterns manager. * @param \Drupal\ui_patterns\UiPatternsSourceManager $source_manager - * UI Patterns source manager. + * UI Patterns source manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, UiPatternsManager $patterns_manager, UiPatternsSourceManager $source_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -121,12 +121,12 @@ class Pattern extends Fields { * Helper function: check for all conditions that make a field visible. * * @param \Drupal\views\Plugin\views\field\FieldPluginBase $field - * Field object. + * Field object. * @param \Drupal\Component\Render\MarkupInterface|null $field_output - * Field output. + * Field output. * * @return bool - * TRUE if a field should be visible, FALSE otherwise. + * TRUE if a field should be visible, FALSE otherwise. * * @see template_preprocess_pattern_views_row() */ diff --git a/modules/ui_patterns_views/ui_patterns_views.module b/modules/ui_patterns_views/ui_patterns_views.module index 7f4902356..ae6b76985 100644 --- a/modules/ui_patterns_views/ui_patterns_views.module +++ b/modules/ui_patterns_views/ui_patterns_views.module @@ -22,7 +22,7 @@ function ui_patterns_views_theme() { * Preprocess hook. * * @param array $variables - * Theme variables. + * Theme variables. */ function template_preprocess_pattern_views_row(array &$variables) { /** @var \Drupal\views\ResultRow $row */ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5ca615c51..e1c2285c3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> -<phpunit bootstrap="vendor/autoload.php" backupGlobals="true" colors="true" > +<phpunit bootstrap="${drupal.root}/core/tests/bootstrap.php" backupGlobals="true" colors="true" > <php> <ini name="error_reporting" value="32767"/> - <var name="namespaces" value=""/> <ini name="memory_limit" value="-1"/> <env name="SIMPLETEST_BASE_URL" value="${drupal.base_url}"/> + <env name="SIMPLETEST_IGNORE_DIRECTORIES" value="${drupal.root}"/> <env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/> </php> <testsuites> diff --git a/runner.yml.dist b/runner.yml.dist index c9331a267..7bbfba788 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -10,9 +10,17 @@ drupal: post_install: - "./vendor/bin/drush en -y ui_patterns_test" - "./vendor/bin/drush cr" + settings: + settings: + file_scan_ignore_directories: + - "node_modules" + - "bower_components" + - "vendor" + - "${drupal.root}" commands: drupal:site-setup: + - { task: "symlink", from: "../../..", to: "${drupal.root}/modules/custom/ui_patterns" } - { task: "run", command: "drupal:drush-setup" } - { task: "run", command: "drupal:settings-setup" } - { task: "run", command: "setup:behat" } diff --git a/src/Annotation/UiPatternsSource.php b/src/Annotation/UiPatternsSource.php index cfbcb053f..1f02b88be 100644 --- a/src/Annotation/UiPatternsSource.php +++ b/src/Annotation/UiPatternsSource.php @@ -43,9 +43,9 @@ class UiPatternsSource extends Plugin { * We should tackle this by using contexts but, until configuration entities * will not be exposed as typed data, we will use tags instead. * - * @link https://www.drupal.org/node/1818574 - * * @var array + * + * @link https://www.drupal.org/node/1818574 */ public $tags = []; diff --git a/src/Definition/PatternDefinition.php b/src/Definition/PatternDefinition.php index 1e4e08130..531b41b61 100644 --- a/src/Definition/PatternDefinition.php +++ b/src/Definition/PatternDefinition.php @@ -79,7 +79,7 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * Return array definition. * * @return array - * Array definition. + * Array definition. */ public function toArray() { $definition = $this->definition; @@ -195,7 +195,7 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * Get field as options. * * @return array - * Fields as select options. + * Fields as select options. */ public function getFieldsAsOptions() { $options = []; @@ -225,10 +225,10 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * Get field. * * @param string $name - * Field name. + * Field name. * * @return PatternDefinitionField|null - * Definition field. + * Definition field. */ public function getField($name) { return $this->hasField($name) ? $this->definition['fields'][$name] : NULL; @@ -251,9 +251,9 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * Set field. * * @param string $name - * Field name. + * Field name. * @param string $label - * Field label. + * Field label. * * @return $this */ @@ -312,7 +312,7 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * Getter. * * @return bool - * Whereas definition uses the "use:" property. + * Whereas definition uses the "use:" property. */ public function hasUse() { return !empty($this->definition['use']); @@ -359,7 +359,7 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * * @return $this */ - public function setTags($tags) { + public function setTags(array $tags) { $this->definition['tags'] = $tags; return $this; } @@ -501,7 +501,7 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin * * @return $this */ - public function setAdditional($additional) { + public function setAdditional(array $additional) { $this->definition['additional'] = $additional; return $this; } diff --git a/src/Definition/PatternDefinitionField.php b/src/Definition/PatternDefinitionField.php index bbf6e9ecc..be33e4027 100644 --- a/src/Definition/PatternDefinitionField.php +++ b/src/Definition/PatternDefinitionField.php @@ -44,7 +44,7 @@ class PatternDefinitionField implements \ArrayAccess { * Return array definition. * * @return array - * Array definition. + * Array definition. */ public function toArray() { return $this->definition; diff --git a/src/Definition/PatternSourceField.php b/src/Definition/PatternSourceField.php index 63302975d..4809e5dca 100644 --- a/src/Definition/PatternSourceField.php +++ b/src/Definition/PatternSourceField.php @@ -9,9 +9,6 @@ namespace Drupal\ui_patterns\Definition; */ class PatternSourceField { - /** - * Separator used to namespace fields with their plugin type. - */ const FIELD_KEY_SEPARATOR = ':'; private $fieldName; @@ -125,7 +122,7 @@ class PatternSourceField { * Get unique field key. * * @return string - * Field key. + * Field key. */ public function getFieldKey() { return $this->getPluginId() . self::FIELD_KEY_SEPARATOR . $this->getFieldName(); diff --git a/src/Element/Pattern.php b/src/Element/Pattern.php index 3e5cd851c..1f8047597 100644 --- a/src/Element/Pattern.php +++ b/src/Element/Pattern.php @@ -181,9 +181,9 @@ class Pattern extends RenderElement { * Render array. * * @return bool - * TRUE or FALSE. + * TRUE or FALSE. */ - public static function hasFields($element) { + public static function hasFields(array $element) { return isset($element['#fields']) && !empty($element['#fields']) && is_array($element['#fields']); } @@ -194,9 +194,9 @@ class Pattern extends RenderElement { * Render array. * * @return bool - * TRUE or FALSE. + * TRUE or FALSE. */ - public static function hasMultipleSources($element) { + public static function hasMultipleSources(array $element) { return isset($element['#multiple_sources']) && $element['#multiple_sources'] === TRUE; } @@ -207,9 +207,9 @@ class Pattern extends RenderElement { * Render array. * * @return bool - * TRUE or FALSE. + * TRUE or FALSE. */ - public static function hasValidContext($element) { + public static function hasValidContext(array $element) { return isset($element['#context']) && is_array($element['#context']) && !empty($element['#context']['type']); } diff --git a/src/Element/PatternContext.php b/src/Element/PatternContext.php index 02e4221a4..48f0ab34c 100644 --- a/src/Element/PatternContext.php +++ b/src/Element/PatternContext.php @@ -27,9 +27,9 @@ class PatternContext { * PatternContext constructor. * * @param string $type - * Pattern context type. + * Pattern context type. * @param array $values - * Initial context values. + * Initial context values. */ public function __construct($type, array $values = []) { $this->type = $type; @@ -43,7 +43,7 @@ class PatternContext { * Get pattern context property. * * @return mixed - * Property value. + * Property value. */ public function getProperty($name) { return isset($this->properties[$name]) ? $this->properties[$name] : NULL; @@ -53,9 +53,9 @@ class PatternContext { * Set pattern context property. * * @param string $name - * Property name. + * Property name. * @param mixed $value - * Property value. + * Property value. */ public function setProperty($name, $value) { $this->properties[$name] = $value; @@ -65,10 +65,10 @@ class PatternContext { * Check whereas the current context is of a given type. * * @param string $type - * Type string. + * Type string. * * @return bool - * Whereas the current context is of a given type. + * Whereas the current context is of a given type. */ public function isOfType($type) { return $this->type == $type; @@ -78,7 +78,7 @@ class PatternContext { * Get context type. * * @return string - * Context type. + * Context type. */ public function getType() { return $this->type; diff --git a/src/Element/PatternPreview.php b/src/Element/PatternPreview.php index 1c8f1844b..f7d0d2416 100644 --- a/src/Element/PatternPreview.php +++ b/src/Element/PatternPreview.php @@ -2,7 +2,7 @@ namespace Drupal\ui_patterns\Element; -use \Drupal\Core\Render\Markup; +use Drupal\Core\Render\Markup; use Drupal\ui_patterns\UiPatterns; /** diff --git a/src/Form/PatternDisplayFormTrait.php b/src/Form/PatternDisplayFormTrait.php index a60708389..1480332d4 100644 --- a/src/Form/PatternDisplayFormTrait.php +++ b/src/Form/PatternDisplayFormTrait.php @@ -20,13 +20,13 @@ trait PatternDisplayFormTrait { * Build pattern display form. * * @param array $form - * Form array. + * Form array. * @param string $tag - * Source field tag. + * Source field tag. * @param array $context - * Plugin context. + * Plugin context. * @param array $configuration - * Default configuration coming form the host form. + * Default configuration coming form the host form. */ public function buildPatternDisplayForm(array &$form, $tag, array $context, array $configuration) { @@ -57,16 +57,16 @@ trait PatternDisplayFormTrait { * Get mapping form. * * @param string $pattern_id - * Pattern ID for which to print the mapping form for. + * Pattern ID for which to print the mapping form for. * @param string $tag - * Source field plugin tag. + * Source field plugin tag. * @param array $context - * Plugin context. + * Plugin context. * @param array $configuration - * Default configuration coming form the host form. + * Default configuration coming form the host form. * * @return array - * Mapping form. + * Mapping form. */ public function getMappingForm($pattern_id, $tag, array $context, array $configuration) { /** @var \Drupal\ui_patterns\Definition\PatternDefinition $pattern */ @@ -131,9 +131,9 @@ trait PatternDisplayFormTrait { * Normalize settings coming from a form submission. * * @param array $settings - * Pattern display form values array. + * Pattern display form values array. */ - static public function processFormStateValues(array &$settings) { + public static function processFormStateValues(array &$settings) { // Normalize only when necessary. if (isset($settings['pattern_mapping'][$settings['pattern']]['settings'])) { $settings['pattern_mapping'] = $settings['pattern_mapping'][$settings['pattern']]['settings']; @@ -163,14 +163,14 @@ trait PatternDisplayFormTrait { * Helper function: return mapping destination given plugin id and field name. * * @param string $plugin - * Current plugin ID. + * Current plugin ID. * @param string $source - * Source field name. + * Source field name. * @param array $settings - * Setting array. + * Setting array. * * @return string|null - * Destination field or NULL if none found. + * Destination field or NULL if none found. */ public function getMappingDestination($plugin, $source, array $settings) { $mapping_id = $plugin . PatternSourceBase::DERIVATIVE_SEPARATOR . $source; @@ -184,14 +184,14 @@ trait PatternDisplayFormTrait { * Helper function: check if given source field has mapping destination. * * @param string $plugin - * Current plugin ID. + * Current plugin ID. * @param string $source - * Source field name. + * Source field name. * @param array $settings - * Setting array. + * Setting array. * * @return bool - * TRUE if source has destination field, FALSE otherwise. + * TRUE if source has destination field, FALSE otherwise. */ public function hasMappingDestination($plugin, $source, array $settings) { return $this->getMappingDestination($plugin, $source, $settings) !== NULL; @@ -201,14 +201,14 @@ trait PatternDisplayFormTrait { * Helper function: get default value. * * @param array $configuration - * Configuration. + * Configuration. * @param string $field_name - * Field name. + * Field name. * @param string $value - * Value name. + * Value name. * * @return string - * Field property value. + * Field property value. */ protected function getDefaultValue(array $configuration, $field_name, $value) { if (isset($configuration['pattern_mapping'][$field_name][$value])) { diff --git a/src/Plugin/Deriver/AbstractPatternsDeriver.php b/src/Plugin/Deriver/AbstractPatternsDeriver.php index b4a936cbd..9f24f8fd1 100644 --- a/src/Plugin/Deriver/AbstractPatternsDeriver.php +++ b/src/Plugin/Deriver/AbstractPatternsDeriver.php @@ -59,12 +59,12 @@ abstract class AbstractPatternsDeriver extends DeriverBase implements PatternsDe * Get pattern data object. * * @param array $definition - * Pattern definition array. + * Pattern definition array. * * @return \Drupal\ui_patterns\Definition\PatternDefinition - * Pattern definition object. + * Pattern definition object. */ - protected function getPatternDefinition($definition = []) { + protected function getPatternDefinition(array $definition = []) { return new PatternDefinition($definition); } @@ -72,10 +72,10 @@ abstract class AbstractPatternsDeriver extends DeriverBase implements PatternsDe * Validate pattern definition. * * @param \Drupal\ui_patterns\Definition\PatternDefinition $definition - * Pattern definition. + * Pattern definition. * * @return bool - * Whereas current pattern definition is valid or not. + * Whereas current pattern definition is valid or not. */ protected function isValidPatternDefinition(PatternDefinition $definition) { $data_definition = PatternDataDefinition::create(); diff --git a/src/Plugin/Deriver/PatternsDeriverInterface.php b/src/Plugin/Deriver/PatternsDeriverInterface.php index 8ac384ff7..fe74332c9 100644 --- a/src/Plugin/Deriver/PatternsDeriverInterface.php +++ b/src/Plugin/Deriver/PatternsDeriverInterface.php @@ -13,7 +13,7 @@ interface PatternsDeriverInterface { * Get pattern definition objects. * * @return \Drupal\ui_patterns\Definition\PatternDefinition[] - * List of pattern definitions contained in the file. + * List of pattern definitions contained in the file. */ public function getPatterns(); diff --git a/src/Plugin/Deriver/YamlPatternsDeriverInterface.php b/src/Plugin/Deriver/YamlPatternsDeriverInterface.php index 947f8c525..ca5de384d 100644 --- a/src/Plugin/Deriver/YamlPatternsDeriverInterface.php +++ b/src/Plugin/Deriver/YamlPatternsDeriverInterface.php @@ -13,7 +13,7 @@ interface YamlPatternsDeriverInterface extends PatternsDeriverInterface { * Get list of possible yaml definition file extensions. * * @return string[] - * List of allowed file extensions. + * List of allowed file extensions. */ public function getFileExtensions(); diff --git a/src/Plugin/PatternBase.php b/src/Plugin/PatternBase.php index f23567e1c..2cc71fd2d 100644 --- a/src/Plugin/PatternBase.php +++ b/src/Plugin/PatternBase.php @@ -97,11 +97,11 @@ abstract class PatternBase extends PluginBase implements PatternInterface, Conta * Process libraries. * * @param array|string $libraries - * List of dependencies or "dependencies:" root property. + * List of dependencies or "dependencies:" root property. * @param string $base_path - * Pattern base path. + * Pattern base path. * @param string $parent - * Item parent set in previous recursive iteration, if any. + * Item parent set in previous recursive iteration, if any. */ protected function processLibraries(&$libraries, $base_path, $parent = '') { if (!is_string($libraries)) { @@ -125,10 +125,10 @@ abstract class PatternBase extends PluginBase implements PatternInterface, Conta * Process 'use' definition property. * * @param \Drupal\ui_patterns\Definition\PatternDefinition $definition - * Pattern definition array. + * Pattern definition array. * * @return array - * Processed hook definition portion. + * Processed hook definition portion. */ protected function processUseProperty(PatternDefinition $definition) { $return = []; @@ -145,10 +145,10 @@ abstract class PatternBase extends PluginBase implements PatternInterface, Conta * Process theme variables. * * @param \Drupal\ui_patterns\Definition\PatternDefinition $definition - * Pattern definition array. + * Pattern definition array. * * @return array - * Processed hook definition portion. + * Processed hook definition portion. */ protected function processVariables(PatternDefinition $definition) { $return = []; diff --git a/src/Plugin/PatternInterface.php b/src/Plugin/PatternInterface.php index 3658c4206..8d33478c4 100644 --- a/src/Plugin/PatternInterface.php +++ b/src/Plugin/PatternInterface.php @@ -15,7 +15,7 @@ interface PatternInterface { * @see ui_patterns_theme() * * @return array - * Theme implementation array. + * Theme implementation array. */ public function getThemeImplementation(); @@ -25,7 +25,7 @@ interface PatternInterface { * @see ui_patterns_library_info_build() * * @return array - * Library definitions array. + * Library definitions array. */ public function getLibraryDefinitions(); diff --git a/src/Plugin/PatternSourceInterface.php b/src/Plugin/PatternSourceInterface.php index 37ca973af..a98016cce 100644 --- a/src/Plugin/PatternSourceInterface.php +++ b/src/Plugin/PatternSourceInterface.php @@ -11,12 +11,12 @@ interface PatternSourceInterface { * Source field factory method. * * @param string $name - * Machine name. + * Machine name. * @param string $label - * Human readable label. + * Human readable label. * * @return \Drupal\ui_patterns\Definition\PatternSourceField - * Source field instance. + * Source field instance. */ public function getSourceField($name, $label); @@ -24,7 +24,7 @@ interface PatternSourceInterface { * Return list of source fields. * * @return \Drupal\ui_patterns\Definition\PatternSourceField[] - * List of source fields. + * List of source fields. */ public function getSourceFields(); @@ -32,10 +32,10 @@ interface PatternSourceInterface { * Get context property value, if any. * * @param string $name - * Context property name. + * Context property name. * * @return mixed - * Context property value. + * Context property value. */ public function getContextProperty($name); diff --git a/src/Template/TwigExtension.php b/src/Template/TwigExtension.php index 4aa2dd193..6f1dd93fb 100644 --- a/src/Template/TwigExtension.php +++ b/src/Template/TwigExtension.php @@ -30,16 +30,16 @@ class TwigExtension extends \Twig_Extension { * Render given pattern. * * @param string $id - * Pattern ID. + * Pattern ID. * @param array $fields - * Pattern fields. + * Pattern fields. * * @return array - * Pattern render array. + * Pattern render array. * * @see \Drupal\ui_patterns\Element\Pattern */ - public function renderPattern($id, $fields = []) { + public function renderPattern($id, array $fields = []) { return [ '#type' => 'pattern', '#id' => $id, @@ -51,10 +51,10 @@ class TwigExtension extends \Twig_Extension { * Render given pattern. * * @param string $id - * Pattern ID. + * Pattern ID. * * @return array - * Pattern render array. + * Pattern render array. * * @see \Drupal\ui_patterns\Element\Pattern */ diff --git a/src/TypedData/PatternDataDefinition.php b/src/TypedData/PatternDataDefinition.php index 7865c2084..a0e89b902 100644 --- a/src/TypedData/PatternDataDefinition.php +++ b/src/TypedData/PatternDataDefinition.php @@ -57,7 +57,7 @@ class PatternDataDefinition extends MapDataDefinition { * Get valid machine name definition. * * @return \Drupal\Core\TypedData\DataDefinition - * Data definition instance. + * Data definition instance. */ protected function getMachineNameDefinition() { return DataDefinition::create('string') @@ -68,7 +68,7 @@ class PatternDataDefinition extends MapDataDefinition { * Get definition for 'field' property. * * @return \Drupal\Core\TypedData\ListDataDefinition - * Data definition instance. + * Data definition instance. */ protected function getFieldsDefinition() { return new ListDataDefinition([], MapDataDefinition::create() diff --git a/src/UiPatterns.php b/src/UiPatterns.php index 99cae0f40..c480b7129 100644 --- a/src/UiPatterns.php +++ b/src/UiPatterns.php @@ -13,7 +13,7 @@ class UiPatterns { * Get pattern manager instance. * * @return \Drupal\ui_patterns\UiPatternsManager - * UI Patterns manager instance. + * UI Patterns manager instance. */ public static function getManager() { return \Drupal::service('plugin.manager.ui_patterns'); @@ -23,7 +23,7 @@ class UiPatterns { * Get pattern field sources manager instance. * * @return \Drupal\ui_patterns\UiPatternsSourceManager - * UI Patterns field sources manager instance. + * UI Patterns field sources manager instance. */ public static function getSourceManager() { return \Drupal::service('plugin.manager.ui_patterns_source'); @@ -33,10 +33,10 @@ class UiPatterns { * Get pattern definition. * * @param string $id - * Pattern ID. + * Pattern ID. * * @return \Drupal\ui_patterns\Definition\PatternDefinition - * Pattern object instance. + * Pattern object instance. */ public static function getPatternDefinition($id) { return \Drupal::service('plugin.manager.ui_patterns')->getDefinition($id); @@ -46,7 +46,7 @@ class UiPatterns { * Get pattern definitions. * * @return \Drupal\ui_patterns\Definition\PatternDefinition[] - * Pattern object instance. + * Pattern object instance. */ public static function getPatternDefinitions() { return \Drupal::service('plugin.manager.ui_patterns')->getDefinitions(); diff --git a/src/UiPatternsManager.php b/src/UiPatternsManager.php index 254f8a259..83a827510 100644 --- a/src/UiPatternsManager.php +++ b/src/UiPatternsManager.php @@ -41,7 +41,7 @@ class UiPatternsManager extends DefaultPluginManager implements PluginManagerInt * Get pattern objects. * * @return \Drupal\ui_patterns\Plugin\PatternBase[] - * Pattern objects. + * Pattern objects. */ public function getPatterns() { $patterns = []; @@ -55,7 +55,7 @@ class UiPatternsManager extends DefaultPluginManager implements PluginManagerInt * Return pattern definitions. * * @return \Drupal\ui_patterns\Definition\PatternDefinition[] - * Pattern definitions. + * Pattern definitions. */ public function getDefinitions() { $definitions = $this->getCachedDefinitions(); diff --git a/src/UiPatternsSourceManager.php b/src/UiPatternsSourceManager.php index edf99d1a3..d9cccc6ab 100644 --- a/src/UiPatternsSourceManager.php +++ b/src/UiPatternsSourceManager.php @@ -24,10 +24,10 @@ class UiPatternsSourceManager extends DefaultPluginManager { * Filter definitions by given tag. * * @param string $tag - * Tag used on plugin annotation. + * Tag used on plugin annotation. * * @return array - * List of definitions tagged with given tag. + * List of definitions tagged with given tag. */ public function getDefinitionsByTag($tag) { return array_filter($this->getDefinitions(), function ($definition) use ($tag) { @@ -39,14 +39,14 @@ class UiPatternsSourceManager extends DefaultPluginManager { * Get field source definitions by specified tags. * * @param string $tag - * Field source tag. + * Field source tag. * @param array $context - * Plugin context. + * Plugin context. * * @return \Drupal\ui_patterns\Definition\PatternSourceField[] - * List of source fields. + * List of source fields. */ - public function getFieldsByTag($tag, $context) { + public function getFieldsByTag($tag, array $context) { /** @var \Drupal\ui_patterns\Plugin\PatternSourceInterface $plugin */ $fields = []; foreach ($this->getDefinitionsByTag($tag) as $id => $definition) { diff --git a/tests/features/overview.feature b/tests/features/overview.feature index 2c67b1378..3f5a74ac0 100644 --- a/tests/features/overview.feature +++ b/tests/features/overview.feature @@ -71,11 +71,12 @@ Feature: Overview And the response should contain "/ui_patterns_test_theme/templates/patterns/media/js/media2.js" And the response should contain "/misc/tabledrag.js" + @javascript Scenario: Patterns overview page will show validation errors after clearing the cache. Given I am logged in as a user with the "access patterns page" permission - And the cache has been cleared - When I am on "/patterns" + And the cache has been cleared + And I reload the page Then I should see the following error messages: | error messages | | Pattern 'bad_pattern' is skipped because of the following validation error(s): | diff --git a/ui_patterns.api.php b/ui_patterns.api.php index d497a83d8..7db0a1f6b 100644 --- a/ui_patterns.api.php +++ b/ui_patterns.api.php @@ -11,11 +11,11 @@ use Drupal\ui_patterns\Element\PatternContext; * Alter UI Patterns definitions. * * @param \Drupal\ui_patterns\Definition\PatternDefinition[] $definitions - * Pattern definitions. + * Pattern definitions. * * @see \Drupal\ui_patterns\UiPatternsManager */ -function hook_ui_patterns_info_alter(&$definitions) { +function hook_ui_patterns_info_alter(array &$definitions) { $definitions['my_pattern']->setLabel('My new label'); } -- GitLab