diff --git a/.gitignore b/.gitignore index fd824867..d8633ada 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /phpunit.xml /docker-compose.override.yml /runner.yml +/.editorconfig +/.gitattributes diff --git a/.travis.yml b/.travis.yml index d148b376..c602fc47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,34 +2,36 @@ sudo: required language: php php: -- 7.1 -- 7.2 +- 7.3 +- 7.4 services: - docker env: global: - - DOCKER_COMPOSE_VERSION=1.17.1 + - DOCKER_COMPOSE_VERSION=1.25.5 matrix: - - DRUPAL_VERSION=~8.6 - - DRUPAL_VERSION=~8.7 - - DRUPAL_VERSION=8.8.x-dev + - DRUPAL_VERSION=~8.8.7 GRUMPHP_CONFIG=grumphp.drupal8.yml + - DRUPAL_VERSION=~8.9.0 GRUMPHP_CONFIG=grumphp.drupal8.yml + - DRUPAL_VERSION=~9.0.0 GRUMPHP_CONFIG=grumphp.yml + - DRUPAL_VERSION=9.1.x-dev GRUMPHP_CONFIG=grumphp.yml matrix: allow_failures: - - env: DRUPAL_VERSION=8.8.x-dev + - env: DRUPAL_VERSION=9.1.x-dev before_install: - docker-compose up -d install: -- docker-compose exec -u root php composer require webflo/drupal-core-require-dev:$DRUPAL_VERSION --dev +- docker-compose exec -u root php composer require drupal/core-recommended:$DRUPAL_VERSION --dev - docker-compose exec -u root php chown -R www-data:www-data build script: -- docker-compose exec -u www-data php ./vendor/bin/grumphp run +- docker-compose exec -u www-data php ./vendor/bin/grumphp run -c $GRUMPHP_CONFIG - docker-compose exec -u www-data php ./vendor/bin/phpunit notifications: - email: false \ No newline at end of file + email: false + diff --git a/composer.json b/composer.json index d4d08d1b..3260541b 100644 --- a/composer.json +++ b/composer.json @@ -15,21 +15,19 @@ "require-dev": { "composer/installers": "^1.2", "cweagans/composer-patches": "~1.4", - "drupal-composer/drupal-scaffold": "^2.2", - "drupal/config_installer": "~1", - "drupal/console": "~1", - "drush/drush": "~9", - "drupal/ds": "~3", - "drupal/field_group": "~1", - "drupal/coffee": "~1", "drupal/config_devel": "~1", - "drupal/panels": "~4", + "drupal/core-composer-scaffold": "^8.8 || ^9", + "drupal/core-dev": "^8.8 || ^9", + "drupal/core-recommended": "~8.9.0", + "drupal/ds": "~3", + "drupal/field_group": "~3", "drupal/page_manager": "*", + "drupal/panels": "~4", "drupal/paragraphs": "~1", "drupal/token": "~1", - "phpro/grumphp": "~0.14", - "webflo/drupal-core-require-dev": "~8.7", - "openeuropa/task-runner": "~1.0-beta3" + "drush/drush": "~10", + "openeuropa/task-runner": "~1.0-beta3", + "phpro/grumphp": "~0.14" }, "repositories": [ { @@ -48,13 +46,17 @@ } }, "scripts": { - "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold", "post-install-cmd": "./vendor/bin/run drupal:site-setup", "post-update-cmd": "./vendor/bin/run drupal:site-setup" }, "extra": { "composer-exit-on-patch-failure": true, "enable-patching": true, + "drupal-scaffold": { + "locations": { + "web-root": "build/" + } + }, "installer-paths": { "build/core": ["type:drupal-core"], "build/modules/contrib/{$name}": ["type:drupal-module"], diff --git a/docker-compose.yml b/docker-compose.yml index 4796a637..c9c010c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: "2" services: mariadb: - image: wodby/mariadb:10.1-3.3.0 + image: wodby/mariadb:10.3-3.8.4 stop_grace_period: 30s environment: MYSQL_ROOT_PASSWORD: password @@ -12,7 +12,7 @@ services: MYSQL_PASSWORD: drupal php: - image: wodby/drupal-php:${TRAVIS_PHP_VERSION}-4.6.3 + image: wodby/drupal-php:${TRAVIS_PHP_VERSION}-4.15.9 environment: DB_HOST: mariadb DB_USER: drupal diff --git a/grumphp.yml.dist b/grumphp.drupal8.yml similarity index 100% rename from grumphp.yml.dist rename to grumphp.drupal8.yml diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 00000000..79311e22 --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,16 @@ +grumphp: + ascii: + failed: ~ + succeeded: ~ + tasks: + phpcs: + standard: vendor/drupal/coder/coder_sniffer/Drupal/ + ignore_patterns: + - build/ + - vendor/ + triggered_by: + - php + - module + - install + - inc + - theme diff --git a/modules/ui_patterns_ds/tests/modules/ui_patterns_ds_test/ui_patterns_ds_test.info.yml b/modules/ui_patterns_ds/tests/modules/ui_patterns_ds_test/ui_patterns_ds_test.info.yml index 16ede36d..2142c359 100644 --- a/modules/ui_patterns_ds/tests/modules/ui_patterns_ds_test/ui_patterns_ds_test.info.yml +++ b/modules/ui_patterns_ds/tests/modules/ui_patterns_ds_test/ui_patterns_ds_test.info.yml @@ -2,6 +2,7 @@ name: 'UI Patterns Display Suite Test' type: module description: 'Test module for UI Patterns.' core: 8.x +core_version_requirement: ^8 || ^9 hidden: true package: 'User interface' dependencies: diff --git a/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldRenderTest.php b/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldRenderTest.php index b99f62b5..64ef3168 100644 --- a/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldRenderTest.php +++ b/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldRenderTest.php @@ -12,6 +12,13 @@ */ class UiPatternsFieldRenderTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldSettingsTest.php b/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldSettingsTest.php index 74f7e31f..2487d9a9 100644 --- a/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldSettingsTest.php +++ b/modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldSettingsTest.php @@ -12,6 +12,13 @@ */ class UiPatternsFieldSettingsTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_ds/ui_patterns_ds.info.yml b/modules/ui_patterns_ds/ui_patterns_ds.info.yml index 3058bad0..a37275e2 100644 --- a/modules/ui_patterns_ds/ui_patterns_ds.info.yml +++ b/modules/ui_patterns_ds/ui_patterns_ds.info.yml @@ -2,6 +2,7 @@ name: UI Patterns Display Suite type: module description: Use patterns as Display Suite field templates. It also provides Display Suite pattern sources. core: 8.x +core_version_requirement: ^8 || ^9 package: User interface dependencies: - ds:ds diff --git a/modules/ui_patterns_ds/ui_patterns_ds.services.yml b/modules/ui_patterns_ds/ui_patterns_ds.services.yml index 580ff770..1cea2e17 100644 --- a/modules/ui_patterns_ds/ui_patterns_ds.services.yml +++ b/modules/ui_patterns_ds/ui_patterns_ds.services.yml @@ -1,4 +1,3 @@ services: ui_patterns_ds.field_template_processor: class: Drupal\ui_patterns_ds\FieldTemplateProcessor - diff --git a/modules/ui_patterns_field_group/tests/modules/ui_patterns_field_group_test/ui_patterns_field_group_test.info.yml b/modules/ui_patterns_field_group/tests/modules/ui_patterns_field_group_test/ui_patterns_field_group_test.info.yml index cfe353b8..a6226496 100644 --- a/modules/ui_patterns_field_group/tests/modules/ui_patterns_field_group_test/ui_patterns_field_group_test.info.yml +++ b/modules/ui_patterns_field_group/tests/modules/ui_patterns_field_group_test/ui_patterns_field_group_test.info.yml @@ -2,6 +2,7 @@ name: 'UI Patterns Field Group Test' type: module description: 'Test module for UI Patterns.' core: 8.x +core_version_requirement: ^8 || ^9 hidden: true package: 'User interface' dependencies: diff --git a/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupRenderTest.php b/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupRenderTest.php index dd7e8c34..8f59175e 100644 --- a/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupRenderTest.php +++ b/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupRenderTest.php @@ -12,6 +12,13 @@ */ class UiPatternsFieldGroupRenderTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupSettingsTest.php b/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupSettingsTest.php index 632aa369..6ff078e4 100644 --- a/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupSettingsTest.php +++ b/modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupSettingsTest.php @@ -13,6 +13,13 @@ */ class UiPatternsFieldGroupSettingsTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_field_group/ui_patterns_field_group.info.yml b/modules/ui_patterns_field_group/ui_patterns_field_group.info.yml index dab10213..2c5a4b0b 100644 --- a/modules/ui_patterns_field_group/ui_patterns_field_group.info.yml +++ b/modules/ui_patterns_field_group/ui_patterns_field_group.info.yml @@ -2,6 +2,7 @@ name: UI Patterns Field Group type: module description: Use patterns as field groups templates. core: 8.x +core_version_requirement: ^8 || ^9 package: User interface dependencies: - field_group:field_group diff --git a/modules/ui_patterns_layouts/tests/modules/ui_patterns_layouts_test/ui_patterns_layouts_test.info.yml b/modules/ui_patterns_layouts/tests/modules/ui_patterns_layouts_test/ui_patterns_layouts_test.info.yml index ccef506d..9f2d26c6 100644 --- a/modules/ui_patterns_layouts/tests/modules/ui_patterns_layouts_test/ui_patterns_layouts_test.info.yml +++ b/modules/ui_patterns_layouts/tests/modules/ui_patterns_layouts_test/ui_patterns_layouts_test.info.yml @@ -2,6 +2,7 @@ name: 'UI Patterns Layouts Test' type: module description: 'Test module for UI Patterns.' core: 8.x +core_version_requirement: ^8 || ^9 hidden: true package: 'User interface' dependencies: @@ -18,4 +19,3 @@ config_devel: - field.field.node.article.body - node.type.article - core.entity_view_display.node.article.default - diff --git a/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsRenderTest.php b/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsRenderTest.php index 7aab0498..44feaaf4 100644 --- a/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsRenderTest.php +++ b/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsRenderTest.php @@ -12,6 +12,13 @@ */ class UiPatternsLayoutsRenderTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsSettingsTest.php b/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsSettingsTest.php index f07732c7..0b1c589f 100644 --- a/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsSettingsTest.php +++ b/modules/ui_patterns_layouts/tests/src/FunctionalJavascript/UiPatternsLayoutsSettingsTest.php @@ -12,6 +12,13 @@ */ class UiPatternsLayoutsSettingsTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_layouts/ui_patterns_layouts.info.yml b/modules/ui_patterns_layouts/ui_patterns_layouts.info.yml index 472023e2..d0f06b18 100644 --- a/modules/ui_patterns_layouts/ui_patterns_layouts.info.yml +++ b/modules/ui_patterns_layouts/ui_patterns_layouts.info.yml @@ -2,6 +2,7 @@ name: UI Patterns Layouts type: module description: Use patterns as layouts via the Layout Discovery module. core: 8.x +core_version_requirement: ^8 || ^9 package: User interface dependencies: - drupal:layout_discovery diff --git a/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php b/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php index 88e34399..5601003b 100644 --- a/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php +++ b/modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php @@ -4,6 +4,8 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Extension\ExtensionDiscovery; +use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\TypedData\TypedDataManager; use Drupal\ui_patterns\Plugin\Deriver\AbstractYamlPatternsDeriver; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -80,6 +82,10 @@ class LibraryDeriver extends AbstractYamlPatternsDeriver { * The base plugin ID. * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager * Typed data manager service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * Messenger. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * File system service. * @param string $root * Application root directory. * @param array $extensions @@ -89,8 +95,8 @@ class LibraryDeriver extends AbstractYamlPatternsDeriver { * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * Theme handler service. */ - public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, $root, array $extensions, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { - parent::__construct($base_plugin_id, $typed_data_manager); + public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, MessengerInterface $messenger, FileSystemInterface $file_system, $root, array $extensions, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { + parent::__construct($base_plugin_id, $typed_data_manager, $messenger, $file_system); $this->root = $root; $this->fileExtensions = $extensions; $this->moduleHandler = $module_handler; @@ -105,6 +111,8 @@ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, $container->get('typed_data_manager'), + $container->get('messenger'), + $container->get('file_system'), $container->get('app.root'), $container->getParameter('ui_patterns_library.file_extensions'), $container->get('module_handler'), diff --git a/modules/ui_patterns_library/tests/modules/ui_patterns_library_bad_definition_test/ui_patterns_library_bad_definition_test.info.yml b/modules/ui_patterns_library/tests/modules/ui_patterns_library_bad_definition_test/ui_patterns_library_bad_definition_test.info.yml index 8763ac09..5c6900d0 100644 --- a/modules/ui_patterns_library/tests/modules/ui_patterns_library_bad_definition_test/ui_patterns_library_bad_definition_test.info.yml +++ b/modules/ui_patterns_library/tests/modules/ui_patterns_library_bad_definition_test/ui_patterns_library_bad_definition_test.info.yml @@ -1,3 +1,4 @@ name: 'UI Patterns bad definition test' type: module core: 8.x +core_version_requirement: ^8 || ^9 diff --git a/modules/ui_patterns_library/tests/modules/ui_patterns_library_module_test/ui_patterns_library_module_test.info.yml b/modules/ui_patterns_library/tests/modules/ui_patterns_library_module_test/ui_patterns_library_module_test.info.yml index a46c4374..8fbd6cc8 100644 --- a/modules/ui_patterns_library/tests/modules/ui_patterns_library_module_test/ui_patterns_library_module_test.info.yml +++ b/modules/ui_patterns_library/tests/modules/ui_patterns_library_module_test/ui_patterns_library_module_test.info.yml @@ -1,3 +1,4 @@ name: 'UI Patterns library module test' type: module core: 8.x +core_version_requirement: ^8 || ^9 diff --git a/modules/ui_patterns_library/tests/modules/ui_patterns_library_theme_test/ui_patterns_library_theme_test.info.yml b/modules/ui_patterns_library/tests/modules/ui_patterns_library_theme_test/ui_patterns_library_theme_test.info.yml index 386175b7..d0069a21 100644 --- a/modules/ui_patterns_library/tests/modules/ui_patterns_library_theme_test/ui_patterns_library_theme_test.info.yml +++ b/modules/ui_patterns_library/tests/modules/ui_patterns_library_theme_test/ui_patterns_library_theme_test.info.yml @@ -1,3 +1,5 @@ name: 'UI Patterns library theme test' type: theme core: 8.x +core_version_requirement: ^8 || ^9 +base theme: stark diff --git a/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryBadDefinitionTest.php b/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryBadDefinitionTest.php index 89ad31f0..3f41c4fa 100644 --- a/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryBadDefinitionTest.php +++ b/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryBadDefinitionTest.php @@ -11,6 +11,13 @@ */ class UiPatternsLibraryBadDefinitionTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * {@inheritdoc} */ diff --git a/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php b/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php index 3b1fecba..3188b00b 100644 --- a/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php +++ b/modules/ui_patterns_library/tests/src/FunctionalJavascript/UiPatternsLibraryOverviewTest.php @@ -12,6 +12,13 @@ */ class UiPatternsLibraryOverviewTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'ui_patterns_library_theme_test'; + /** * {@inheritdoc} */ @@ -24,13 +31,9 @@ class UiPatternsLibraryOverviewTest extends WebDriverTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); - $this->container->get('theme_installer')->install(['ui_patterns_library_theme_test']); - $this->container->get('theme_handler')->setDefault('ui_patterns_library_theme_test'); - $this->container->set('theme.registry', NULL); - $user = $this->drupalCreateUser(['access patterns page']); $this->drupalLogin($user); } @@ -57,7 +60,7 @@ public function testOverviewPage() { // Test view single page link. $session->linkExists("View {$pattern['label']} as stand-alone"); $link = $this->getSession()->getPage()->findLink("View {$pattern['label']} as stand-alone"); - $this->assertContains('/patterns/' . $pattern['name'], $link->getAttribute('href')); + $this->assertStringContainsString('/patterns/' . $pattern['name'], $link->getAttribute('href')); } } @@ -67,7 +70,7 @@ public function testOverviewPage() { public function testSinglePages() { $session = $this->assertSession(); - foreach ($this->getExpectedPatterns() as $index => $pattern) { + foreach ($this->getExpectedPatterns() as $pattern) { $this->drupalGet('/patterns/' . $pattern['name']); $session->elementContains('css', 'h1', $pattern['label']); diff --git a/modules/ui_patterns_library/ui_patterns_library.info.yml b/modules/ui_patterns_library/ui_patterns_library.info.yml index 3121a23a..23ad2ff1 100644 --- a/modules/ui_patterns_library/ui_patterns_library.info.yml +++ b/modules/ui_patterns_library/ui_patterns_library.info.yml @@ -2,6 +2,7 @@ name: UI Patterns Library type: module description: Exposed patterns in you modules and themes and display them in a pattern library page. core: 8.x +core_version_requirement: ^8 || ^9 package: User interface dependencies: - ui_patterns:ui_patterns diff --git a/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/config/install/views.view.articles.yml b/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/config/install/views.view.articles.yml index dffea42c..59f8ca52 100644 --- a/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/config/install/views.view.articles.yml +++ b/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/config/install/views.view.articles.yml @@ -15,6 +15,7 @@ tag: '' base_table: node_field_data base_field: nid core: 8.x +core_version_requirement: ^8 || ^9 display: default: display_plugin: default diff --git a/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/ui_patterns_views_test.info.yml b/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/ui_patterns_views_test.info.yml index 03073c51..e6954e14 100644 --- a/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/ui_patterns_views_test.info.yml +++ b/modules/ui_patterns_views/tests/modules/ui_patterns_views_test/ui_patterns_views_test.info.yml @@ -2,6 +2,7 @@ name: 'UI Patterns Views Test' type: module description: 'Test module for UI Patterns.' core: 8.x +core_version_requirement: ^8 || ^9 hidden: true package: 'User interface' dependencies: diff --git a/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsRenderTest.php b/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsRenderTest.php index 239a6ac5..b58ee19c 100644 --- a/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsRenderTest.php +++ b/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsRenderTest.php @@ -14,6 +14,13 @@ class UiPatternsViewsRenderTest extends WebDriverTestBase { use TwigDebugTrait; + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsSettingsTest.php b/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsSettingsTest.php index 6e567eb2..2c7c5439 100644 --- a/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsSettingsTest.php +++ b/modules/ui_patterns_views/tests/src/FunctionalJavascript/UiPatternsViewsSettingsTest.php @@ -12,6 +12,13 @@ */ class UiPatternsViewsSettingsTest extends WebDriverTestBase { + /** + * Default theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/modules/ui_patterns_views/ui_patterns_views.info.yml b/modules/ui_patterns_views/ui_patterns_views.info.yml index 30371593..f1297fdd 100644 --- a/modules/ui_patterns_views/ui_patterns_views.info.yml +++ b/modules/ui_patterns_views/ui_patterns_views.info.yml @@ -2,6 +2,7 @@ name: UI Patterns Views type: module description: Use patterns as Views templates. core: 8.x +core_version_requirement: ^8 || ^9 package: User interface dependencies: - drupal:views diff --git a/modules/ui_patterns_views/ui_patterns_views.module b/modules/ui_patterns_views/ui_patterns_views.module index 388b2872..0b2ad4c6 100644 --- a/modules/ui_patterns_views/ui_patterns_views.module +++ b/modules/ui_patterns_views/ui_patterns_views.module @@ -47,7 +47,7 @@ function template_preprocess_pattern_views_row(array &$variables) { $variables['pattern'] = []; if ($view->preview && !isset($view->element['#embed'])) { - drupal_set_message(t("Pattern Views row plugin does not support preview."), 'warning'); + \Drupal::messenger()->addWarning(t("Pattern Views row plugin does not support preview.")); $variables['pattern'] = ['#type' => 'status_messages']; } elseif (!empty($fields)) { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 13971453..5322204e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + @@ -9,7 +9,7 @@ - + ./tests/ ./modules/*/tests/ diff --git a/runner.yml.dist b/runner.yml.dist index adf7fbf1..5cfd75e5 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -24,7 +24,14 @@ selenium: commands: drupal:site-setup: - - { task: "symlink", from: "../../..", to: "${drupal.root}/modules/custom/ui_patterns" } + - { task: "symlink", from: "../../../../modules", to: "${drupal.root}/modules/custom/ui_patterns/modules" } + - { task: "symlink", from: "../../../../src", to: "${drupal.root}/modules/custom/ui_patterns/src" } + - { task: "symlink", from: "../../../../templates", to: "${drupal.root}/modules/custom/ui_patterns/templates" } + - { task: "symlink", from: "../../../../tests", to: "${drupal.root}/modules/custom/ui_patterns/tests" } + - { task: "symlink", from: "../../../../ui_patterns.info.yml", to: "${drupal.root}/modules/custom/ui_patterns/ui_patterns.info.yml" } + - { task: "symlink", from: "../../../../ui_patterns.install", to: "${drupal.root}/modules/custom/ui_patterns/ui_patterns.install" } + - { task: "symlink", from: "../../../../ui_patterns.module", to: "${drupal.root}/modules/custom/ui_patterns/ui_patterns.module" } + - { task: "symlink", from: "../../../../ui_patterns.services.yml", to: "${drupal.root}/modules/custom/ui_patterns/ui_patterns.services.yml" } # Generate settings.testing.php, it will be used when running functional tests. - { task: "process-php", type: "write", config: "drupal.settings", source: "${drupal.root}/sites/default/default.settings.php", destination: "${drupal.root}/sites/default/settings.testing.php", override: true } - { task: "run", command: "drupal:drush-setup" } diff --git a/src/Definition/PatternSourceField.php b/src/Definition/PatternSourceField.php index 4809e5dc..8c9177d0 100644 --- a/src/Definition/PatternSourceField.php +++ b/src/Definition/PatternSourceField.php @@ -11,9 +11,32 @@ class PatternSourceField { const FIELD_KEY_SEPARATOR = ':'; + /** + * Field name. + * + * @var string + */ private $fieldName; + + /** + * Field label. + * + * @var string + */ private $fieldLabel; + + /** + * Plugin ID. + * + * @var string + */ private $pluginId; + + /** + * Plugin label. + * + * @var string + */ private $pluginLabel; /** @@ -29,7 +52,7 @@ public function __construct($field_name, $field_label, $plugin_id, $plugin_label /** * Get FieldName property. * - * @return mixed + * @return string * Property value. */ public function getFieldName() { @@ -39,7 +62,7 @@ public function getFieldName() { /** * Set FieldName property. * - * @param mixed $fieldName + * @param string $fieldName * Property value. * * @return $this @@ -52,7 +75,7 @@ public function setFieldName($fieldName) { /** * Get FieldLabel property. * - * @return mixed + * @return string * Property value. */ public function getFieldLabel() { @@ -62,7 +85,7 @@ public function getFieldLabel() { /** * Set FieldLabel property. * - * @param mixed $fieldLabel + * @param string $fieldLabel * Property value. * * @return $this @@ -75,7 +98,7 @@ public function setFieldLabel($fieldLabel) { /** * Get Plugin property. * - * @return mixed + * @return string * Property value. */ public function getPluginId() { @@ -85,7 +108,7 @@ public function getPluginId() { /** * Set Plugin property. * - * @param mixed $pluginId + * @param string $pluginId * Property value. * * @return $this @@ -98,7 +121,7 @@ public function setPluginId($pluginId) { /** * Get PluginLabel property. * - * @return mixed + * @return string * Property value. */ public function getPluginLabel() { @@ -108,7 +131,7 @@ public function getPluginLabel() { /** * Set PluginLabel property. * - * @param mixed $pluginLabel + * @param string $pluginLabel * Property value. * * @return $this diff --git a/src/Plugin/Deriver/AbstractPatternsDeriver.php b/src/Plugin/Deriver/AbstractPatternsDeriver.php index 9f24f8fd..152fb307 100644 --- a/src/Plugin/Deriver/AbstractPatternsDeriver.php +++ b/src/Plugin/Deriver/AbstractPatternsDeriver.php @@ -3,7 +3,9 @@ namespace Drupal\ui_patterns\Plugin\Deriver; use Drupal\Component\Plugin\Derivative\DeriverBase; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\TypedData\TypedDataManager; use Drupal\ui_patterns\Definition\PatternDefinition; use Drupal\ui_patterns\TypedData\PatternDataDefinition; @@ -16,6 +18,8 @@ */ abstract class AbstractPatternsDeriver extends DeriverBase implements PatternsDeriverInterface, ContainerDeriverInterface { + use StringTranslationTrait; + /** * Typed data manager service. * @@ -23,12 +27,20 @@ abstract class AbstractPatternsDeriver extends DeriverBase implements PatternsDe */ protected $typedDataManager; + /** + * The messenger. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * AbstractPatternsDeriver constructor. */ - public function __construct($base_plugin_id, TypedDataManager $typed_data_manager) { + public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, MessengerInterface $messenger) { $this->basePluginId = $base_plugin_id; $this->typedDataManager = $typed_data_manager; + $this->messenger = $messenger; } /** @@ -37,7 +49,8 @@ public function __construct($base_plugin_id, TypedDataManager $typed_data_manage public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('typed_data_manager') + $container->get('typed_data_manager'), + $container->get('messenger') ); } @@ -82,14 +95,14 @@ protected function isValidPatternDefinition(PatternDefinition $definition) { $violations = $this->typedDataManager->create($data_definition, $definition->toArray())->validate(); if ($violations->count()) { /** @var \Symfony\Component\Validator\ConstraintViolation $violation */ - drupal_set_message(t("Pattern ':id' is skipped because of the following validation error(s):", [':id' => $definition->id()]), 'error'); + $this->messenger->addError($this->t("Pattern ':id' is skipped because of the following validation error(s):", [':id' => $definition->id()])); foreach ($violations as $violation) { - $message = t('Validation error on ":id.:property": :message', [ + $message = $this->t('Validation error on ":id.:property": :message', [ ':id' => $definition->id(), ':property' => $violation->getPropertyPath(), ':message' => $violation->getMessage(), ]); - drupal_set_message($message, 'error'); + $this->messenger->addError($message); } return FALSE; } diff --git a/src/Plugin/Deriver/AbstractYamlPatternsDeriver.php b/src/Plugin/Deriver/AbstractYamlPatternsDeriver.php index 2a2bb9fd..a9ce9625 100644 --- a/src/Plugin/Deriver/AbstractYamlPatternsDeriver.php +++ b/src/Plugin/Deriver/AbstractYamlPatternsDeriver.php @@ -2,7 +2,11 @@ namespace Drupal\ui_patterns\Plugin\Deriver; +use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Site\Settings; +use Drupal\Core\TypedData\TypedDataManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class AbstractYamlPatternsDeriver. @@ -13,6 +17,43 @@ */ abstract class AbstractYamlPatternsDeriver extends AbstractPatternsDeriver implements YamlPatternsDeriverInterface { + /** + * File system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** + * Constructor. + * + * @param string $base_plugin_id + * The base plugin ID. + * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager + * Typed data manager service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * Messenger. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * File system service. + */ + public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, MessengerInterface $messenger, FileSystemInterface $file_system) { + parent::__construct($base_plugin_id, $typed_data_manager, $messenger); + + $this->fileSystem = $file_system; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('typed_data_manager'), + $container->get('messenger'), + $container->get('file_system') + ); + } + /** * {@inheritdoc} */ @@ -21,7 +62,11 @@ public function fileScanDirectory($directory) { $extensions = $this->getFileExtensions(); $extensions = array_map('preg_quote', $extensions); $extensions = implode('|', $extensions); - return file_scan_directory($directory, "/{$extensions}$/", $options, 0); + $files = $this->fileSystem->scanDirectory($directory, "/{$extensions}$/", $options); + // In different file systems order of files in a folder can be different + // that can break tests. So let's sort them alphabetically manually. + ksort($files); + return $files; } /** diff --git a/src/Plugin/PatternSourceBase.php b/src/Plugin/PatternSourceBase.php index 114aa603..560f69a3 100644 --- a/src/Plugin/PatternSourceBase.php +++ b/src/Plugin/PatternSourceBase.php @@ -6,13 +6,13 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\ui_patterns\Definition\PatternSourceField; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginInspectionInterface; /** * Base class for UI Patterns Source plugins. */ -abstract class PatternSourceBase extends PluginBase implements PatternSourceInterface, PluginInspectionInterface, ConfigurablePluginInterface { +abstract class PatternSourceBase extends PluginBase implements PatternSourceInterface, PluginInspectionInterface, ConfigurableInterface { use StringTranslationTrait; @@ -55,14 +55,8 @@ public function getContextProperty($name) { return $configuration['context'][$name]; } $reflection = new \ReflectionClass($this); - throw new PluginException($this->t("Context property '@property' from @class is missing or empty.", ['@property' => $name, '@class' => $reflection->name])); - } - - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - return []; + $message = sprintf("Context property '%s' from %s is missing or empty.", $name, $reflection->name); + throw new PluginException($message); } } diff --git a/src/Plugin/UiPatterns/Source/FieldSource.php b/src/Plugin/UiPatterns/Source/FieldSource.php index 06ce4473..7ff73013 100644 --- a/src/Plugin/UiPatterns/Source/FieldSource.php +++ b/src/Plugin/UiPatterns/Source/FieldSource.php @@ -2,7 +2,7 @@ namespace Drupal\ui_patterns\Plugin\UiPatterns\Source; -use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\EntityFieldManager; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\ui_patterns\Plugin\PatternSourceBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,16 +24,16 @@ class FieldSource extends PatternSourceBase implements ContainerFactoryPluginInt /** * Entity manager service. * - * @var \Drupal\Core\Entity\EntityManager + * @var \Drupal\Core\Entity\EntityFieldManager */ - protected $entityManager; + protected $entityFieldManager; /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManager $entity_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManager $entity_field_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityManager = $entity_manager; + $this->entityFieldManager = $entity_field_manager; } /** @@ -44,7 +44,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager') + $container->get('entity_field.manager') ); } @@ -53,7 +53,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function getSourceFields() { $sources = []; - $fields = $this->entityManager->getFieldDefinitions($this->getContextProperty('entity_type'), $this->getContextProperty('entity_bundle')); + $fields = $this->entityFieldManager->getFieldDefinitions($this->getContextProperty('entity_type'), $this->getContextProperty('entity_bundle')); /** @var \Drupal\Core\Field\FieldDefinitionInterface $field */ foreach ($fields as $field) { diff --git a/tests/modules/ui_patterns_field_source_test/ui_patterns_field_source_test.info.yml b/tests/modules/ui_patterns_field_source_test/ui_patterns_field_source_test.info.yml index c3f61f75..7f770e42 100644 --- a/tests/modules/ui_patterns_field_source_test/ui_patterns_field_source_test.info.yml +++ b/tests/modules/ui_patterns_field_source_test/ui_patterns_field_source_test.info.yml @@ -1,3 +1,4 @@ name: 'UI Patterns field source test' type: module core: 8.x +core_version_requirement: ^8 || ^9 diff --git a/tests/modules/ui_patterns_render_test/ui_patterns_render_test.info.yml b/tests/modules/ui_patterns_render_test/ui_patterns_render_test.info.yml index 9519a677..df40108b 100644 --- a/tests/modules/ui_patterns_render_test/ui_patterns_render_test.info.yml +++ b/tests/modules/ui_patterns_render_test/ui_patterns_render_test.info.yml @@ -1,3 +1,4 @@ name: 'UI Patterns Render Test' type: module core: 8.x +core_version_requirement: ^8 || ^9 diff --git a/tests/src/Functional/UiPatternsPreviewRenderTest.php b/tests/src/Functional/UiPatternsPreviewRenderTest.php index 9d93928f..380d1f0a 100644 --- a/tests/src/Functional/UiPatternsPreviewRenderTest.php +++ b/tests/src/Functional/UiPatternsPreviewRenderTest.php @@ -12,6 +12,13 @@ */ class UiPatternsPreviewRenderTest extends BrowserTestBase { + /** + * Default theme. See https://www.drupal.org/node/3083055. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Disable schema validation when running tests. * diff --git a/tests/src/Kernel/Plugin/Deriver/YamlDeriverTest.php b/tests/src/Kernel/Plugin/Deriver/YamlDeriverTest.php index 18061ac6..a7bb4053 100644 --- a/tests/src/Kernel/Plugin/Deriver/YamlDeriverTest.php +++ b/tests/src/Kernel/Plugin/Deriver/YamlDeriverTest.php @@ -6,7 +6,7 @@ use Drupal\ui_patterns\UiPatterns; /** - * @coversDefaultClass \Drupal\ui_patterns\Plugin\Deriver\YamlDeriver + * @coversDefaultClass \Drupal\ui_patterns\Plugin\Deriver\AbstractYamlPatternsDeriver * * @group ui_patterns */ @@ -16,17 +16,34 @@ class YamlDeriverTest extends AbstractUiPatternsTest { * {@inheritdoc} */ public static $modules = [ + 'system', 'ui_patterns', + 'ui_patterns_library', ]; + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + // Theme with existing patterns has to be enabled. + $default_theme = 'ui_patterns_library_theme_test'; + $this->container->get('theme_installer')->install([$default_theme]); + $this->container->get('config.factory')->getEditable('system.theme')->set('default', $default_theme)->save(); + } + /** * Test get derivative definitions. * * @covers ::getDerivativeDefinitions */ public function testGetDerivativeDefinitions() { + UiPatterns::getManager()->clearCachedDefinitions(); foreach (UiPatterns::getManager()->getDefinitions() as $definition) { - $this->assertArrayHasKey(['id', 'provider', 'base path'], $definition); + $this->assertNotEmpty($definition->id(), 'Pattern definition id is empty'); + $this->assertNotEmpty($definition->getProvider(), 'Pattern definition provider is empty'); + $this->assertNotEmpty($definition->getBasePath(), 'Pattern definition base path is empty'); } } diff --git a/tests/src/Kernel/Plugin/PatternBaseTest.php b/tests/src/Kernel/Plugin/PatternBaseTest.php index 9134bf8d..5298b389 100644 --- a/tests/src/Kernel/Plugin/PatternBaseTest.php +++ b/tests/src/Kernel/Plugin/PatternBaseTest.php @@ -17,7 +17,7 @@ class PatternBaseTest extends AbstractUiPatternsTest { * * @dataProvider hookLibraryInfoBuildDataProvider * - * @covers ::hookLibraryInfoBuild + * @covers ::getLibraryDefinitions */ public function testHookLibraryInfoBuild($actual, $expected) { $pattern = $this->getUiPatternBaseMock($actual); @@ -46,7 +46,7 @@ public function hookLibraryInfoBuildDataProvider() { * @param array $methods * List of methods to mock. * - * @return \PHPUnit_Framework_MockObject_MockObject + * @return \PHPUnit\Framework\MockObject\MockObject * Mock object. */ protected function getUiPatternBaseMock(array $plugin_definition = [], array $methods = []) { diff --git a/tests/src/Kernel/UiPatternsManagerTest.php b/tests/src/Kernel/UiPatternsManagerTest.php index 506aa3b8..a7f3198f 100644 --- a/tests/src/Kernel/UiPatternsManagerTest.php +++ b/tests/src/Kernel/UiPatternsManagerTest.php @@ -15,13 +15,27 @@ class UiPatternsManagerTest extends AbstractUiPatternsTest { * {@inheritdoc} */ public static $modules = [ + 'system', 'ui_patterns', + 'ui_patterns_library', ]; + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + // Theme with existing patterns has to be enabled. + $default_theme = 'ui_patterns_library_theme_test'; + $this->container->get('theme_installer')->install([$default_theme]); + $this->container->get('config.factory')->getEditable('system.theme')->set('default', $default_theme)->save(); + } + /** * Test UiPatternsManager::getPatternDefinition. * - * @covers ::getPatternDefinition + * @covers ::getPatterns */ public function testGetPattern() { $manager = UiPatterns::getManager(); diff --git a/ui_patterns.info.yml b/ui_patterns.info.yml index 94f9c2ea..fdd0b2e2 100644 --- a/ui_patterns.info.yml +++ b/ui_patterns.info.yml @@ -2,6 +2,5 @@ name: UI Patterns type: module description: UI patterns core: 8.x +core_version_requirement: ^8 || ^9 package: User interface -dependencies: - - drupal:system (>=8.3.0)