diff --git a/composer.json b/composer.json index 84550d4e53e2dff8dceb8d60c3d22a074c8d18b0..ddc40517ef950b38cbec41bf37a8fbef443357a0 100644 --- a/composer.json +++ b/composer.json @@ -148,7 +148,7 @@ "drupal/mobile_device_detection": "3.2", "drupal/module_filter": "3.1", "drupal/pantheon_advanced_page_cache": "1.0", - "drupal/paragraphs": "1.11", + "drupal/paragraphs": "1.12", "drupal/pathauto": "1.6", "drupal/realname": "1.0.0-rc2", "drupal/rebuild_cache_access": "1.7", @@ -302,9 +302,6 @@ "2809699": "https://www.drupal.org/files/issues/2018-10-26/menu_block-label_configuration-2809699-82.patch", "2811337": "https://www.drupal.org/files/issues/menu_block-2_level_menu_block_not_limited_to_active_parent-2811337-58.patch" }, - "drupal/paragraphs": { - "3114512": "https://www.drupal.org/files/issues/2020-02-20/3114512-1.patch" - }, "drupal/smtp": { "2781157": "https://www.drupal.org/files/issues/2018-11-07/2781157-n10.patch" }, @@ -321,4 +318,4 @@ "php": "7.0.8" } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index e72247e4d85c73f88bd2d0d0ca6013759665b005..bf2b5d855784eae1678a27e66c8eb56ab75b01e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "49d5961f8a3140652419db70da74c6d9", + "content-hash": "fa10be72a1367107fd10a1c43ed9c20d", "packages": [ { "name": "alchemy/zippy", @@ -6463,20 +6463,20 @@ }, { "name": "drupal/paragraphs", - "version": "1.11.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/paragraphs.git", - "reference": "8.x-1.11" + "reference": "8.x-1.12" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/paragraphs-8.x-1.11.zip", - "reference": "8.x-1.11", - "shasum": "4fa849a249fbc689ca0c83523a967c08767e91af" + "url": "https://ftp.drupal.org/files/projects/paragraphs-8.x-1.12.zip", + "reference": "8.x-1.12", + "shasum": "3b67d8af1160af42d93a4610be1e02869e428965" }, "require": { - "drupal/core": "^8.7.7 || ^9", + "drupal/core": "^8.8 || ^9", "drupal/entity_reference_revisions": "~1.3" }, "require-dev": { @@ -6497,24 +6497,18 @@ }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.11", - "datestamp": "1581850829", + "version": "8.x-1.12", + "datestamp": "1590140081", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" } - }, - "patches_applied": { - "3114512": "https://www.drupal.org/files/issues/2020-02-20/3114512-1.patch" } }, "notification-url": "https://packages.drupal.org/8/downloads", "license": [ - "GPL-2.0" + "GPL-2.0-or-later" ], "authors": [ { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index e114ec1040e17f95aa8e2efd99c824e3f2666c5d..1254846cb3a00b8d88f543bff977e9d3b80743e8 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -6660,21 +6660,21 @@ }, { "name": "drupal/paragraphs", - "version": "1.11.0", - "version_normalized": "1.11.0.0", + "version": "1.12.0", + "version_normalized": "1.12.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/paragraphs.git", - "reference": "8.x-1.11" + "reference": "8.x-1.12" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/paragraphs-8.x-1.11.zip", - "reference": "8.x-1.11", - "shasum": "4fa849a249fbc689ca0c83523a967c08767e91af" + "url": "https://ftp.drupal.org/files/projects/paragraphs-8.x-1.12.zip", + "reference": "8.x-1.12", + "shasum": "3b67d8af1160af42d93a4610be1e02869e428965" }, "require": { - "drupal/core": "^8.7.7 || ^9", + "drupal/core": "^8.8 || ^9", "drupal/entity_reference_revisions": "~1.3" }, "require-dev": { @@ -6695,25 +6695,19 @@ }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.11", - "datestamp": "1581850829", + "version": "8.x-1.12", + "datestamp": "1590140081", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" } - }, - "patches_applied": { - "3114512": "https://www.drupal.org/files/issues/2020-02-20/3114512-1.patch" } }, "installation-source": "dist", "notification-url": "https://packages.drupal.org/8/downloads", "license": [ - "GPL-2.0" + "GPL-2.0-or-later" ], "authors": [ { diff --git a/web/modules/paragraphs/PATCHES.txt b/web/modules/paragraphs/PATCHES.txt deleted file mode 100644 index 3dda710f5382eb06ad1c6663a4c5f60ba904abbd..0000000000000000000000000000000000000000 --- a/web/modules/paragraphs/PATCHES.txt +++ /dev/null @@ -1,7 +0,0 @@ -This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches) -Patches applied to this directory: - -3114512 -Source: https://www.drupal.org/files/issues/2020-02-20/3114512-1.patch - - diff --git a/web/modules/paragraphs/README.txt b/web/modules/paragraphs/README.txt index f1c652a6b98bf47081892252dc54221fed98c1b2..c4e36a8079fc052d9bda1fa07e6bbdc5773c7b59 100644 --- a/web/modules/paragraphs/README.txt +++ b/web/modules/paragraphs/README.txt @@ -39,12 +39,6 @@ results in a very compact display that makes it easier to move them around. Starting with Drupal 8.8.0, the necessary library is part of Drupal core and this feature is always available. -In Drupal 8.7 and earlier, an additional library is necessary, which needs to be -put in the libraries folder. Download from -https://github.com/RubaXa/Sortable/releases, make sure that the folder name is -Sortable (with uppercase S) so that the path to the javascript file is -/libraries/Sortable/Sortable.min.js. - Use the version 1.10+ as it's tested and approved. Older versions may introduce bugs with nested drag & drop functionality. diff --git a/web/modules/paragraphs/composer.json b/web/modules/paragraphs/composer.json index 7d4960b265aef5c8f5ee67987238a7aef392f19d..c65f9072b65d912026e9a8afe6071ae53b66aba0 100644 --- a/web/modules/paragraphs/composer.json +++ b/web/modules/paragraphs/composer.json @@ -2,9 +2,8 @@ "name": "drupal/paragraphs", "description": "Enables the creation of Paragraphs entities.", "type": "drupal-module", - "license": "GPL-2.0", + "license": "GPL-2.0-or-later", "require": { - "drupal/core": "^8.7.7 || ^9", "drupal/entity_reference_revisions": "~1.3" }, "suggest": { diff --git a/web/modules/paragraphs/config/install/core.entity_view_mode.paragraph.preview.yml b/web/modules/paragraphs/config/install/core.entity_view_mode.paragraph.preview.yml index e32016f70949fc5a57b4ff97c43b30d71855316d..2f5516eca5a950b513692db3aec554c4ea247cf9 100644 --- a/web/modules/paragraphs/config/install/core.entity_view_mode.paragraph.preview.yml +++ b/web/modules/paragraphs/config/install/core.entity_view_mode.paragraph.preview.yml @@ -1,9 +1,9 @@ langcode: en -id: paragraph.preview -label: Preview status: true -cache: true -targetEntityType: paragraph dependencies: module: - - paragraphs \ No newline at end of file + - paragraphs +id: paragraph.preview +label: Preview +targetEntityType: paragraph +cache: true diff --git a/web/modules/paragraphs/config/schema/paragraphs_type.schema.yml b/web/modules/paragraphs/config/schema/paragraphs_type.schema.yml index 15fc2f1dab38d80ecfcc3d309c4ef5cd50c5eb4b..fbed06457a62ba0978b2f750acca805ab08afc99 100644 --- a/web/modules/paragraphs/config/schema/paragraphs_type.schema.yml +++ b/web/modules/paragraphs/config/schema/paragraphs_type.schema.yml @@ -20,6 +20,7 @@ paragraphs.paragraphs_type.*: behavior_plugins: type: sequence label: 'Plugins' + orderby: key sequence: type: paragraphs.behavior.settings.[%key] label: 'Behavior plugins' @@ -44,6 +45,7 @@ entity_reference_selection.default:paragraph: type: integer target_bundles_drag_drop: type: sequence + orderby: key sequence: type: mapping mapping: @@ -101,5 +103,6 @@ field.widget.settings.paragraphs: type: string features: type: sequence + orderby: key sequence: type: string diff --git a/web/modules/paragraphs/css/paragraphs.actions.css b/web/modules/paragraphs/css/paragraphs.actions.css index 62c3baf81ce9aaadd4a93e35f361874791f26626..28eb05385e06345086c86c7b53c7ec21669100f4 100644 --- a/web/modules/paragraphs/css/paragraphs.actions.css +++ b/web/modules/paragraphs/css/paragraphs.actions.css @@ -112,6 +112,7 @@ .form-wrapper .paragraphs-dropdown-action.button { margin-top: 0; + margin-bottom: 0; } @media (max-width: 768px) { diff --git a/web/modules/paragraphs/css/paragraphs.actions.scss b/web/modules/paragraphs/css/paragraphs.actions.scss index c5d1ce4771fce7408515c595c10739ef060fcb72..23313041c6652de464493591158702c93cdeadb4 100644 --- a/web/modules/paragraphs/css/paragraphs.actions.scss +++ b/web/modules/paragraphs/css/paragraphs.actions.scss @@ -105,9 +105,11 @@ outline: none; } - // Override seven button.css top margin. .form-wrapper & { + // Override Seven's button.css top margin. margin-top: 0; + // Override Claro's bottom margin. + margin-bottom: 0; @media (max-width: map-get($grid-breakpoints, 'md')) { // Bigger touch area for small screens. diff --git a/web/modules/paragraphs/js/paragraphs.admin.js b/web/modules/paragraphs/js/paragraphs.admin.js index 9b1ae6663a3ec9304a4857e3ad00318b60d0cabc..f0696cb9529e51e87a547656ed5afe07fc8cce42 100644 --- a/web/modules/paragraphs/js/paragraphs.admin.js +++ b/web/modules/paragraphs/js/paragraphs.admin.js @@ -51,19 +51,20 @@ * Paragraphs widget. */ var switchActiveClass = function ($parTabs, $clickedTab, $parWidget) { - $parTabs.find('li').removeClass('is-active'); - $clickedTab.parent('li').addClass('is-active'); - $parWidget.removeClass('behavior-active content-active'); - $($parWidget).find($clickedTab.attr('href')).addClass('is-active'); + var $clickedTabParent = $clickedTab.parent(); - if ($parWidget.find('#content').hasClass('is-active')) { - $parWidget.addClass('content-active'); - $parWidget.find('.paragraphs-add-wrapper').parent().removeClass('hidden'); - } - else if ($parWidget.find('#behavior').hasClass('is-active')) { - $parWidget.addClass('behavior-active'); - $parWidget.find('.paragraphs-add-wrapper').parent().addClass('hidden'); - } + $parTabs.find('li').removeClass('is-active'); + $clickedTabParent.addClass('is-active'); + + $parWidget.removeClass('behavior-active content-active'); + if ($clickedTabParent.attr('id') === 'content') { + $parWidget.addClass('content-active'); + $parWidget.find('.paragraphs-add-wrapper').parent().removeClass('hidden'); + } + else { + $parWidget.addClass('behavior-active'); + $parWidget.find('.paragraphs-add-wrapper').parent().addClass('hidden'); + } }; /** diff --git a/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml b/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml index 9cf3de61f18eb3366d0f713a5c69a4dd282cd840..a415b8a8bbcf7a7d6e2070b88a8157f6662b5dfb 100644 --- a/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml +++ b/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml @@ -69,6 +69,7 @@ content: weight: 5 settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' third_party_settings: { } diff --git a/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.paragraph.user.default.yml b/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.paragraph.user.default.yml index a7515b6297bd776511799c55fe01aeb6b0c7d19d..61298d241955d8ce96ad99fbd11e5a2c8e869631 100644 --- a/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.paragraph.user.default.yml +++ b/web/modules/paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.paragraph.user.default.yml @@ -13,6 +13,7 @@ content: weight: 0 settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' third_party_settings: { } diff --git a/web/modules/paragraphs/modules/paragraphs_demo/paragraphs_demo.info.yml b/web/modules/paragraphs/modules/paragraphs_demo/paragraphs_demo.info.yml index 6fc26853857e157b37a540d82652a0b09003efcd..0a67b970e1a2297b1c559e1adde10f018997dfdb 100644 --- a/web/modules/paragraphs/modules/paragraphs_demo/paragraphs_demo.info.yml +++ b/web/modules/paragraphs/modules/paragraphs_demo/paragraphs_demo.info.yml @@ -21,7 +21,7 @@ name: Paragraphs Demo package: Paragraphs type: module -# Information added by Drupal.org packaging script on 2020-02-16 -version: '8.x-1.11' +# Information added by Drupal.org packaging script on 2020-05-21 +version: '8.x-1.12' project: 'paragraphs' -datestamp: 1581850832 +datestamp: 1590061337 diff --git a/web/modules/paragraphs/modules/paragraphs_demo/tests/src/Functional/ParagraphsDemoTest.php b/web/modules/paragraphs/modules/paragraphs_demo/tests/src/Functional/ParagraphsDemoTest.php index a4cb73466618f46069d6d6e9b8a55c82132d117f..56ab0fb79351c0e214b2de5f1f045211dbf50f44 100644 --- a/web/modules/paragraphs/modules/paragraphs_demo/tests/src/Functional/ParagraphsDemoTest.php +++ b/web/modules/paragraphs/modules/paragraphs_demo/tests/src/Functional/ParagraphsDemoTest.php @@ -46,10 +46,10 @@ public function testConfigurationsAndCreation() { // Assert that the demo page is displayed to anymous users. $this->drupalGet(''); - $this->assertText('Paragraphs is the new way of content creation!'); - $this->assertText('Apart from the included Paragraph types'); - $this->assertText('A search api example can be found'); - $this->assertText('This is content from the library. We can reuse it multiple times without duplicating it.'); + $this->assertSession()->pageTextContains('Paragraphs is the new way of content creation!'); + $this->assertSession()->pageTextContains('Apart from the included Paragraph types'); + $this->assertSession()->pageTextContains('A search api example can be found'); + $this->assertSession()->pageTextContains('This is content from the library. We can reuse it multiple times without duplicating it.'); $admin_user = $this->drupalCreateUser(array( 'administer site configuration', @@ -87,66 +87,66 @@ public function testConfigurationsAndCreation() { // Check for all pre-configured paragraphs_types. $this->drupalGet('admin/structure/paragraphs_type'); - $this->assertText('Image + Text'); - $this->assertText('Images'); - $this->assertText('Text'); - $this->assertText('Text + Image'); - $this->assertText('User'); + $this->assertSession()->pageTextContains('Image + Text'); + $this->assertSession()->pageTextContains('Images'); + $this->assertSession()->pageTextContains('Text'); + $this->assertSession()->pageTextContains('Text + Image'); + $this->assertSession()->pageTextContains('User'); // Check for preconfigured languages. $this->drupalGet('admin/config/regional/language'); - $this->assertText('English'); - $this->assertText('German'); - $this->assertText('French'); + $this->assertSession()->pageTextContains('English'); + $this->assertSession()->pageTextContains('German'); + $this->assertSession()->pageTextContains('French'); // Check for Content language translation checks. $this->drupalGet('admin/config/regional/content-language'); - $this->assertFieldChecked('edit-entity-types-node'); - $this->assertFieldChecked('edit-entity-types-paragraph'); - $this->assertFieldChecked('edit-settings-node-paragraphed-content-demo-translatable'); - $this->assertNoFieldChecked('edit-settings-node-paragraphed-content-demo-fields-field-paragraphs-demo'); - $this->assertFieldChecked('edit-settings-paragraph-images-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-image-text-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-text-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-text-image-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-user-translatable'); + $this->assertSession()->checkboxChecked('edit-entity-types-node'); + $this->assertSession()->checkboxChecked('edit-entity-types-paragraph'); + $this->assertSession()->checkboxChecked('edit-settings-node-paragraphed-content-demo-translatable'); + $this->assertSession()->checkboxNotChecked('edit-settings-node-paragraphed-content-demo-fields-field-paragraphs-demo'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-images-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-image-text-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-text-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-text-image-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-user-translatable'); // Check for paragraph type Image + text that has the correct fields set. $this->drupalGet('admin/structure/paragraphs_type/image_text/fields'); - $this->assertText('Text'); - $this->assertText('Image'); + $this->assertSession()->pageTextContains('Text'); + $this->assertSession()->pageTextContains('Image'); // Check for paragraph type Text that has the correct fields set. $this->drupalGet('admin/structure/paragraphs_type/text/fields'); - $this->assertText('Text'); - $this->assertNoText('Image'); + $this->assertSession()->pageTextContains('Text'); + $this->assertSession()->pageTextNotContains('Image'); // Make sure we have the paragraphed article listed as a content type. $this->drupalGet('admin/structure/types'); - $this->assertText('Paragraphed article'); + $this->assertSession()->pageTextContains('Paragraphed article'); // Check that title and the descriptions are set. $this->drupalGet('admin/structure/types/manage/paragraphed_content_demo'); - $this->assertText('Paragraphed article'); - $this->assertText('Article with Paragraphs.'); + $this->assertSession()->pageTextContains('Paragraphed article'); + $this->assertSession()->pageTextContains('Article with Paragraphs.'); // Check that the Paragraph field is added. $this->clickLink('Manage fields'); - $this->assertText('Paragraphs'); + $this->assertSession()->pageTextContains('Paragraphs'); // Check that all paragraphs types are enabled (disabled). $this->clickLink('Edit', 0); - $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-image-text-enabled'); - $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-images-enabled'); - $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-image-enabled'); - $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-user-enabled'); - $this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-enabled'); + $this->assertSession()->checkboxNotChecked('edit-settings-handler-settings-target-bundles-drag-drop-image-text-enabled'); + $this->assertSession()->checkboxNotChecked('edit-settings-handler-settings-target-bundles-drag-drop-images-enabled'); + $this->assertSession()->checkboxNotChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-image-enabled'); + $this->assertSession()->checkboxNotChecked('edit-settings-handler-settings-target-bundles-drag-drop-user-enabled'); + $this->assertSession()->checkboxNotChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-enabled'); $this->drupalGet('node/add/paragraphed_content_demo'); - $this->assertRaw('<h4 class="label">Paragraphs</h4>', 'Field name is present on the page.'); + $this->assertSession()->responseContains('<h4 class="label">Paragraphs</h4>'); $this->drupalPostForm(NULL, NULL, t('Add Text')); - $this->assertNoRaw('<strong data-drupal-selector="edit-field-paragraphs-demo-title">Paragraphs</strong>', 'Field name for empty field is not present on the page.'); - $this->assertRaw('<h4 class="label">Paragraphs</h4>', 'Field name appears in the table header.'); + $this->assertSession()->responseNotContains('<strong data-drupal-selector="edit-field-paragraphs-demo-title">Paragraphs</strong>'); + $this->assertSession()->responseContains('<h4 class="label">Paragraphs</h4>'); $edit = array( 'title[0][value]' => 'Paragraph title', 'moderation_state[0][state]' => 'published', @@ -158,36 +158,36 @@ public function testConfigurationsAndCreation() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Paragraphed article Paragraph title has been created.'); - $this->assertText('Paragraph title'); - $this->assertText('Paragraph text'); + $this->assertSession()->pageTextContains('Paragraphed article Paragraph title has been created.'); + $this->assertSession()->pageTextContains('Paragraph title'); + $this->assertSession()->pageTextContains('Paragraph text'); // Search a nested Paragraph text. $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'A search api example']]); - $this->assertRaw('Welcome to the Paragraphs Demo module!'); + $this->assertSession()->pageTextContains('Welcome to the Paragraphs Demo module!'); // Search a node paragraph field text. $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'It allows you']]); - $this->assertRaw('Welcome to the Paragraphs Demo module!'); + $this->assertSession()->pageTextContains('Welcome to the Paragraphs Demo module!'); // Search non existent text. $this->drupalGet('paragraphs_search', ['query' => ['search_api_fulltext' => 'foo']]); - $this->assertNoRaw('Welcome to the Paragraphs Demo module!'); + $this->assertSession()->responseNotContains('Welcome to the Paragraphs Demo module!'); // Check that the dropbutton of Nested Paragraph has the Duplicate function. // For now, this indicates that it is using the EXPERIMENTAL widget. $this->drupalGet('node/1/edit'); - $this->assertFieldByName('field_paragraphs_demo_3_subform_field_paragraphs_demo_0_duplicate'); + $this->assertSession()->buttonExists('field_paragraphs_demo_3_subform_field_paragraphs_demo_0_duplicate'); // Check the library paragraph. $this->drupalGet('admin/content/paragraphs'); - $this->assertText('Library item'); - $this->assertText('This is content from the library.'); + $this->assertSession()->pageTextContains('Library item'); + $this->assertSession()->pageTextContains('This is content from the library.'); // Assert anonymous users cannot update library items. $this->drupalLogout(); $this->drupalGet('admin/content/paragraphs/1/edit'); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet('admin/content/paragraphs/1/delete'); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); } } diff --git a/web/modules/paragraphs/modules/paragraphs_library/config/install/core.entity_form_display.paragraph.from_library.default.yml b/web/modules/paragraphs/modules/paragraphs_library/config/install/core.entity_form_display.paragraph.from_library.default.yml index 8349f201b0ed757922a4b2cd5346de91e99d6320..6f5163d144333482029309e0b894111830796025 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/config/install/core.entity_form_display.paragraph.from_library.default.yml +++ b/web/modules/paragraphs/modules/paragraphs_library/config/install/core.entity_form_display.paragraph.from_library.default.yml @@ -13,6 +13,7 @@ content: weight: 0 settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' third_party_settings: { } diff --git a/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.info.yml b/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.info.yml index 6186fe0e98e59ce7d673d87cc788eb38c3915397..f2372be3de8942c4aa38dd8fcc26ee32a510d693 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.info.yml +++ b/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.info.yml @@ -11,7 +11,7 @@ dependencies: test_dependencies: - entity_browser:entity_browser -# Information added by Drupal.org packaging script on 2020-02-16 -version: '8.x-1.11' +# Information added by Drupal.org packaging script on 2020-05-21 +version: '8.x-1.12' project: 'paragraphs' -datestamp: 1581850832 +datestamp: 1590061337 diff --git a/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.module b/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.module index 8c55ac14a6430c327a42cf6f185fca2346da4874..d2e4829de70d4ff3824b1d534654d110e1f41050 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.module +++ b/web/modules/paragraphs/modules/paragraphs_library/paragraphs_library.module @@ -73,6 +73,9 @@ function paragraphs_library_paragraphs_widget_actions_alter(&$widget_actions, &$ 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade', ], + '#attributes' => [ + 'class' => ['button--small'], + ], ]; } elseif ($allow_library_conversion) { @@ -89,6 +92,9 @@ function paragraphs_library_paragraphs_widget_actions_alter(&$widget_actions, &$ 'wrapper' => $widget_state['ajax_wrapper_id'], ], '#access' => \Drupal::entityTypeManager()->getAccessControlHandler('paragraphs_library_item')->createAccess(), + '#attributes' => [ + 'class' => ['button--small'], + ], ]; } } @@ -136,10 +142,13 @@ function paragraphs_library_preprocess_paragraph(&$variables) { if ($library_item->access('view')) { $view_builder = \Drupal::entityTypeManager() ->getViewBuilder('paragraphs_library_item'); - $library_item_render_array = $view_builder->view($library_item); + $library_item_render_array = $view_builder->view($library_item, $variables['elements']['field_reusable_paragraph'][0]['#view_mode']); // This will remove all fields other then field_reusable_paragraph. - $variables['content'] = $view_builder->build($library_item_render_array)['paragraphs']; + $build = $view_builder->build($library_item_render_array); + if (!empty($build['paragraphs'])) { + $variables['content'] = $build['paragraphs']; + } } } } @@ -168,7 +177,7 @@ function paragraphs_library_views_pre_render(ViewExecutable $view) { */ function _paragraphs_library_count_usage(array $usage_data) { $count = 0; - foreach ($usage_data as $entity_type => $entities) { + foreach ($usage_data as $entities) { // We only want to register usages by different entities, ignoring usages // accross revisions / translations / fields of the same entity. $count += count($entities); diff --git a/web/modules/paragraphs/modules/paragraphs_library/src/Controller/LibraryItemController.php b/web/modules/paragraphs/modules/paragraphs_library/src/Controller/LibraryItemController.php index 302f06063f9a6bfd691a32a9c822f02bd2d47ea0..138afb4810e1c2c341d3a59d4cd14c2a4b88f513 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/src/Controller/LibraryItemController.php +++ b/web/modules/paragraphs/modules/paragraphs_library/src/Controller/LibraryItemController.php @@ -7,6 +7,7 @@ use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Render\Renderer; use Drupal\paragraphs_library\Entity\LibraryItem; use Drupal\paragraphs_library\LibraryItemInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -27,6 +28,13 @@ class LibraryItemController extends ControllerBase implements ContainerInjection */ protected $entityTypeManager; + /** + * The renderer service. + * + * @var \Drupal\Core\Render\Renderer + */ + protected $renderer; + /** * LibraryItemController constructor. * @@ -34,10 +42,13 @@ class LibraryItemController extends ControllerBase implements ContainerInjection * The date formatter service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. + * @param \Drupal\Core\Render\Renderer $renderer + * The renderer service. */ - public function __construct(DateFormatterInterface $date_formatter, EntityTypeManagerInterface $entity_type_manager) { + public function __construct(DateFormatterInterface $date_formatter, EntityTypeManagerInterface $entity_type_manager, Renderer $renderer) { $this->dateFormatter = $date_formatter; $this->entityTypeManager = $entity_type_manager; + $this->renderer = $renderer; } /** @@ -46,8 +57,9 @@ public function __construct(DateFormatterInterface $date_formatter, EntityTypeMa public static function create(ContainerInterface $container) { return new static( $container->get('date.formatter'), - $container->get('entity_type.manager') - ); + $container->get('entity_type.manager'), + $container->get('renderer') + ); } /** @@ -83,7 +95,7 @@ public function revisionOverview(LibraryItem $paragraphs_library_item) { '#context' => [ 'date' => $revision->toLink($date, $revision->isDefaultRevision() ? 'canonical' : 'revision')->toString(), 'label' => $revision->label(), - 'author' => \Drupal::service('renderer')->renderPlain($username), + 'author' => $this->renderer->renderPlain($username), 'message' => ['#markup' => $revision->get('revision_log')->value, '#allowed_tags' => Xss::getHtmlTagList()], ], ], diff --git a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php index 8e87363eadd980e9c437e1731abd28e54f9f49e4..94f7c1291bfabe6a644cf994def3110ea5ce858c 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php +++ b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php @@ -86,7 +86,7 @@ public function testReuseTranslationForNestedParagraphFromLibrary() { 'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'En label Example text for test in nested paragraph.', ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertText('Paragraph En label Test nested paragraph has been created.'); + $this->assertSession()->pageTextContains('Paragraph En label Test nested paragraph has been created.'); // Translate nested paragraphs library item. $this->clickLink('Translate'); @@ -114,10 +114,10 @@ public function testReuseTranslationForNestedParagraphFromLibrary() { $this->drupalPostForm('de/node/' . $node->id() . '/translations/add/en/de', $edit, 'Save (this translation)'); $this->drupalGet('node/' . $node->id()); - $this->assertText('En label Example text for test in nested paragraph.'); + $this->assertSession()->pageTextContains('En label Example text for test in nested paragraph.'); $this->drupalGet('de/node/' . $node->id()); - $this->assertText('De label Beispieltext fur den Test in geschachteltem Absatz.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.'); // Update translation of library item. $edit = [ @@ -127,7 +127,7 @@ public function testReuseTranslationForNestedParagraphFromLibrary() { // Check updated content. $this->drupalGet('de/node/' . $node->id()); - $this->assertText('De label Beispieltext fur den Test geander.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test geander.'); } /** @@ -163,14 +163,14 @@ public function testMoveTranslatedNestedParagraphToLibrary() { // Check translation. $this->drupalGet($node->toUrl()); - $this->assertText('En label Example text for test in nested paragraph'); + $this->assertSession()->pageTextContains('En label Example text for test in nested paragraph'); $this->drupalGet('de/node/' . $node->id()); - $this->assertText('De label Beispieltext fur den Test in geschachteltem Absatz.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.'); // Check library item after converting translated paragraph. $this->drupalGet('de/admin/content/paragraphs/1'); - $this->assertText('De label Beispieltext fur den Test in geschachteltem Absatz.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.'); } /** @@ -188,7 +188,7 @@ public function testDetachTranslatedNestedParagraphItemFromLibrary() { 'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'En label Example text for test.' ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertText('Paragraph En label Test nested paragraph has been created.'); + $this->assertSession()->pageTextContains('Paragraph En label Test nested paragraph has been created.'); // Translate nested paragraphs library item. $this->clickLink('Translate'); @@ -215,18 +215,18 @@ public function testDetachTranslatedNestedParagraphItemFromLibrary() { ]; $this->drupalPostForm('de/node/' . $node->id() . '/translations/add/en/de', $edit, 'Save (this translation)'); - $this->assertText('De label Beispieltext fur den Test in geschachteltem Absatz.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.'); // The detach action is not visible while translating. $this->clickLink('Edit'); - $this->assertNoText('Unlink from library'); + $this->assertSession()->pageTextNotContains('Unlink from library'); // Detach from library an check content. $this->drupalGet('node/' . $node->id()); - $this->assertText('En label Example text for test.'); + $this->assertSession()->pageTextContains('En label Example text for test.'); $this->clickLink('Edit'); $this->drupalPostForm(NULL, NULL, 'field_paragraphs_0_unlink_from_library'); - $this->assertText('En label Example text for test.'); + $this->assertSession()->pageTextContains('En label Example text for test.'); } /** @@ -244,7 +244,7 @@ public function testDetachBeforeTranslation() { 'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'En label Example text for test.' ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertText('Paragraph En label Test nested paragraph has been created.'); + $this->assertSession()->pageTextContains('Paragraph En label Test nested paragraph has been created.'); // Translate nested paragraphs library item. $this->clickLink('Translate'); @@ -272,10 +272,10 @@ public function testDetachBeforeTranslation() { $node = $this->drupalGetNodeByTitle('En label Test node nested'); $this->drupalPostForm('de/node/' . $node->id() . '/translations/add/en/de', NULL, 'Save (this translation)'); - $this->assertText('De label Beispieltext fur den Test in geschachteltem Absatz.'); + $this->assertSession()->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.'); $this->drupalGet('node/' . $node->id()); - $this->assertText('En label Example text for test.'); + $this->assertSession()->pageTextContains('En label Example text for test.'); } /** diff --git a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTest.php b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTest.php index 1e91637d12c5dcecde72a36a5e276d6efaa15a2d..0f13b888e04abb7494002c84ba66969995891b81 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTest.php +++ b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTest.php @@ -197,8 +197,8 @@ public function testNoConversionSideEffects() { ->find('xpath', '(//tbody//tr)[2]//a') ->click(); $revision_url = $this->getSession()->getCurrentUrl(); - $this->assertContains('/node/' . $node->id() . '/revisions/', $revision_url); - $this->assertContains('view', $revision_url); + $this->assertStringContainsString('/node/' . $node->id() . '/revisions/', $revision_url); + $this->assertStringContainsString('view', $revision_url); // Check that the child text paragraph is still present in this revision. $this->assertSession()->pageTextContains('Test text 1'); diff --git a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryTest.php b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryTest.php index 5986cf5623bd2b61589af2aa8d871ecca659c96f..d8970da2709dd684637b051dc4d5bbc7f0c0f098 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryTest.php +++ b/web/modules/paragraphs/modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryTest.php @@ -54,35 +54,35 @@ public function testLibraryItems() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->clickLink('re usable paragraph label'); - $this->assertRaw('bartik/css/base/elements.css', t("The default frontend theme's CSS appears on the page for viewing a library item.")); + $this->assertSession()->responseContains('bartik/css/base/elements.css'); $this->clickLink('Edit'); - $this->assertNoRaw('class="messages messages--warning"', 'No warning message is displayed.'); + $this->assertSession()->responseNotContains('class="messages messages--warning"'); $items = \Drupal::entityQuery('paragraphs_library_item')->sort('id', 'DESC')->range(0, 1)->execute(); $library_item_id = reset($items); // Assert local tasks and URLs. - $this->assertLink('Edit'); - $this->assertText('Delete'); + $this->assertSession()->linkExists('Edit'); + $this->assertSession()->pageTextContains('Delete'); $this->clickLink('View'); - $this->assertUrl(Url::fromRoute('entity.paragraphs_library_item.canonical', ['paragraphs_library_item' => $library_item_id])); + $this->assertSession()->addressEquals(Url::fromRoute('entity.paragraphs_library_item.canonical', ['paragraphs_library_item' => $library_item_id])); $this->drupalGet('admin/content/paragraphs/' . $library_item_id . '/delete'); - $this->assertUrl(Url::fromRoute('entity.paragraphs_library_item.delete_form', ['paragraphs_library_item' => $library_item_id])); + $this->assertSession()->addressEquals(Url::fromRoute('entity.paragraphs_library_item.delete_form', ['paragraphs_library_item' => $library_item_id])); $this->clickLink('Edit'); - $this->assertUrl(Url::fromRoute('entity.paragraphs_library_item.edit_form', ['paragraphs_library_item' => $library_item_id])); + $this->assertSession()->addressEquals(Url::fromRoute('entity.paragraphs_library_item.edit_form', ['paragraphs_library_item' => $library_item_id])); // Check that the data is correctly stored. $this->drupalGet('admin/content/paragraphs'); - $this->assertText('Used', 'Usage column is available.'); - $this->assertText('Changed', 'Changed column is available.'); + $this->assertSession()->pageTextContains('Used'); + $this->assertSession()->pageTextContains('Changed'); $result = $this->cssSelect('.views-field-count'); - $this->assertEqual(trim($result[1]->getText()), '0', 'Usage info is correctly displayed.'); - $this->assertText('Delete'); + $this->assertEquals(trim($result[1]->getText()), '0', 'Usage info is correctly displayed.'); + $this->assertSession()->pageTextContains('Delete'); // Check the changed field. $result = $this->cssSelect('.views-field-changed'); $this->assertNotNull(trim($result[1]->getText())); $this->clickLink('Edit'); - $this->assertFieldByName('label[0][value]', 're usable paragraph label'); - $this->assertFieldByName('paragraphs[0][subform][field_text][0][value]', 're_usable_text'); + $this->assertSession()->fieldExists('label[0][value]'); + $this->assertSession()->fieldExists('paragraphs[0][subform][field_text][0][value]'); // Create a node with the library paragraph. $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_from_library_add_more'); @@ -94,18 +94,89 @@ public function testLibraryItems() { $library_items = \Drupal::entityTypeManager()->getStorage('paragraphs_library_item')->loadByProperties(['label' => 're usable paragraph label']); $this->drupalGet('admin/content/paragraphs/' . current($library_items)->id() . '/edit'); - $this->assertText('Modifications on this form will affect all existing usages of this entity.'); - $this->assertText('Delete'); + $this->assertSession()->pageTextContains('Modifications on this form will affect all existing usages of this entity.'); + $this->assertSession()->pageTextContains('Delete'); $this->drupalGet('admin/content/paragraphs'); $result = $this->cssSelect('.views-field-count'); - $this->assertEqual(trim($result[1]->getText()), '1', 'Usage info is correctly displayed.'); + $this->assertEquals(trim($result[1]->getText()), '1', 'Usage info is correctly displayed.'); // Assert that the paragraph is shown correctly. $node_one = $this->getNodeByTitle('library_test'); + $this->drupalGet('node/' . $node_one->id()); + $this->assertSession()->pageTextContains('re_usable_text'); + + // Assert that the correct view mode is used. + $notext_view_mode = \Drupal::entityTypeManager()->getStorage('entity_view_mode')->create([ + 'id' => "paragraph.notext", + 'label' => 'No label view mode', + 'targetEntityType' => 'paragraph', + 'cache' => FALSE, + ]); + $notext_view_mode->enable(); + $notext_view_mode->save(); + + $display_storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); + $notest_display = $display_storage->create([ + 'status' => TRUE, + 'id' => "paragraph.$paragraph_type.notext", + 'targetEntityType' => 'paragraph', + 'bundle' => $paragraph_type, + 'mode' => 'notext', + 'content' => [], + ]); + $notest_display->save(); + + $alternative_view_mode = \Drupal::entityTypeManager()->getStorage('entity_view_mode')->create([ + 'id' => 'paragraphs_library_item.alternative', + 'label' => 'Alternative view mode', + 'targetEntityType' => 'paragraphs_library_item', + 'cache' => FALSE, + ]); + $alternative_view_mode->enable(); + $alternative_view_mode->save(); + + $display_storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); + $alternative_display = $display_storage->create([ + 'status' => TRUE, + 'id' => 'paragraphs_library_item.paragraphs_library_item.alternative', + 'targetEntityType' => 'paragraphs_library_item', + 'bundle' => 'paragraphs_library_item', + 'mode' => 'alternative', + 'content' => [ + 'paragraphs' => [ + 'label' => 'hidden', + 'type' => 'entity_reference_revisions_entity_view', + 'region' => 'content', + 'settings' => [ + 'view_mode' => 'notext', + ], + 'third_party_settings' => [], + 'weight' => 0, + ], + ], + ]); + $alternative_display->save(); + $this->drupalGet('node/' . $node_one->id()); $this->assertText('re_usable_text'); + /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $from_library_view_display */ + $from_library_view_display = $display_storage->load('paragraph.from_library.default'); + $field_reusable_paragraph_component = $from_library_view_display->getComponent('field_reusable_paragraph'); + $field_reusable_paragraph_component['settings']['view_mode'] = 'alternative'; + $from_library_view_display->setComponent('field_reusable_paragraph', $field_reusable_paragraph_component); + $from_library_view_display->save(); + + $this->drupalGet('node/' . $node_one->id()); + $this->assertNoText('re_usable_text'); + + $from_library_view_display = $display_storage->load('paragraph.from_library.default'); + $field_reusable_paragraph_component = $from_library_view_display->getComponent('field_reusable_paragraph'); + $field_reusable_paragraph_component['settings']['view_mode'] = 'default'; + $from_library_view_display->setComponent('field_reusable_paragraph', $field_reusable_paragraph_component); + $from_library_view_display->save(); + // Create a new node with the library paragraph. $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_from_library_add_more'); $edit = [ @@ -115,11 +186,11 @@ public function testLibraryItems() { $this->drupalPostForm(NULL, $edit, 'Save'); // Assert that the paragraph is shown correctly. $node_two = $this->getNodeByTitle('library_test_new'); - $this->assertUrl('node/' . $node_two->id()); - $this->assertText('re_usable_text'); - $this->assertNoText('Reusable paragraph', 'Label from the paragraph that references a library item is not displayed.'); - $this->assertNoText('re usable paragraph label', 'Label from library item is not visible.'); - $this->assertNoText('Paragraphs', 'Label from library item field paragraphs is hidden.'); + $this->assertSession()->addressEquals('node/' . $node_two->id()); + $this->assertSession()->pageTextContains('re_usable_text'); + $this->assertSession()->pageTextNotContains('Reusable paragraph'); + $this->assertSession()->pageTextNotContains('re usable paragraph label'); + $this->assertSession()->elementTextNotContains('css', '.paragraph--type--from-library', 'Paragraphs'); $this->drupalGet('node/' . $node_two->id() . '/edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_from_library_add_more'); @@ -131,21 +202,21 @@ public function testLibraryItems() { $this->drupalPostForm(NULL, $edit, 'Save'); $reusable_paragraphs_text = $this->xpath('//div[contains(@class, "field--name-field-paragraphs")]/div[@class="field__items"]/div[1]//div[@class="field__item"]/p'); - $this->assertEqual($reusable_paragraphs_text[0]->getText(), 're_usable_text'); + $this->assertEquals($reusable_paragraphs_text[0]->getText(), 're_usable_text'); $second_reusable_paragraphs_text = $this->xpath('//div[contains(@class, "field--name-field-paragraphs")]/div[@class="field__items"]/div[2]//div[@class="field__item"]/p'); - $this->assertEqual($second_reusable_paragraphs_text[0]->getText(), 're_usable_text'); + $this->assertEquals($second_reusable_paragraphs_text[0]->getText(), 're_usable_text'); // Edit the paragraph and change the text. $this->drupalGet('admin/content/paragraphs'); - $this->assertText('Used', 'Usage column is available.'); + $this->assertSession()->pageTextContains('Used'); $result = $this->cssSelect('.views-field-count'); - $this->assertEqual(trim($result[1]->getText()), '4', 'Usage info is correctly displayed.'); - $this->assertNoLink('4', 'Link to usage statistics is not available for user without permission.'); + $this->assertEquals(trim($result[1]->getText()), '4', 'Usage info is correctly displayed.'); + $this->assertSession()->linkNotExists('4'); $this->clickLink('Edit'); - $this->assertText('Modifications on this form will affect all existing usages of this entity.'); + $this->assertSession()->pageTextContains('Modifications on this form will affect all existing usages of this entity.'); $edit = [ 'paragraphs[0][subform][field_text][0][value]' => 're_usable_text_new', ]; @@ -155,9 +226,9 @@ public function testLibraryItems() { // that the cache is populated. $this->drupalLogout(); $this->drupalGet('node/' . $node_one->id()); - $this->assertText('re_usable_text_new'); + $this->assertSession()->pageTextContains('re_usable_text_new'); $this->drupalGet('node/' . $node_two->id()); - $this->assertText('re_usable_text_new'); + $this->assertSession()->pageTextContains('re_usable_text_new'); $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content', 'administer paragraphs library']); @@ -170,11 +241,11 @@ public function testLibraryItems() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/' . $node_one->id()); - $this->assertText('re_usable_text_new'); + $this->assertSession()->pageTextContains('re_usable_text_new'); $this->drupalLogout(); $this->drupalGet('node/' . $node_one->id()); - $this->assertNoText('re_usable_text_new'); + $this->assertSession()->pageTextNotContains('re_usable_text_new'); // Log in again, publish again, make sure it shows up again. $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content', 'administer paragraphs library']); @@ -185,21 +256,21 @@ public function testLibraryItems() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/' . $node_one->id()); - $this->assertText('re_usable_text_new'); + $this->assertSession()->pageTextContains('re_usable_text_new'); $this->drupalLogout(); $this->drupalGet('node/' . $node_one->id()); - $this->assertText('re_usable_text_new'); + $this->assertSession()->pageTextContains('re_usable_text_new'); $this->loginAsAdmin(['administer paragraphs library', 'access entity usage statistics']); $this->drupalGet('admin/content/paragraphs'); - $this->assertLink('4', 0, 'Link to usage statistics is available for user with permission.'); + $this->assertSession()->linkExists('4', 0, 'Link to usage statistics is available for user with permission.'); $element = $this->cssSelect('th.views-field-paragraphs__target-id'); - $this->assertEqual($element[0]->getText(), 'Paragraphs', 'Paragraphs column is available.'); + $this->assertEquals($element[0]->getText(), 'Paragraphs', 'Paragraphs column is available.'); $element = $this->cssSelect('.paragraphs-description .paragraphs-content-wrapper .summary-content'); - $this->assertEqual(trim($element[0]->getText()), 're_usable_text_new', 'Paragraphs summary available.'); + $this->assertEquals(trim($element[0]->getText()), 're_usable_text_new', 'Paragraphs summary available.'); // Check that the deletion of library items does not cause errors. current($library_items)->delete(); @@ -214,14 +285,14 @@ public function testLibraryItems() { 'access administration pages', ]); $this->drupalGet('admin/config/content/paragraphs_library_item'); - $this->assertLink('Manage fields'); - $this->assertLink('Manage form display'); - $this->assertLink('Manage display'); + $this->assertSession()->linkExists('Manage fields'); + $this->assertSession()->linkExists('Manage form display'); + $this->assertSession()->linkExists('Manage display'); // Assert that users can create fields to $this->clickLink('Manage fields'); $this->clickLink(t('Add field')); - $this->assertResponse(200); - $this->assertNoText('plugin does not exist'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextNotContains('plugin does not exist'); $this->drupalGet('admin/config/content'); $this->clickLink('Paragraphs library item settings'); } @@ -250,7 +321,7 @@ public function testConvertLibraryItemIntoParagraph() { 'paragraphs[0][subform][field_text][0][value]' => 'reusable_text', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Paragraph reusable paragraph label has been created.'); + $this->assertSession()->pageTextContains('Paragraph reusable paragraph label has been created.'); // Add created library item to a node. $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_from_library_add_more'); @@ -259,17 +330,17 @@ public function testConvertLibraryItemIntoParagraph() { 'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'reusable paragraph label', ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertText('paragraphed_test Node with converted library item has been created.'); - $this->assertText('reusable_text'); + $this->assertSession()->pageTextContains('paragraphed_test Node with converted library item has been created.'); + $this->assertSession()->pageTextContains('reusable_text'); // Convert library item to paragraph. $this->clickLink('Edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_unlink_from_library'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertNoFieldByName('field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]'); - $this->assertText('reusable_text'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->fieldNotExists('field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]'); + $this->assertSession()->pageTextContains('reusable_text'); $this->drupalPostForm(NULL, [], 'Save'); - $this->assertText('reusable_text'); + $this->assertSession()->pageTextContains('reusable_text'); } /** @@ -294,9 +365,9 @@ public function testConvertParagraphIntoLibrary() { // Adding library item is available with the administer library permission. $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, 'Add text'); - $this->assertField('field_paragraphs_0_promote_to_library'); + $this->assertSession()->buttonExists('field_paragraphs_0_promote_to_library'); $this->drupalGet('admin/content/paragraphs/add/default'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Adding library item is not available without appropriate permissions. $user_roles = $user->getRoles(TRUE); @@ -304,9 +375,9 @@ public function testConvertParagraphIntoLibrary() { user_role_revoke_permissions($user_role, ['administer paragraphs library']); $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, 'Add text'); - $this->assertNoField('field_paragraphs_0_promote_to_library'); + $this->assertSession()->buttonNotExists('field_paragraphs_0_promote_to_library'); $this->drupalGet('admin/content/paragraphs/add/default'); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); // Enabling a dummy behavior plugin for testing the item label creation. $edit = [ @@ -316,26 +387,26 @@ public function testConvertParagraphIntoLibrary() { // Assign "create paragraph library item" permission to a user. user_role_grant_permissions($user_role, ['create paragraph library item']); $this->drupalGet('admin/content/paragraphs/add/default'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, 'Add text'); - $this->assertField('field_paragraphs_0_promote_to_library'); - $this->assertRaw('Promote to library'); + $this->assertSession()->buttonExists('field_paragraphs_0_promote_to_library'); + $this->assertSession()->responseContains('Promote to library'); $edit = [ 'field_paragraphs[0][subform][field_text][0][value]' => 'Random text for testing converting into library.', ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_promote_to_library'); - $this->assertText('From library'); - $this->assertText('Reusable paragraph'); - $this->assertFieldByName('field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]', 'text: Random text for testing converting into library. (1)'); + $this->assertSession()->pageTextContains('From library'); + $this->assertSession()->pageTextContains('Reusable paragraph'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]'); $edit = [ 'title[0][value]' => 'TextParagraphs', ]; - $this->assertNoField('field_paragraphs_0_promote_to_library'); - $this->assertField('field_paragraphs_0_unlink_from_library'); + $this->assertSession()->buttonNotExists('field_paragraphs_0_promote_to_library'); + $this->assertSession()->buttonExists('field_paragraphs_0_unlink_from_library'); $this->drupalPostForm(NULL, $edit, 'Save'); $this->drupalGet('node/1'); - $this->assertText('Random text for testing converting into library.'); + $this->assertSession()->pageTextContains('Random text for testing converting into library.'); // Create library item from existing paragraph item. $this->drupalGet('node/add/paragraphed_test'); @@ -350,8 +421,8 @@ public function testConvertParagraphIntoLibrary() { $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_promote_to_library'); user_role_grant_permissions($user_role, ['administer paragraphs library']); $this->drupalGet('/admin/content/paragraphs'); - $this->assertText('Text'); - $this->assertText('Random text for testing converting into library.'); + $this->assertSession()->pageTextContains('Text'); + $this->assertSession()->pageTextContains('Random text for testing converting into library.'); // Test disallow convesrion. $edit = ['allow_library_conversion' => FALSE]; @@ -364,11 +435,11 @@ public function testConvertParagraphIntoLibrary() { $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, 'Add text'); - $this->assertNoRaw('Promote to library'); + $this->assertSession()->responseNotContains('Promote to library'); // Test that the checkbox is not visible on from_library. $this->drupalGet('admin/structure/paragraphs_type/from_library'); - $this->assertNoField('allow_library_conversion'); + $this->assertSession()->fieldNotExists('allow_library_conversion'); } /** @@ -399,7 +470,7 @@ public function testLibraryItemParagraphsSummary() { 'paragraphs[0][subform][field_paragraphs][0][subform][field_text][0][value]' => 'test text paragraph', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('test text paragraph'); + $this->assertSession()->pageTextContains('test text paragraph'); // Assert that the user with the access content permission can see the // paragraph type label. @@ -410,7 +481,7 @@ public function testLibraryItemParagraphsSummary() { $this->drupalLogin($user); $this->drupalGet('admin/content/paragraphs'); $paragraph_type = $this->xpath('//table/tbody/tr/td[2]'); - $this->assertEqual(trim(strip_tags($paragraph_type[0]->getText())), 'nested_test'); + $this->assertEquals(trim(strip_tags($paragraph_type[0]->getText())), 'nested_test'); } /** @@ -434,26 +505,26 @@ public function testLibraryitemValidation() { // Check the label validation. $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('Label field is required.'); + $this->assertSession()->pageTextContains('Label field is required.'); $edit = [ 'label[0][value]' => 're usable paragraph label', ]; $this->drupalPostForm(NULL, $edit, t('Save')); // Check the paragraph validation. - $this->assertText('Paragraphs field is required.'); + $this->assertSession()->pageTextContains('Paragraphs field is required.'); $this->drupalPostForm(NULL, [], 'paragraphs_text_paragraph_add_more'); $edit['paragraphs[0][subform][field_text][0][value]'] = 're_usable_text'; // Check that the library item is created. $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Paragraph re usable paragraph label has been created.'); + $this->assertSession()->pageTextContains('Paragraph re usable paragraph label has been created.'); $this->clickLink('Edit'); $edit = [ 'paragraphs[0][subform][field_text][0][value]' => 'new text', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Paragraph re usable paragraph label has been updated.'); + $this->assertSession()->pageTextContains('Paragraph re usable paragraph label has been updated.'); } /** @@ -478,7 +549,7 @@ public function testLibraryReferencingParagraphValidation() { 'paragraphs[0][subform][field_text][0][value]' => 'reusable_text', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Paragraph reusable paragraph label has been created.'); + $this->assertSession()->pageTextContains('Paragraph reusable paragraph label has been created.'); // Create a node with a "From library" paragraph referencing the library // item. @@ -489,7 +560,7 @@ public function testLibraryReferencingParagraphValidation() { 'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'reusable paragraph label', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test library_test has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test library_test has been created.'); // Disallow the paragraphs type "Text" for the used content type. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs'); @@ -499,14 +570,14 @@ public function testLibraryReferencingParagraphValidation() { 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); - $this->assertText('Saved field_paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved field_paragraphs configuration.'); // Check that the node now fails validation. $node = $this->getNodeByTitle('library_test'); $this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertUrl('node/' . $node->id() . '/edit'); - $this->assertText('The Reusable paragraph field cannot contain a text paragraph, because the parent field_paragraphs field disallows it.'); + $this->assertSession()->addressEquals('node/' . $node->id() . '/edit'); + $this->assertSession()->pageTextContains('The Reusable paragraph field cannot contain a text paragraph, because the parent field_paragraphs field disallows it.'); } /** @@ -539,16 +610,16 @@ public function testLibraryItemRevisions() { 'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'Example text for revision original.', ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertText('Paragraph Test revisions nested original has been created.'); + $this->assertSession()->pageTextContains('Paragraph Test revisions nested original has been created.'); // Check revisions tab. $this->clickLink('Test revisions nested original'); $this->clickLink('Revisions'); - $this->assertTitle('Revisions for Test revisions nested original | Drupal'); + $this->assertSession()->titleEquals('Revisions for Test revisions nested original | Drupal'); // Edit library item, check that new revision is enabled as default. $this->clickLink('Edit'); - $this->assertFieldChecked('edit-revision'); + $this->assertSession()->checkboxChecked('edit-revision'); $edit = [ 'label[0][value]' => 'Test revisions nested first change', 'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'Example text for revision first change.', @@ -560,22 +631,22 @@ public function testLibraryItemRevisions() { $date_formatter = \Drupal::service('date.formatter'); $this->clickLink('Test revisions nested first change'); $this->clickLink('Revisions'); - $this->assertTitle('Revisions for Test revisions nested first change | Drupal'); + $this->assertSession()->titleEquals('Revisions for Test revisions nested first change | Drupal'); $revision = $storage->loadRevision(1); - $this->assertText('Test revisions nested original by ' . $this->admin_user->getAccountName()); - $this->assertText($date_formatter->format($revision->getChangedTime(), 'short') . ': ' . $revision->label()); + $this->assertSession()->pageTextContains('Test revisions nested original by ' . $this->admin_user->getAccountName()); + $this->assertSession()->pageTextContains($date_formatter->format($revision->getChangedTime(), 'short') . ': ' . $revision->label()); $this->clickLink($date_formatter->format($revision->getChangedTime(), 'short'), 1); - $this->assertText('Test revisions nested original'); - $this->assertText('Example text for revision original'); + $this->assertSession()->pageTextContains('Test revisions nested original'); + $this->assertSession()->pageTextContains('Example text for revision original'); $this->clickLink('Revisions'); // Test reverting revision. $this->clickLink('Revert'); - $this->assertRaw(t('Are you sure you want to revert revision from %revision-date?', [ + $this->assertSession()->responseContains(t('Are you sure you want to revert revision from %revision-date?', [ '%revision-date' => $date_formatter->format($revision->getChangedTime()) ])); $this->drupalPostForm(NULL, NULL, 'Revert'); - $this->assertRaw(t('%title has been reverted to the revision from %revision-date.', [ + $this->assertSession()->responseContains(t('%title has been reverted to the revision from %revision-date.', [ '%title' => 'Test revisions nested original', '%revision-date' => $date_formatter->format($revision->getChangedTime()) ])); @@ -583,17 +654,17 @@ public function testLibraryItemRevisions() { // Check current revision. $current_revision = $storage->loadRevision(3); $this->clickLink($date_formatter->format($current_revision->getChangedTime(), 'short')); - $this->assertText('Example text for revision original'); + $this->assertSession()->pageTextContains('Example text for revision original'); $this->clickLink('Revisions'); // Test deleting revision. $revision_for_deleting = $storage->loadRevision(2); $this->clickLink('Delete'); - $this->assertRaw(t('Are you sure you want to delete revision from %revision-date', [ + $this->assertSession()->responseContains(t('Are you sure you want to delete revision from %revision-date', [ '%revision-date' => $date_formatter->format($revision_for_deleting->getChangedTime()) ])); $this->drupalPostForm(NULL, NULL, 'Delete'); - $this->assertRaw(t('Revision from %revision-date has been deleted.', [ + $this->assertSession()->responseContains(t('Revision from %revision-date has been deleted.', [ '%revision-date' => $date_formatter->format($revision_for_deleting->getChangedTime()) ])); } diff --git a/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php b/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php index 02502735033ec8e477127c9f2ffc93bc3b0f6d6d..a8a2a6233ff1dae9e3773738b4c4c5a2174a1b48 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php +++ b/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsContentModerationTest.php @@ -270,7 +270,7 @@ public function testModeratedParagraphedContent() { $page->fillField('revision_log[0][value]', 'Node revision #4'); $page->pressButton('Save'); // The admin is currently at /node/*/latest. - $this->assertTrue(strpos($session->getCurrentUrl(), "/node/{$host_node_id}/latest") !== FALSE); + $this->assertNotEmpty(strpos($session->getCurrentUrl(), "/node/{$host_node_id}/latest") !== FALSE); $assert_session->pageTextContains('paragraphed_moderated_test Host page 1 (rev 4) has been updated.'); // The admin user should be seeing the latest, forward-revision. $assert_session->pageTextNotContains('Direct paragraph text 3'); @@ -434,8 +434,8 @@ public function testModeratedContentNestedParagraphs() { $this->addParagraphsType('rich_paragraph'); $this->addFieldtoParagraphType('rich_paragraph', 'field_intermediate_text', 'text'); $this->addFieldtoParagraphType('rich_paragraph', 'field_nested_paragraphs', 'entity_reference', ['target_type' => 'paragraphs_library_item']); - entity_get_display('paragraph', 'rich_paragraph', 'default') - ->setComponent('field_nested_paragraphs', [ + $display = \Drupal::service('entity_display.repository')->getViewDisplay('paragraph', 'rich_paragraph'); + $display->setComponent('field_nested_paragraphs', [ 'type' => 'entity_reference_entity_view', ])->save(); diff --git a/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php b/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php index 4247f71d6d8151a310b82a4bb77a2f57dff4c5c7..4090c498ab05902feef7de9f3636fb2c4ce67c13 100644 --- a/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php +++ b/web/modules/paragraphs/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php @@ -133,7 +133,7 @@ public function testEntityBrowserWidget() { $this->waitForAjaxToFinish(); // Check that there is only one translation of the paragraph listed. $rows = $this->xpath('//*[@id="entity-browser-paragraphs-library-items-form"]/div[1]/div[2]/table/tbody/tr'); - $this->assertTrue(count($rows) == 1); + $this->assertCount(1, $rows); // Add a text paragraph in a new library item. $this->drupalGet('admin/content/paragraphs/add/default'); diff --git a/web/modules/paragraphs/modules/paragraphs_type_permissions/paragraphs_type_permissions.info.yml b/web/modules/paragraphs/modules/paragraphs_type_permissions/paragraphs_type_permissions.info.yml index d80c46fa7eb14490fba7f042afb5eeb993c0f4fd..6c65ff200e3b1d8696e792beb6dbcc086e29fb7a 100644 --- a/web/modules/paragraphs/modules/paragraphs_type_permissions/paragraphs_type_permissions.info.yml +++ b/web/modules/paragraphs/modules/paragraphs_type_permissions/paragraphs_type_permissions.info.yml @@ -7,7 +7,7 @@ package: Paragraphs dependencies: - paragraphs:paragraphs -# Information added by Drupal.org packaging script on 2020-02-16 -version: '8.x-1.11' +# Information added by Drupal.org packaging script on 2020-05-21 +version: '8.x-1.12' project: 'paragraphs' -datestamp: 1581850832 +datestamp: 1590061337 diff --git a/web/modules/paragraphs/modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php b/web/modules/paragraphs/modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php index a784efe1c7ce34bcc4bcfaa44fb3f12bcd68c188..223bf255f87e2ae3c627325fe022ea9b7699df3c 100644 --- a/web/modules/paragraphs/modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php +++ b/web/modules/paragraphs/modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php @@ -89,7 +89,9 @@ protected function setUp() { 'type' => 'image', 'settings' => ['image_style' => 'medium', 'image_link' => 'file'], ]; - $display = entity_get_display('paragraph', 'images', 'default'); + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + $display = $display_repository->getViewDisplay('paragraph', 'images'); $display->setComponent('field_images_demo', $display_options) ->save(); @@ -97,7 +99,7 @@ protected function setUp() { 'type' => 'image', 'settings' => ['image_style' => 'large', 'image_link' => 'file'], ]; - $display = entity_get_display('paragraph', 'text_image', 'default'); + $display = $display_repository->getViewDisplay('paragraph', 'text_image'); $display->setComponent('field_image_demo', $display_options) ->save(); } @@ -130,8 +132,8 @@ public function testAnonymousParagraphsTypePermissions() { 'text', ]; foreach ($paragraph_types as $paragraph_type) { - entity_get_form_display('paragraph', $paragraph_type, 'default') - ->setComponent('status', [ + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('paragraph', $paragraph_type); + $form_display->setComponent('status', [ 'type' => 'boolean_checkbox' ]) ->save(); @@ -166,26 +168,26 @@ public function testAnonymousParagraphsTypePermissions() { $images_tag = '/files/styles/medium/public/' . date('Y-m') . '/image-test_0.png?itok='; // Check that all paragraphs are shown for admin user. - $this->assertRaw($image_text_tag); - $this->assertRaw($images_tag); - $this->assertText('Paragraph type Image + Text'); - $this->assertText('Paragraph type Text'); + $this->assertSession()->responseContains($image_text_tag); + $this->assertSession()->responseContains($images_tag); + $this->assertSession()->pageTextContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextContains('Paragraph type Text'); // Logout, check that no paragraphs are shown for anonymous user. $this->drupalLogout(); $this->drupalGet('node/' . $node->id()); - $this->assertNoRaw($image_text_tag); - $this->assertNoRaw($images_tag); - $this->assertNoText('Paragraph type Image + Text'); - $this->assertNoText('Paragraph type Text'); + $this->assertSession()->responseNotContains($image_text_tag); + $this->assertSession()->responseNotContains($images_tag); + $this->assertSession()->pageTextNotContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextNotContains('Paragraph type Text'); // Login as authenticated user, check that no paragraphs are shown for him. $this->drupalLogin($authenticated_user); $this->drupalGet('node/' . $node->id()); - $this->assertNoRaw($image_text_tag); - $this->assertNoRaw($images_tag); - $this->assertNoText('Paragraph type Image + Text'); - $this->assertNoText('Paragraph type Text'); + $this->assertSession()->responseNotContains($image_text_tag); + $this->assertSession()->responseNotContains($images_tag); + $this->assertSession()->pageTextNotContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextNotContains('Paragraph type Text'); // Login as admin $this->drupalLogout(); @@ -199,17 +201,17 @@ public function testAnonymousParagraphsTypePermissions() { // Unpublish the 'Image + Text' paragraph type. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertFieldChecked('edit-field-paragraphs-demo-0-subform-status-value'); + $this->assertSession()->checkboxChecked('edit-field-paragraphs-demo-0-subform-status-value'); $edit = [ 'field_paragraphs_demo[0][subform][status][value]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); // Check that 'Image + Text' paragraph is not shown anymore for admin user. - $this->assertNoRaw($image_text_tag); - $this->assertRaw($images_tag); - $this->assertNoText('Paragraph type Image + Text'); - $this->assertText('Paragraph type Text'); + $this->assertSession()->responseNotContains($image_text_tag); + $this->assertSession()->responseContains($images_tag); + $this->assertSession()->pageTextNotContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextContains('Paragraph type Text'); $this->drupalLogout(); @@ -231,18 +233,18 @@ public function testAnonymousParagraphsTypePermissions() { // Check that the anonymous user can only view the 'Text' paragraph. $this->drupalGet('node/' . $node->id()); - $this->assertNoRaw($image_text_tag); - $this->assertNoRaw($images_tag); - $this->assertNoText('Paragraph type Image + Text'); - $this->assertText('Paragraph type Text'); + $this->assertSession()->responseNotContains($image_text_tag); + $this->assertSession()->responseNotContains($images_tag); + $this->assertSession()->pageTextNotContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextContains('Paragraph type Text'); // Check that the authenticated user can only view the 'Images' paragraph. $this->drupalLogin($authenticated_user); $this->drupalGet('node/' . $node->id()); - $this->assertNoRaw($image_text_tag); - $this->assertRaw($images_tag); - $this->assertNoText('Paragraph type Image + Text'); - $this->assertNoText('Paragraph type Text'); + $this->assertSession()->responseNotContains($image_text_tag); + $this->assertSession()->responseContains($images_tag); + $this->assertSession()->pageTextNotContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextNotContains('Paragraph type Text'); // Check the authenticated user with edit permission. $authenticated_role->grantPermission('update paragraph content text_image'); @@ -250,23 +252,23 @@ public function testAnonymousParagraphsTypePermissions() { $authenticated_role->save(); $this->drupalLogin($authenticated_user); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('Image + Text'); - $this->assertText('Paragraph type Image + Text'); - $this->assertText('You are not allowed to remove this Paragraph.'); - $this->assertText('Published'); - $this->assertText('Images'); - $this->assertText('You are not allowed to edit or remove this Paragraph.'); - $this->assertRaw('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">image-test_0.png<'); - $this->assertNoRaw('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Paragraph type Text<'); + $this->assertSession()->responseContains('Image + Text'); + $this->assertSession()->pageTextContains('Paragraph type Image + Text'); + $this->assertSession()->pageTextContains('You are not allowed to remove this Paragraph.'); + $this->assertSession()->pageTextContains('Published'); + $this->assertSession()->pageTextContains('Images'); + $this->assertSession()->pageTextContains('You are not allowed to edit or remove this Paragraph.'); + $this->assertSession()->responseContains('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">image-test_0.png<'); + $this->assertSession()->responseNotContains('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Paragraph type Text<'); // Check that the paragraph is collapsed by asserting the content summary. $authenticated_role->grantPermission('view paragraph content text'); $authenticated_role->save(); $this->drupalLogin($authenticated_user); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertText('You are not allowed to edit or remove this Paragraph.'); - $this->assertRaw('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">image-test_0.png<'); - $this->assertRaw('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Paragraph type Text<'); + $this->assertSession()->pageTextContains('You are not allowed to edit or remove this Paragraph.'); + $this->assertSession()->responseContains('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">image-test_0.png<'); + $this->assertSession()->responseContains('paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Paragraph type Text<'); } } diff --git a/web/modules/paragraphs/paragraphs.info.yml b/web/modules/paragraphs/paragraphs.info.yml index 6b54227d9420ba8a8d2302ea7121aee99fb2fdc3..f3c67844e9f057b588e12af65c65d80d6e148cbd 100644 --- a/web/modules/paragraphs/paragraphs.info.yml +++ b/web/modules/paragraphs/paragraphs.info.yml @@ -1,7 +1,7 @@ name: Paragraphs type: module description: 'Enables the creation of paragraphs entities.' -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.8 || ^9 package: Paragraphs configure: entity.paragraphs_type.collection @@ -16,7 +16,7 @@ test_dependencies: - field_group:field_group - block_field:block_field -# Information added by Drupal.org packaging script on 2020-02-16 -version: '8.x-1.11' +# Information added by Drupal.org packaging script on 2020-05-21 +version: '8.x-1.12' project: 'paragraphs' -datestamp: 1581850832 +datestamp: 1590061337 diff --git a/web/modules/paragraphs/paragraphs.install b/web/modules/paragraphs/paragraphs.install index 49bb4541b74ce42c16b09814f3c2a50e2fb8cd4a..0bf3cae5c61aed3239741cbf51396ce9c51ba504 100644 --- a/web/modules/paragraphs/paragraphs.install +++ b/web/modules/paragraphs/paragraphs.install @@ -220,6 +220,30 @@ function paragraphs_update_8013() { $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $entity_type = $definition_update_manager->getEntityType('paragraph'); + // Update the field storage definitions of the parent fields + // as done in 8019. + $last_installed_schema = \Drupal::service('entity.last_installed_schema.repository'); + foreach (['parent_id', 'parent_type', 'parent_field_name'] as $field_name) { + $column_schema = [ + 'type' => 'varchar_ascii', + 'length' => $field_name == 'parent_id' ? 255 : 32, + 'binary' => FALSE, + 'not null' => FALSE, + ]; + // Update the field storage repository. + $storage_definition = $definition_update_manager->getFieldStorageDefinition($field_name, 'paragraph'); + $storage_definition->setRevisionable(TRUE); + $last_installed_schema->setLastInstalledFieldStorageDefinition($storage_definition); + + // Update the stored field schema. + // @todo: There has to be a better way to do this. + $key = 'paragraph.field_schema_data.' . $field_name; + $field_schema = \Drupal::keyValue('entity.storage_schema.sql')->get($key); + $field_schema['paragraphs_item_revision_field_data']['fields'][$field_name] = $column_schema; + \Drupal::keyValue('entity.storage_schema.sql')->set($key, $field_schema); + } + + // Update the revision metadata keys to remove revision uid which is removed // in 8017 and 8021. if ($metadata_keys = $entity_type->get('revision_metadata_keys')) { @@ -315,11 +339,11 @@ function paragraphs_update_8016() { } /** - * Moved function content to paragraphs_update_8023(). - * see https://www.drupal.org/project/paragraphs/issues/2833935#comment-13471948 + * Update the revision metadata keys to remove revision uid. */ function paragraphs_update_8017() { - + // Moved function content to paragraphs_update_8021(), see + // https://www.drupal.org/project/paragraphs/issues/2833935. } /** @@ -448,19 +472,3 @@ function paragraphs_update_8022() { // Regenerate entity type indexes. $manager->updateEntityType($manager->getEntityType('paragraph')); } - -/** - * Update the revision metadata keys to remove revision uid. - */ -function paragraphs_update_8023() { - $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager(); - $entity_type = $entity_definition_update_manager->getEntityType('paragraph'); - if ($metadata_keys = $entity_type->get('revision_metadata_keys')) { - if (is_array($metadata_keys) && isset($metadata_keys['revision_user'])) { - unset($metadata_keys['revision_user']); - $metadata_keys['revision_default'] = 'revision_default'; - $entity_type->set('revision_metadata_keys', $metadata_keys); - $entity_definition_update_manager->updateEntityType($entity_type); - } - } -} diff --git a/web/modules/paragraphs/paragraphs.libraries.yml b/web/modules/paragraphs/paragraphs.libraries.yml index 42f4733efa023703b59d3013b153297ae2122f87..e59af4435b50821ceaa4b3276ca8f9953a916ed2 100644 --- a/web/modules/paragraphs/paragraphs.libraries.yml +++ b/web/modules/paragraphs/paragraphs.libraries.yml @@ -72,16 +72,6 @@ drupal.paragraphs.modal: - core/drupal.dialog.ajax - core/jquery.once -# This library will be deleted in paragraphs_library_info_alter when -# core/sortable is available. -sortable: - website: https://github.com/RubaXa/Sortable - license: - name: MIT - url: https://github.com/RubaXa/Sortable/blob/master/README.md - gpl-compatible: true - js: { } - paragraphs-dragdrop: css: theme: @@ -91,9 +81,6 @@ paragraphs-dragdrop: dependencies: - core/jquery - core/drupal - # Sortable is only in core from 8.8+. When the library is not available, the - # dependency will be changed with paragraphs/sortable in - # paragraphs_library_info_alter. - core/sortable drupal.paragraphs.formatter: diff --git a/web/modules/paragraphs/paragraphs.links.menu.yml b/web/modules/paragraphs/paragraphs.links.menu.yml index 2a2a98f91d07a4211103e8996a7d61da3e532e29..d101b6f62c54ad0fe0b617189927a7210cb8d806 100644 --- a/web/modules/paragraphs/paragraphs.links.menu.yml +++ b/web/modules/paragraphs/paragraphs.links.menu.yml @@ -8,3 +8,9 @@ paragraphs.settings: title: 'Paragraphs settings' parent: system.admin_config_content route_name: paragraphs.settings + +paragraphs.type_add: + title: 'Add paragraph type' + menu_name: admin + parent: entity.paragraphs_type.collection + route_name: paragraphs.type_add diff --git a/web/modules/paragraphs/paragraphs.module b/web/modules/paragraphs/paragraphs.module index 20aacf17a019d1509721ffcc582e68c39c6f867b..53f7d5f091d7665e54a295b81badc313f5deed29 100644 --- a/web/modules/paragraphs/paragraphs.module +++ b/web/modules/paragraphs/paragraphs.module @@ -291,7 +291,7 @@ function template_preprocess_paragraph(&$variables) { } $paragraph_type = $variables['elements']['#paragraph']->getParagraphType(); - foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin_value) { + foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_value) { $plugin_value->preprocess($variables); } @@ -391,103 +391,6 @@ function paragraphs_preprocess_field_multiple_value_form(&$variables) { } } -/** - * Implements hook_libraries_info(). - */ -function paragraphs_libraries_info() { - // Drupal 8.8+ has the sortable library in core, so we don't need to provide custom library information here. - if (version_compare(\Drupal::VERSION, '8.8', '>=')) { - return []; - } - - $libraries = [ - 'Sortable' => [ - 'name' => 'Sortable', - 'vendor url' => 'https://github.com/RubaXa/Sortable', - 'download url' => 'https://github.com/RubaXa/Sortable/releases', - 'files' => [ - 'js' => [ - 'Sortable.min.js' => [], - ], - ], - 'version arguments' => [ - // The version is at the end of the file, which is currently about 15k - // characters long. - 'file' => 'Sortable.min.js', - 'pattern' => '/\.version="(.*?)"/', - 'lines' => 5, - 'cols' => 20000 - ] - ], - ]; - return $libraries; -} - -/** - * Implements hook_library_info_alter(). - */ -function paragraphs_library_info_alter(&$libraries, $extension) { - if ($extension != 'paragraphs') { - return; - } - - if (version_compare(\Drupal::VERSION, '8.8', '>=')) { - // When core/sortable is available, the paragraphs/sortable library can be removed. - unset($libraries['sortable']); - return $libraries; - } - else { - // If the core/sortable is not available, the paragraphs/sortable library should be used as a dependency of - // paragraphs-dragdrop instead. - $library_core_dep_key = array_search('core/sortable', $libraries['paragraphs-dragdrop']['dependencies']); - $libraries['paragraphs-dragdrop']['dependencies'][$library_core_dep_key] = 'paragraphs/sortable'; - } - - if (\Drupal::moduleHandler()->moduleExists('libraries')) { - $info = libraries_detect('Sortable'); - } - else { - // If the library module is not installed, hardcode the path and fetch - // the required information ourself. - $library_path = 'libraries/Sortable'; - $file = 'Sortable.min.js'; - $path = DRUPAL_ROOT . '/' . $library_path . '/' . $file; - if (file_exists($path)) { - if (preg_match('/\.version="(.*?)"/', file_get_contents($path), $version)) { - $info = [ - 'installed' => TRUE, - 'version' => $version[1], - 'library path' => $library_path, - 'files' => [ - 'js' => [ - $file => [], - ], - ], - ]; - } - } - } - - if (!empty($info['installed'])) { - $libraries['sortable'] += [ - 'version' => $info['version'], - ]; - // Self hosted player, use files from library definition. - if (!empty($info['files']['js'])) { - foreach ($info['files']['js'] as $filename => $options) { - $libraries['sortable']['js']["/{$info['library path']}/{$filename}"] = $options; - } - } - } - else { - // Unset the libraries if we failed to detect them. - unset($libraries['sortable']); - unset($libraries['paragraphs-dragdrop']); - } - - return $libraries; -} - /** * Implements hook_migration_plugins_alter(). * @@ -500,7 +403,7 @@ function paragraphs_migration_plugins_alter(array &$migrations) { /** @var \Drupal\migrate\Plugin\MigrateSourcePluginManager $source_plugin_manager */ $source_plugin_manager = \Drupal::service('plugin.manager.migrate.source'); - foreach ($migrations as $key => &$migration) { + foreach ($migrations as &$migration) { if (!empty($migration['source'])) { $configuration = $migration['source']; $migration_stub = $migration_plugin_manager->createStubMigration($migration); diff --git a/web/modules/paragraphs/paragraphs.plugin_type.yml b/web/modules/paragraphs/paragraphs.plugin_type.yml new file mode 100644 index 0000000000000000000000000000000000000000..9d063e14bdf63ed0ea6bdb37ec101e9a3cb7b981 --- /dev/null +++ b/web/modules/paragraphs/paragraphs.plugin_type.yml @@ -0,0 +1,4 @@ +paragraphs.paragraphs_behavior: + label: 'Paragraphs behavior' + plugin_manager_service_id: plugin.manager.paragraphs.behavior + plugin_definition_decorator_class: Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator diff --git a/web/modules/paragraphs/paragraphs.post_update.php b/web/modules/paragraphs/paragraphs.post_update.php index 8208016385f28aa91884e0c09276dc55ff5b747a..d76c3d2e8dd4c9247860b6f840f4ac0a895b65b8 100644 --- a/web/modules/paragraphs/paragraphs.post_update.php +++ b/web/modules/paragraphs/paragraphs.post_update.php @@ -5,6 +5,7 @@ * Post update functions for Paragraphs. */ +use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\Condition; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -202,7 +203,7 @@ function paragraphs_post_update_rebuild_parent_fields(array &$sandbox) { } $current_field = $sandbox['paragraph_field_ids'][$sandbox['current_index']]; - $revision_column = $current_field['revision_column']; + $revision_column = !empty($current_field['revision_column']) ? ($current_field['revision_column']) : $current_field['field_name'] . '_target_revision_id'; $entity_id_column = $current_field['entity_id_column']; $entity_type_id = $current_field['entity_type_id']; $field_name = $current_field['field_name']; @@ -216,7 +217,13 @@ function paragraphs_post_update_rebuild_parent_fields(array &$sandbox) { // Select paragraphs with at least one wrong parent field. $or_group = new Condition('OR'); - $or_group->where("p.parent_id <> f.$entity_id_column"); + // Only use CAST if the db driver is Postgres. + if (Database::getConnection()->databaseType() == 'pgsql') { + $or_group->where("CAST(p.parent_id as TEXT) <> CAST(f.$entity_id_column as TEXT)"); + } + else { + $or_group->where("p.parent_id <> f.$entity_id_column"); + } $or_group->condition('p.parent_type', $entity_type_id, '<>'); $or_group->condition('p.parent_field_name', $field_name, '<>'); $query->condition($or_group); diff --git a/web/modules/paragraphs/src/Entity/Paragraph.php b/web/modules/paragraphs/src/Entity/Paragraph.php index c96fac05e9461ad5946d907940e6ccf33010e1c2..07e86ab1398d5fa15620773b709ce779acc68be9 100644 --- a/web/modules/paragraphs/src/Entity/Paragraph.php +++ b/web/modules/paragraphs/src/Entity/Paragraph.php @@ -150,18 +150,17 @@ public function label() { if (($parent = $this->getParentEntity()) && $parent->hasField($this->get('parent_field_name')->value)) { $parent_field = $this->get('parent_field_name')->value; $field = $parent->get($parent_field); - $found = FALSE; - foreach ($field as $key => $value) { - if ($value->entity->id() == $this->id()) { - $found = TRUE; + $label = $parent->label() . ' > ' . $field->getFieldDefinition()->getLabel(); + // A previous or draft revision or a deleted stale Paragraph. + $postfix = ' (previous revision)'; + foreach ($field as $value) { + if ($value->entity && $value->entity->getRevisionId() == $this->getRevisionId()) { + $postfix = ''; break; } } - if ($found) { - $label = $parent->label() . ' > ' . $field->getFieldDefinition()->getLabel(); - } else { - // A previous or draft revision or a deleted stale Paragraph. - $label = $parent->label() . ' > ' . $field->getFieldDefinition()->getLabel() . ' (previous revision)'; + if ($postfix) { + $label .= $postfix; } } else { @@ -452,7 +451,7 @@ public function getSummaryItems(array $options = []) { // Add content summary items. $this->summaryCount = 0; - $components = entity_get_form_display('paragraph', $this->getType(), 'default')->getComponents(); + $components = \Drupal::service('entity_display.repository')->getFormDisplay('paragraph', $this->getType())->getComponents(); uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); foreach (array_keys($components) as $field_name) { // Components can be extra fields, check if the field really exists. @@ -525,7 +524,7 @@ public function getSummaryItems(array $options = []) { // Add behaviors summary items. if ($show_behavior_summary) { $paragraphs_type = $this->getParagraphType(); - foreach ($paragraphs_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin) { + foreach ($paragraphs_type->getEnabledBehaviorPlugins() as $plugin) { if ($plugin_summary = $plugin->settingsSummary($this)) { foreach ($plugin_summary as $plugin_summary_element) { if (!is_array($plugin_summary_element)) { @@ -561,7 +560,7 @@ public function getIcons(array $options = []) { if ($show_behavior_info) { $paragraphs_type = $this->getParagraphType(); - foreach ($paragraphs_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin) { + foreach ($paragraphs_type->getEnabledBehaviorPlugins() as $plugin) { if ($plugin_info = $plugin->settingsIcon($this)) { $icons = array_merge($icons, $plugin_info); } @@ -647,7 +646,7 @@ public function isChanged() { protected function getFileSummary($field_name) { $summary = ''; if ($this->get($field_name)->entity) { - foreach ($this->get($field_name) as $file_key => $file_value) { + foreach ($this->get($field_name) as $file_value) { $text = ''; if ($file_value->description != '') { diff --git a/web/modules/paragraphs/src/Form/ParagraphsSettingsForm.php b/web/modules/paragraphs/src/Form/ParagraphsSettingsForm.php index 1d7da4cac09cb29fdffc9b566c6f446a9ae298b7..0f6a410ef812ae34eb78af4205d25b9a839e7a86 100644 --- a/web/modules/paragraphs/src/Form/ParagraphsSettingsForm.php +++ b/web/modules/paragraphs/src/Form/ParagraphsSettingsForm.php @@ -33,7 +33,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('Show unpublished Paragraphs'), '#default_value' => $config->get('show_unpublished'), - '#description' => $this->t('Allow users with "View unpublished paragraphs" permission to see unpublished Paragraphs.') + '#description' => $this->t('Allow users with "View unpublished paragraphs" permission to see unpublished Paragraphs. Disable this if unpublished paragraphs should be hidden for all users, including super administrators.') ]; return parent::buildForm($form, $form_state); diff --git a/web/modules/paragraphs/src/Form/ParagraphsTypeForm.php b/web/modules/paragraphs/src/Form/ParagraphsTypeForm.php index c92774da528bef36fad83609ecbb37a5813a326b..986533e5c0d44ef22b412835e09fe210424b26af 100644 --- a/web/modules/paragraphs/src/Form/ParagraphsTypeForm.php +++ b/web/modules/paragraphs/src/Form/ParagraphsTypeForm.php @@ -213,8 +213,8 @@ public function save(array $form, FormStateInterface $form_state) { } } else { - // The plugin is not enabled, reset to default configuration. - $behavior_plugin->setConfiguration([]); + // The plugin is not enabled, remove it from the paragraphs type. + $paragraphs_type->getBehaviorPlugins()->removeInstanceId($id); } } } diff --git a/web/modules/paragraphs/src/ParagraphViewBuilder.php b/web/modules/paragraphs/src/ParagraphViewBuilder.php index 87b45ebb5f03843e5c132b9b06ca722c8159aab0..bca9b7175dbc593f31b8699cbb993cf30ebae265 100644 --- a/web/modules/paragraphs/src/ParagraphViewBuilder.php +++ b/web/modules/paragraphs/src/ParagraphViewBuilder.php @@ -34,7 +34,7 @@ public function buildMultiple(array $build_list) { ]); } - foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin_value) { + foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_value) { $plugin_value->view($build_list[$key], $build['#paragraph'], $display, $build['#view_mode']); } $build_list[$key]['#attached']['library'][] = 'paragraphs/drupal.paragraphs.unpublished'; diff --git a/web/modules/paragraphs/src/Plugin/EntityReferenceSelection/ParagraphSelection.php b/web/modules/paragraphs/src/Plugin/EntityReferenceSelection/ParagraphSelection.php index 2aa7acd0cc85abd61dc79495f1287f3b532e6605..1545d85cc54bbaffbda068961b42d8bbd3e5e913 100644 --- a/web/modules/paragraphs/src/Plugin/EntityReferenceSelection/ParagraphSelection.php +++ b/web/modules/paragraphs/src/Plugin/EntityReferenceSelection/ParagraphSelection.php @@ -19,22 +19,24 @@ * ) */ class ParagraphSelection extends DefaultSelection { + /** + * @inheritDoc + */ + public function defaultConfiguration() { + return parent::defaultConfiguration() + [ + 'negate' => 0, + 'target_bundles_drag_drop' => [], + ]; + } + /** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $entity_type_id = $this->configuration['target_type']; - $selection_handler_settings = $this->configuration['handler_settings'] ?: array(); $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - // Merge-in default values. - $selection_handler_settings += array( - 'target_bundles' => array(), - 'negate' => 0, - 'target_bundles_drag_drop' => array(), - ); - $bundle_options = array(); $bundle_options_simple = array(); @@ -45,8 +47,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $bundle_options_simple[$bundle_name] = $bundle_info['label']; $bundle_options[$bundle_name] = array( 'label' => $bundle_info['label'], - 'enabled' => isset($selection_handler_settings['target_bundles_drag_drop'][$bundle_name]['enabled']) ? $selection_handler_settings['target_bundles_drag_drop'][$bundle_name]['enabled'] : FALSE, - 'weight' => isset($selection_handler_settings['target_bundles_drag_drop'][$bundle_name]['weight']) ? $selection_handler_settings['target_bundles_drag_drop'][$bundle_name]['weight'] : $weight, + 'enabled' => $this->configuration['target_bundles_drag_drop'][$bundle_name]['enabled'] ?? FALSE, + 'weight' => $this->configuration['target_bundles_drag_drop'][$bundle_name]['weight'] ?? $weight, ); $weight++; } @@ -59,14 +61,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta 0 => $this->t('Include the selected below'), ], '#title' => $this->t('Which Paragraph types should be allowed?'), - '#default_value' => isset($selection_handler_settings['negate']) ? $selection_handler_settings['negate'] : 0, + '#default_value' => $this->configuration['negate'], ]; // Kept for compatibility with other entity reference widgets. $form['target_bundles'] = array( '#type' => 'checkboxes', '#options' => $bundle_options_simple, - '#default_value' => isset($selection_handler_settings['target_bundles']) ? $selection_handler_settings['target_bundles'] : array(), + '#default_value' => $this->configuration['target_bundles'] ?? [], '#access' => FALSE, ); @@ -180,18 +182,18 @@ public function getSortedAllowedTypes() { $return_bundles = []; $bundles = $this->entityTypeBundleInfo->getBundleInfo('paragraph'); - if (!empty($this->configuration['handler_settings']['target_bundles'])) { - if (isset($this->configuration['handler_settings']['negate']) && $this->configuration['handler_settings']['negate'] == '1') { - $bundles = array_diff_key($bundles, $this->configuration['handler_settings']['target_bundles']); + if (!empty($this->configuration['target_bundles'])) { + if (isset($this->configuration['negate']) && $this->configuration['negate'] == '1') { + $bundles = array_diff_key($bundles, $this->configuration['target_bundles']); } else { - $bundles = array_intersect_key($bundles, $this->configuration['handler_settings']['target_bundles']); + $bundles = array_intersect_key($bundles, $this->configuration['target_bundles']); } } // Support for the paragraphs reference type. - if (!empty($this->configuration['handler_settings']['target_bundles_drag_drop'])) { - $drag_drop_settings = $this->configuration['handler_settings']['target_bundles_drag_drop']; + if (!empty($this->configuration['target_bundles_drag_drop'])) { + $drag_drop_settings = $this->configuration['target_bundles_drag_drop']; $max_weight = count($bundles); foreach ($drag_drop_settings as $bundle_info) { @@ -245,14 +247,13 @@ public function validateReferenceableNewEntities(array $entities) { */ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { $target_type = $this->configuration['target_type']; - $handler_settings = $this->configuration['handler_settings']; $entity_type = $this->entityTypeManager->getDefinition($target_type); $query = $this->entityTypeManager->getStorage($target_type)->getQuery(); // If 'target_bundles' is NULL, all bundles are referenceable, no further // conditions are needed. - if (isset($handler_settings['target_bundles']) && is_array($handler_settings['target_bundles'])) { + if (is_array($this->configuration['target_bundles'])) { $target_bundles = array_keys($this->getSortedAllowedTypes()); // If 'target_bundles' is an empty array, no bundle is referenceable, @@ -278,8 +279,8 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') $query->addMetaData('entity_reference_selection_handler', $this); // Add the sort option. - if (!empty($handler_settings['sort'])) { - $sort_settings = $handler_settings['sort']; + if (!empty($this->configuration['sort'])) { + $sort_settings = $this->configuration['sort']; if ($sort_settings['field'] != '_none') { $query->sort($sort_settings['field'], $sort_settings['direction']); } diff --git a/web/modules/paragraphs/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php b/web/modules/paragraphs/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php index 6987d5ba54073d3ba3952a2fa5df302f9185bae8..d66b1ea092e5a8276dd9e786e76886048027b886 100644 --- a/web/modules/paragraphs/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php +++ b/web/modules/paragraphs/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php @@ -63,7 +63,7 @@ public static function isApplicable(FieldDefinitionInterface $field_definition) $target_type = $field_definition->getSetting('target_type'); $paragraph_type = \Drupal::entityTypeManager()->getDefinition($target_type); if ($paragraph_type) { - return $paragraph_type->isSubclassOf(ParagraphInterface::class); + return $paragraph_type->entityClassImplements(ParagraphInterface::class); } return FALSE; diff --git a/web/modules/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/web/modules/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php index 4fe506f939ccac0d9fcafff8997d0e010cf7496a..d90cb147c6cff9eee41227f56f57b33171ab2b25 100644 --- a/web/modules/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/web/modules/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Render\Element; +use Drupal\field_group\FormatterHelper; use Drupal\paragraphs\ParagraphInterface; use Symfony\Component\Validator\ConstraintViolationInterface; use Drupal\paragraphs\Plugin\EntityReferenceSelection\ParagraphSelection; @@ -418,6 +419,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#prefix' => '<li class="remove dropbutton__item dropbutton__item--extrasmall">', '#suffix' => '</li>', '#paragraphs_mode' => 'remove', + '#attributes' => [ + 'class' => ['button--small'], + ], ]; } @@ -645,10 +649,13 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ]; field_group_attach_groups($element['subform'], $context); - if (function_exists('field_group_form_pre_render')) { + if (method_exists(FormatterHelper::class, 'formProcess')) { + $element['subform']['#process'][] = [FormatterHelper::class, 'formProcess']; + } + elseif (function_exists('field_group_form_pre_render')) { $element['subform']['#pre_render'][] = 'field_group_form_pre_render'; } - if (function_exists('field_group_form_process')) { + elseif (function_exists('field_group_form_process')) { $element['subform']['#process'][] = 'field_group_form_process'; } } @@ -1052,7 +1059,7 @@ protected function buildButtonsAddMode() { '#type' => 'submit', '#name' => strtr($this->fieldIdPrefix, '-', '_') . '_' . $machine_name . '_add_more', '#value' => $this->t('Add @type', ['@type' => $label]), - '#attributes' => ['class' => ['field-add-more-submit']], + '#attributes' => ['class' => ['field-add-more-submit', 'button--small']], '#limit_validation_errors' => [array_merge($this->fieldParents, [$field_name, 'add_more'])], '#submit' => [[get_class($this), 'addMoreSubmit']], '#ajax' => [ @@ -1238,7 +1245,7 @@ protected function getSelectionHandlerSetting($setting_name) { protected function isContentReferenced() { $target_type = $this->getFieldSetting('target_type'); $target_type_info = \Drupal::entityTypeManager()->getDefinition($target_type); - return $target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface'); + return $target_type_info->entityClassImplements('\Drupal\Core\Entity\ContentEntityInterface'); } /** @@ -1298,7 +1305,7 @@ public function massageFormValues(array $values, array $form, FormStateInterface $widget_state = static::getWidgetState($form['#parents'], $field_name, $form_state); $element = NestedArray::getValue($form_state->getCompleteForm(), $widget_state['array_parents']); - foreach ($values as $delta => &$item) { + foreach ($values as &$item) { if (isset($widget_state['paragraphs'][$item['_original_delta']]['entity']) && $widget_state['paragraphs'][$item['_original_delta']]['mode'] != 'remove') { $paragraphs_entity = $widget_state['paragraphs'][$item['_original_delta']]['entity']; @@ -1497,7 +1504,7 @@ public static function isApplicable(FieldDefinitionInterface $field_definition) $target_type = $field_definition->getSetting('target_type'); $paragraph_type = \Drupal::entityTypeManager()->getDefinition($target_type); if ($paragraph_type) { - return $paragraph_type->isSubclassOf(ParagraphInterface::class); + return $paragraph_type->entityClassImplements(ParagraphInterface::class); } return FALSE; diff --git a/web/modules/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/web/modules/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php index 7c2a7070c1be38bf621d953abd3182a3e0722788..6625db3a0d47d3aae1f9c60d5d7ca5fd9d8cfe01 100644 --- a/web/modules/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php +++ b/web/modules/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php @@ -16,6 +16,7 @@ use Drupal\Core\Form\SubformState; use Drupal\Core\Render\Element; use Drupal\Core\TypedData\TranslationStatusInterface; +use Drupal\field_group\FormatterHelper; use Drupal\paragraphs\ParagraphInterface; use Drupal\paragraphs\Plugin\EntityReferenceSelection\ParagraphSelection; use Symfony\Component\Validator\ConstraintViolationInterface; @@ -562,7 +563,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['top']['type']['label'] = ['#markup' => $bundle_info['label']]; // Type icon and label bundle. - if ($icon_url = $paragraphs_entity->type->entity->getIconUrl()) { + if ($icon_url = $paragraphs_entity->getParagraphType()->getIconUrl()) { $element['top']['type']['icon'] = [ '#theme' => 'image', '#uri' => $icon_url, @@ -601,6 +602,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen 'wrapper' => $widget_state['ajax_wrapper_id'], ], '#access' => $this->duplicateButtonAccess($paragraphs_entity), + '#attributes' => [ + 'class' => ['button--small'], + ], ]; // Force the closed mode when the user cannot edit the Paragraph. @@ -625,6 +629,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ], '#access' => $this->removeButtonAccess($paragraphs_entity), '#paragraphs_mode' => 'remove', + '#attributes' => [ + 'class' => ['button--small'], + ], ]; } @@ -720,7 +727,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $context = [ 'form' => $form, - 'widget' => self::getWidgetState($parents, $field_name, $form_state, $widget_state), + 'widget' => self::getWidgetState($parents, $field_name, $form_state), 'items' => $items, 'delta' => $delta, 'element' => $element, @@ -760,10 +767,13 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ]; field_group_attach_groups($element['subform'], $context); - if (function_exists('field_group_form_pre_render')) { + if (method_exists(FormatterHelper::class, 'formProcess')) { + $element['subform']['#process'][] = [FormatterHelper::class, 'formProcess']; + } + elseif (function_exists('field_group_form_pre_render')) { $element['subform']['#pre_render'][] = 'field_group_form_pre_render'; } - if (function_exists('field_group_form_process')) { + elseif (function_exists('field_group_form_process')) { $element['subform']['#process'][] = 'field_group_form_process'; } } @@ -836,6 +846,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['behavior_plugins'][$plugin_id] = [ '#type' => 'container', '#group' => implode('][', array_merge($element_parents, ['paragraph_behavior'])), + '#parents' => array_merge(array_slice($element_parents, 0, -1), ['behavior_plugins', $plugin_id]), ]; $subform_state = SubformState::createForSubform($element['behavior_plugins'][$plugin_id], $form, $form_state); if ($plugin_form = $plugin->buildBehaviorForm($paragraphs_entity, $element['behavior_plugins'][$plugin_id], $subform_state)) { @@ -927,7 +938,6 @@ protected function buildModalAddForm(array &$element) { 'class' => [ 'paragraph-type-add-modal', 'first-button', - 'paragraphs-add-wrapper', ], ], '#access' => $this->allowReferenceChanges(), @@ -942,6 +952,7 @@ protected function buildModalAddForm(array &$element) { 'class' => [ 'paragraph-type-add-modal-button', 'js-show', + 'button--small', ], ], ]; @@ -1187,6 +1198,8 @@ public function formMultipleElements(FieldItemListInterface $items, array &$form if (($this->realItemCount < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state->isProgrammed() && $this->allowReferenceChanges()) { $elements['add_more'] = $this->buildAddActions(); + // Add the class to hide the add actions in the Behavior perspective. + $elements['add_more']['#attributes']['class'][] = 'paragraphs-add-wrapper'; } $elements['#allow_reference_changes'] = $this->allowReferenceChanges(); @@ -1553,7 +1566,7 @@ public static function getSubmitElementInfo(array $form, FormStateInterface $for protected function buildDropbutton(array $elements = []) { $build = [ '#type' => 'container', - '#attributes' => ['class' => ['paragraphs-dropbutton-wrapper', 'paragraphs-add-wrapper']], + '#attributes' => ['class' => ['paragraphs-dropbutton-wrapper']], ]; $operations = []; @@ -1594,7 +1607,7 @@ protected function buildButtonsAddMode() { '#type' => 'submit', '#name' => $this->fieldIdPrefix . '_' . $machine_name . '_add_more', '#value' => $add_mode == 'modal' ? $label : $this->t('Add @type', ['@type' => $label]), - '#attributes' => ['class' => ['field-add-more-submit', 'paragraphs-add-wrapper']], + '#attributes' => ['class' => ['field-add-more-submit']], '#limit_validation_errors' => [array_merge($this->fieldParents, [$this->fieldDefinition->getName(), 'add_more'])], '#submit' => [[get_class($this), 'addMoreSubmit']], '#ajax' => [ @@ -1609,15 +1622,21 @@ protected function buildButtonsAddMode() { } } - // Determine if buttons should be rendered as dropbuttons. - if (count($options) > 1 && $add_mode == 'dropdown') { - $add_more_elements = $this->buildDropbutton($add_more_elements); + // Define the way how buttons are rendered and add them to a container. + if ($add_mode == 'dropdown') { + if (count($add_more_elements) > 1) { + $add_more_elements = $this->buildDropbutton($add_more_elements); + } + else { + $add_more_elements['#attributes']['class'][] = 'paragraphs-dropbutton-wrapper'; + } $add_more_elements['#suffix'] = $this->t('to %type', ['%type' => $this->fieldDefinition->getLabel()]); } elseif ($add_mode == 'modal') { $this->buildModalAddForm($add_more_elements); $add_more_elements['add_modal_form_area']['#suffix'] = '<span class="paragraphs-add-suffix">' . $this->t('to %type', ['%type' => $this->fieldDefinition->getLabel()]) . '</span>'; } + $add_more_elements['#type'] = 'container'; $add_more_elements['#weight'] = 1; return $add_more_elements; @@ -1637,9 +1656,6 @@ protected function buildSelectAddMode() { $add_more_elements = [ '#type' => 'container', - '#attributes' => [ - 'class' => ['paragraphs-add-wrapper'], - ], ]; $add_more_elements['add_more_select'] = [ @@ -2716,12 +2732,8 @@ protected function duplicateButtonAccess(ParagraphInterface $paragraph) { $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality(); - // Hide the button if field cardinality is one. - if ($cardinality == 1) { - return FALSE; - } - - return TRUE; + // Hide the button if field cardinality is reached. + return !($cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && $this->realItemCount === $cardinality); } /** diff --git a/web/modules/paragraphs/src/Tests/Classic/ParagraphsCoreVersionUiTestTrait.php b/web/modules/paragraphs/src/Tests/Classic/ParagraphsCoreVersionUiTestTrait.php deleted file mode 100644 index 361c87242c33f899cdc78865723d2d2bb9c66f5b..0000000000000000000000000000000000000000 --- a/web/modules/paragraphs/src/Tests/Classic/ParagraphsCoreVersionUiTestTrait.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Drupal\paragraphs\Tests\Classic; - -/** - * Provides helper methods for Drupal 8.3.x and 8.4.x versions. - */ -trait ParagraphsCoreVersionUiTestTrait { - - /** - * An adapter for 8.3 > 8.4 Save (and (un)publish) node button change. - * - * Arguments are the same as WebTestBase::drupalPostForm. - * - * @see \Drupal\simpletest\WebTestBase::drupalPostForm - * @see https://www.drupal.org/node/2847274 - * - * @param \Drupal\Core\Url|string $path - * Location of the post form. - * @param array $edit - * Field data in an associative array. - * @param mixed $submit - * Value of the submit button whose click is to be emulated. For example, - * @param array $options - * (optional) Options to be forwarded to the url generator. - * @param array $headers - * (optional) An array containing additional HTTP request headers. - * @param string $form_html_id - * (optional) HTML ID of the form to be submitted. - * @param string $extra_post - * (optional) A string of additional data to append to the POST submission. - */ - protected function paragraphsPostNodeForm($path, $edit, $submit, array $options = [], array $headers = [], $form_html_id = NULL, $extra_post = NULL) { - $drupal_version = (float) substr(\Drupal::VERSION, 0, 3); - if ($drupal_version > 8.3) { - switch ($submit) { - case t('Save and unpublish'): - $submit = t('Save'); - $edit['status[value]'] = FALSE; - break; - - case t('Save and publish'): - $submit = t('Save'); - $edit['status[value]'] = TRUE; - break; - - case t('Save and keep published (this translation)'): - $submit = t('Save (this translation)'); - break; - - default: - $submit = t('Save'); - } - } - parent::drupalPostForm($path, $edit, $submit, $options, $headers, $form_html_id, $extra_post); - } - -} diff --git a/web/modules/paragraphs/src/Tests/Classic/ParagraphsTestBase.php b/web/modules/paragraphs/src/Tests/Classic/ParagraphsTestBase.php deleted file mode 100644 index 031ecc54ad721d0ee8ac6b70c36eec01f5165b82..0000000000000000000000000000000000000000 --- a/web/modules/paragraphs/src/Tests/Classic/ParagraphsTestBase.php +++ /dev/null @@ -1,202 +0,0 @@ -<?php - -namespace Drupal\paragraphs\Tests\Classic; - -use Drupal\Core\Entity\Entity\EntityFormDisplay; -use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; -use Drupal\simpletest\WebTestBase; -use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait; - -/** - * Base class for tests. - */ -abstract class ParagraphsTestBase extends WebTestBase { - - use FieldUiTestTrait, ParagraphsCoreVersionUiTestTrait, ParagraphsTestBaseTrait; - - /** - * Drupal user object created by loginAsAdmin(). - * - * @var \Drupal\user\UserInterface - */ - protected $admin_user = NULL; - - /** - * List of permissions used by loginAsAdmin(). - * - * @var array - */ - protected $admin_permissions = []; - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = [ - 'node', - 'paragraphs', - 'field', - 'field_ui', - 'block', - 'paragraphs_test', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - // Place the breadcrumb, tested in fieldUIAddNewField(). - $this->drupalPlaceBlock('system_breadcrumb_block'); - $this->drupalPlaceBlock('local_tasks_block'); - $this->drupalPlaceBlock('local_actions_block'); - $this->drupalPlaceBlock('page_title_block'); - - $this->admin_permissions = [ - 'administer content types', - 'administer node fields', - 'administer paragraphs types', - 'administer node form display', - 'administer paragraph fields', - 'administer paragraph form display', - ]; - } - - /** - * Creates an user with admin permissions and log in. - * - * @param array $additional_permissions - * Additional permissions that will be granted to admin user. - * @param bool $reset_permissions - * Flag to determine if default admin permissions will be replaced by - * $additional_permissions. - * - * @return object - * Newly created and logged in user object. - */ - function loginAsAdmin($additional_permissions = [], $reset_permissions = FALSE) { - $permissions = $this->admin_permissions; - - if ($reset_permissions) { - $permissions = $additional_permissions; - } - elseif (!empty($additional_permissions)) { - $permissions = array_merge($permissions, $additional_permissions); - } - - $this->admin_user = $this->drupalCreateUser($permissions); - $this->drupalLogin($this->admin_user); - return $this->admin_user; - } - - /** - * Sets the Paragraphs widget add mode. - * - * @param string $content_type - * Content type name where to set the widget mode. - * @param string $paragraphs_field - * Paragraphs field to change the mode. - * @param string $mode - * Mode to be set. ('dropdown', 'select' or 'button'). - */ - protected function setAddMode($content_type, $paragraphs_field, $mode) { - $form_display = EntityFormDisplay::load('node.' . $content_type . '.default') - ->setComponent($paragraphs_field, [ - 'type' => 'entity_reference_paragraphs', - 'settings' => ['add_mode' => $mode] - ]); - $form_display->save(); - } - - /** - * Sets the allowed Paragraphs types that can be added. - * - * @param string $content_type - * Content type name that contains the paragraphs field. - * @param array $paragraphs_types - * Array of paragraphs types that will be modified. - * @param bool $selected - * Whether or not the paragraphs types will be enabled. - * @param string $paragraphs_field - * Paragraphs field name that does the reference. - */ - protected function setAllowedParagraphsTypes($content_type, $paragraphs_types, $selected, $paragraphs_field) { - $edit = []; - $this->drupalGet('admin/structure/types/manage/' . $content_type . '/fields/node.' . $content_type . '.' . $paragraphs_field); - foreach ($paragraphs_types as $paragraphs_type) { - $edit['settings[handler_settings][target_bundles_drag_drop][' . $paragraphs_type . '][enabled]'] = $selected; - } - $this->drupalPostForm(NULL, $edit, t('Save settings')); - } - - /** - * Sets the weight of a given Paragraphs type. - * - * @param string $content_type - * Content type name that contains the paragraphs field. - * @param string $paragraphs_type - * ID of Paragraph type that will be modified. - * @param int $weight - * Weight to be set. - * @param string $paragraphs_field - * Paragraphs field name that does the reference. - */ - protected function setParagraphsTypeWeight($content_type, $paragraphs_type, $weight, $paragraphs_field) { - $this->drupalGet('admin/structure/types/manage/' . $content_type . '/fields/node.' . $content_type . '.' . $paragraphs_field); - $edit['settings[handler_settings][target_bundles_drag_drop][' . $paragraphs_type . '][weight]'] = $weight; - $this->drupalPostForm(NULL, $edit, t('Save settings')); - } - - /** - * Sets the default paragraph type. - * - * @param $content_type - * Content type name that contains the paragraphs field. - * @param $paragraphs_name - * Paragraphs name. - * @param $paragraphs_field_name - * Paragraphs field name to be used. - * @param $default_type - * Default paragraph type which should be set. - */ - protected function setDefaultParagraphType($content_type, $paragraphs_name, $paragraphs_field_name, $default_type) { - $this->drupalGet('admin/structure/types/manage/' . $content_type . '/form-display'); - $this->drupalPostAjaxForm(NULL, [], $paragraphs_field_name); - $this->drupalPostForm(NULL, ['fields[' . $paragraphs_name . '][settings_edit_form][settings][default_paragraph_type]' => $default_type], t('Update')); - $this->drupalPostForm(NULL, [], t('Save')); - } - - /** - * Removes the default paragraph type. - * - * @param $content_type - * Content type name that contains the paragraphs field. - */ - protected function removeDefaultParagraphType($content_type) { - $this->drupalGet('node/add/' . $content_type); - $this->drupalPostForm(NULL, [], 'Remove'); - $this->drupalPostForm(NULL, [], 'Confirm removal'); - $this->assertNoText('No paragraphs added yet.'); - } - - /** - * Sets the Paragraphs widget display mode. - * - * @param string $content_type - * Content type name where to set the widget mode. - * @param string $paragraphs_field - * Paragraphs field to change the mode. - * @param string $mode - * Mode to be set. ('closed', 'preview' or 'open'). - * 'preview' is only allowed in the classic widget. Use - * setParagraphsWidgetSettings for the experimental widget, instead. - */ - protected function setParagraphsWidgetMode($content_type, $paragraphs_field, $mode) { - $this->drupalGet('admin/structure/types/manage/' . $content_type . '/form-display'); - $this->drupalPostAjaxForm(NULL, [], $paragraphs_field . '_settings_edit'); - $this->drupalPostForm(NULL, ['fields[' . $paragraphs_field . '][settings_edit_form][settings][edit_mode]' => $mode], t('Update')); - $this->drupalPostForm(NULL, [], 'Save'); - } - -} diff --git a/web/modules/paragraphs/src/Tests/Experimental/ParagraphsExperimentalTestBase.php b/web/modules/paragraphs/src/Tests/Experimental/ParagraphsExperimentalTestBase.php deleted file mode 100644 index 8542be2482e3b713612fe913b456d1e34409bdec..0000000000000000000000000000000000000000 --- a/web/modules/paragraphs/src/Tests/Experimental/ParagraphsExperimentalTestBase.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace Drupal\paragraphs\Tests\Experimental; - -use Drupal\Core\Entity\Entity\EntityFormDisplay; -use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; -use Drupal\paragraphs\Tests\Classic\ParagraphsTestBase; -use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait; - -/** - * Base class for tests. - */ -abstract class ParagraphsExperimentalTestBase extends ParagraphsTestBase { - - use FieldUiTestTrait, ParagraphsTestBaseTrait; - - /** - * Sets the Paragraphs widget add mode. - * - * @param string $content_type - * Content type name where to set the widget mode. - * @param string $paragraphs_field - * Paragraphs field to change the mode. - * @param string $mode - * Mode to be set. ('dropdown', 'select' or 'button'). - */ - protected function setAddMode($content_type, $paragraphs_field, $mode) { - $form_display = EntityFormDisplay::load('node.' . $content_type . '.default') - ->setComponent($paragraphs_field, [ - 'type' => 'paragraphs', - 'settings' => ['add_mode' => $mode] - ]); - $form_display->save(); - } - - /** - * Removes the default paragraph type. - * - * @param $content_type - * Content type name that contains the paragraphs field. - */ - protected function removeDefaultParagraphType($content_type) { - $this->drupalGet('node/add/' . $content_type); - $this->drupalPostForm(NULL, [], 'Remove'); - $this->assertNoText('No paragraphs added yet.'); - } - -} diff --git a/web/modules/paragraphs/tests/fixtures/update/README.txt b/web/modules/paragraphs/tests/fixtures/update/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..e5c6b4e08e0b691c50073149f867a16076a6013a --- /dev/null +++ b/web/modules/paragraphs/tests/fixtures/update/README.txt @@ -0,0 +1,16 @@ +Steps for creating the database dump: + +cd modules/paragraphs/ +git checkout 8.x-1.1 +cd ../../ +git checkout 8.8.0 +drush si -y standard --account-pass=admin +drush en -y paragraphs_demo +drush pm-uninstall -y search_api +mkdir -p modules/paragraphs/tests/fixtures/update +php ./core/scripts/db-tools.php dump-database-d8-mysql > modules/paragraphs/tests/fixtures/update/drupal-8.8.standard.paragraphs_demo.php +gzip modules/paragraphs/tests/fixtures/update/drupal-8.8.standard.paragraphs_demo.php +cd modules/paragraphs/ +git checkout 8.x-1.x + + diff --git a/web/modules/paragraphs/tests/modules/paragraphs_test/paragraphs_test.info.yml b/web/modules/paragraphs/tests/modules/paragraphs_test/paragraphs_test.info.yml index 094c654fc59f1ca3994acdfe82370a0c0d8e4609..575b23ffe89c0fe64404fbfb8082ee7b1547cc12 100644 --- a/web/modules/paragraphs/tests/modules/paragraphs_test/paragraphs_test.info.yml +++ b/web/modules/paragraphs/tests/modules/paragraphs_test/paragraphs_test.info.yml @@ -8,7 +8,7 @@ package: Paragraphs dependencies: - paragraphs:paragraphs -# Information added by Drupal.org packaging script on 2020-02-16 -version: '8.x-1.11' +# Information added by Drupal.org packaging script on 2020-05-21 +version: '8.x-1.12' project: 'paragraphs' -datestamp: 1581850832 +datestamp: 1590061337 diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAccessTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAccessTest.php index bc636570fcaae286198faf41d7b4ba858b9ce441..90530233e350c6bc7dcc229011e042289d9a71ab 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAccessTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAccessTest.php @@ -72,8 +72,8 @@ protected function setUp() { ]; $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); - $view_display = entity_get_display('paragraph', 'images', 'default') - ->setComponent('field_images_demo', ['settings' => ['image_style' => 'medium']]); + $view_display = \Drupal::service('entity_display.repository')->getViewDisplay('paragraph', 'images'); + $view_display->setComponent('field_images_demo', ['settings' => ['image_style' => 'medium']]); $view_display->save(); } @@ -144,7 +144,7 @@ public function testParagraphAccessCheck() { $image_style = ImageStyle::load('medium'); $img1_url = $image_style->buildUrl('private://' . date('Y-m') . '/privateImage.jpg'); $image_url = file_url_transform_relative($img1_url); - $this->assertRaw($image_url, 'Image was found in preview'); + $this->assertSession()->responseContains($image_url); $this->clickLink(t('Back to content editing')); $this->drupalPostForm(NULL, [], t('Save')); @@ -153,10 +153,10 @@ public function testParagraphAccessCheck() { $this->drupalGet('node/' . $node->id()); // Check the text and image after publish. - $this->assertRaw($image_url, 'Image was found in content'); + $this->assertSession()->responseContains($image_url); $this->drupalGet($img1_url); - $this->assertResponse(200, 'Image could be downloaded'); + $this->assertSession()->statusCodeEquals(200); // Logout to become anonymous. $this->drupalLogout(); @@ -166,17 +166,17 @@ public function testParagraphAccessCheck() { $img_url = $image_style->buildUrl('private://' . date('Y-m') . '/privateImage2.jpg'); $image_url = file_url_transform_relative($img_url); // Check the text and image after publish. Anonymous should not see content. - $this->assertNoRaw($image_url, 'Image was not found in content'); + $this->assertSession()->responseNotContains($image_url); $this->drupalGet($img_url); - $this->assertResponse(403, 'Image could not be downloaded'); + $this->assertSession()->statusCodeEquals(403); // Login as admin with no delete permissions. $this->loginAsAdmin($admin_user); // Create a new demo node. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertText('Text'); + $this->assertSession()->pageTextContains('Text'); $edit = [ 'title[0][value]' => 'delete_permissions', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Test', @@ -191,6 +191,6 @@ public function testParagraphAccessCheck() { $this->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_confirm_remove'); $this->drupalPostForm(NULL, [], t('Save')); $node = $this->getNodeByTitle('delete_permissions'); - $this->assertUrl('node/' . $node->id()); + $this->assertSession()->addressEquals('node/' . $node->id()); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAddModesTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAddModesTest.php index e934a779788c492969ac6ac186349a98387ca426..4829e60e246062ff69b5f1e149c8d24c0ebb110d 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAddModesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAddModesTest.php @@ -23,10 +23,10 @@ public function testNoDefaultValue() { $this->clickLink(t('Edit')); // Check that the current field does not allow to add default values. - $this->assertText('No widget available for: paragraphs_field.'); + $this->assertSession()->pageTextContains('No widget available for: paragraphs_field.'); $this->drupalPostForm(NULL, [], t('Save settings')); - $this->assertText('Saved paragraphs_field configuration.'); - $this->assertResponse(200); + $this->assertSession()->pageTextContains('Saved paragraphs_field configuration.'); + $this->assertSession()->statusCodeEquals(200); } /** @@ -40,7 +40,7 @@ public function testEmptyAllowedTypes() { $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields'); $this->clickLink(t('Edit')); $this->drupalPostForm(NULL, [], t('Save settings')); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); } /** @@ -119,12 +119,12 @@ public function testSelectMode() { */ protected function assertAddButtons($options) { $this->drupalGet('node/add/paragraphed_test'); - $buttons = $this->xpath('//input[@class="field-add-more-submit button js-form-submit form-submit"]'); + $buttons = $this->xpath('//input[@class="field-add-more-submit button--small button js-form-submit form-submit"]'); // Check if the buttons are in the same order as the given array. foreach ($buttons as $key => $button) { - $this->assertEqual($button->getValue(), $options[$key]); + $this->assertEquals($button->getValue(), $options[$key]); } - $this->assertTrue(count($buttons) == count($options), 'The amount of drop down options matches with the given array'); + $this->assertEquals(count($buttons), count($options), 'The amount of drop down options matches with the given array'); } /** @@ -140,10 +140,10 @@ protected function assertSelectOptions($options, $paragraphs_field) { $buttons = $this->xpath('//*[@name="' . $paragraphs_field . '[add_more][add_more_select]"]/option'); // Check if the options are in the same order as the given array. foreach ($buttons as $key => $button) { - $this->assertEqual($button->getValue(), $options[$key]); + $this->assertEquals($button->getValue(), $options[$key]); } - $this->assertTrue(count($buttons) == count($options), 'The amount of select options matches with the given array'); - $this->assertNotEqual($this->xpath('//*[@name="' . $paragraphs_field .'_add_more"]'), [], 'The add button is displayed'); + $this->assertEquals(count($buttons), count($options), 'The amount of select options matches with the given array'); + $this->assertNotEquals($this->xpath('//*[@name="' . $paragraphs_field .'_add_more"]'), [], 'The add button is displayed'); } /** @@ -173,7 +173,7 @@ public function testSettingDefaultParagraphType() { // Check if default paragraph type is showing. $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Text + Image'); + $this->assertSession()->pageTextContains('Text + Image'); $this->removeDefaultParagraphType('paragraphed_test'); // Disable text_image as default paragraph type. @@ -181,7 +181,7 @@ public function testSettingDefaultParagraphType() { // Check if is Text + Image is added as default paragraph type. $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('No Paragraph added yet.'); + $this->assertSession()->pageTextContains('No Paragraph added yet.'); // Check if default type is created only for new host $this->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', 'text_image'); @@ -189,7 +189,7 @@ public function testSettingDefaultParagraphType() { $edit = ['title[0][value]' => 'New Host']; $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/1/edit'); - $this->assertText('No Paragraph added yet.'); + $this->assertSession()->pageTextContains('No Paragraph added yet.'); } /** @@ -213,12 +213,12 @@ public function testDefaultParagraphTypeWithSingleType() { // Check that when only one paragraph type is allowed in a content type, // one instance is automatically added in the 'Add content' dialogue. $this->drupalGet('node/add/paragraphed_test'); - $this->assertNoText('No Paragraph added yet.'); + $this->assertSession()->pageTextNotContains('No Paragraph added yet.'); // Check that no paragraph type is automatically added, if the defaut // setting was set to '- None -'. $this->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', '_none'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('No Paragraph added yet.'); + $this->assertSession()->pageTextContains('No Paragraph added yet.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAdministrationTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAdministrationTest.php index 08dc9184b1f321119e2862ab56ea22a6d716f61b..30e8ba6496e04afc5f17e92e6d33ecbb93b2ab5c 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAdministrationTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsAdministrationTest.php @@ -46,7 +46,7 @@ public function testParagraphsRevisions() { $this->addParagraphsType('text'); // Create field types for the text. static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); // Create an article with paragraphs field. static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array( @@ -100,25 +100,25 @@ public function testParagraphsRevisions() { $this->countRevisions($node, $paragraph1, $paragraph2, 2); // Assert the paragraphs have been changed. - $this->assertNoText('Foo Bar 1'); - $this->assertText('Test text 2'); - $this->assertText('Foo Bar 2'); - $this->assertText('TEST TITLE'); + $this->assertSession()->pageTextNotContains('Foo Bar 1'); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->pageTextContains('Foo Bar 2'); + $this->assertSession()->pageTextContains('TEST TITLE'); // Check out the revisions page and assert there are 2 revisions. $this->drupalGet('node/' . $node->id() . '/revisions'); $rows = $this->xpath('//tbody/tr'); // Make sure two revisions available. - $this->assertEqual(count($rows), 2); + $this->assertEquals(count($rows), 2); // Revert to the old version. $this->clickLink(t('Revert')); $this->drupalPostForm(NULL, [], t('Revert')); $this->drupalGet('node/' . $node->id()); // Assert the node has been reverted. - $this->assertNoText('Foo Bar 2'); - $this->assertText('Test text 2'); - $this->assertText('Foo Bar 1'); - $this->assertText('TEST TITEL'); + $this->assertSession()->pageTextNotContains('Foo Bar 2'); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->pageTextContains('Foo Bar 1'); + $this->assertSession()->pageTextContains('TEST TITEL'); } @@ -141,7 +141,7 @@ public function testParagraphsCreation() { // Assert suggested 'Add a paragraph type' link when there is no type yet. $this->drupalGet('admin/structure/paragraphs_type'); - $this->assertText('There are no Paragraphs types yet.'); + $this->assertSession()->pageTextContains('There are no Paragraphs types yet.'); $this->drupalGet('admin/structure/types/manage/paragraphs/fields/add-field'); $edit = [ 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph', @@ -150,22 +150,22 @@ public function testParagraphsCreation() { ]; $this->drupalPostForm(NULL, $edit, 'Save and continue'); $this->drupalPostForm(NULL, [], 'Save field settings'); - $this->assertLinkByHref('admin/structure/paragraphs_type/add'); + $this->assertSession()->linkByHrefExists('admin/structure/paragraphs_type/add'); $this->clickLink('here'); - $this->assertUrl('admin/structure/paragraphs_type/add'); + $this->assertSession()->addressEquals('admin/structure/paragraphs_type/add'); $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Add paragraph type')); - $this->assertTitle('Add Paragraphs type | Drupal'); + $this->assertSession()->titleEquals('Add Paragraphs type | Drupal'); // Create paragraph type text + image. $this->addParagraphsType('text_image'); $this->drupalGet('admin/structure/paragraphs_type/text_image'); - $this->assertTitle('Edit text_image paragraph type | Drupal'); + $this->assertSession()->titleEquals('Edit text_image paragraph type | Drupal'); // Create field types for text and image. static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text', 'Text', 'text_long', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image', 'Image', 'image', array(), array('settings[alt_field_required]' => FALSE)); - $this->assertText('Saved Image configuration.'); + $this->assertSession()->pageTextContains('Saved Image configuration.'); // Create paragraph type Nested test. $this->addParagraphsType('nested_test'); @@ -185,21 +185,21 @@ public function testParagraphsCreation() { $this->addParagraphsType('image'); // Create field types for image. static::fieldUIAddNewField('admin/structure/paragraphs_type/image', 'image_only', 'Image only', 'image', array(), array()); - $this->assertText('Saved Image only configuration.'); + $this->assertSession()->pageTextContains('Saved Image only configuration.'); $this->drupalGet('admin/structure/paragraphs_type'); $rows = $this->xpath('//tbody/tr'); // Make sure 2 types are available with their label. - $this->assertEqual(count($rows), 3); - $this->assertText('text_image'); - $this->assertText('image'); + $this->assertEquals(count($rows), 3); + $this->assertSession()->pageTextContains('text_image'); + $this->assertSession()->pageTextContains('image'); // Make sure there is an edit link for each type. $this->clickLink(t('Edit')); // Make sure the field UI appears. - $this->assertLink('Manage fields'); - $this->assertLink('Manage form display'); - $this->assertLink('Manage display'); - $this->assertTitle('Edit image paragraph type | Drupal'); + $this->assertSession()->linkExists('Manage fields'); + $this->assertSession()->linkExists('Manage form display'); + $this->assertSession()->linkExists('Manage display'); + $this->assertSession()->titleEquals('Edit image paragraph type | Drupal'); // Test for "Add mode" setting. $this->drupalGet('admin/structure/types/manage/article/form-display'); @@ -214,17 +214,18 @@ public function testParagraphsCreation() { // Check if the setting is stored. $this->drupalGet('admin/structure/types/manage/article/form-display'); - $this->assertText('Add mode: Buttons', 'Checking the settings value.'); + $this->assertSession()->pageTextContains('Add mode: Buttons', 'Checking the settings value.'); $this->drupalPostForm(NULL, array(), $field_name . "_settings_edit"); // Assert the 'Buttons' option is selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.'); + $add_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button'); + $this->assertTrue($add_mode_option->hasAttribute('selected'), 'Updated value correctly.'); // Add two Text + Image paragraphs in article. $this->drupalGet('node/add/article'); // Checking changes on article. - $this->assertRaw('<div class="paragraphs-dropbutton-wrapper"><input', 'Updated value in article.'); + $this->assertSession()->responseContains('<div class="paragraphs-dropbutton-wrapper"><input', 'Updated value in article.'); $this->drupalPostForm(NULL, array(), 'field_paragraphs_text_image_add_more'); $this->drupalPostForm(NULL, array(), 'field_paragraphs_text_image_add_more'); @@ -241,7 +242,7 @@ public function testParagraphsCreation() { 'files[field_paragraphs_1_subform_field_image_0]' => $file_system->realpath($files[1]->uri), ); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('article Test article has been created.'); + $this->assertSession()->pageTextContains('article Test article has been created.'); $node = $this->drupalGetNodeByTitle('Test article'); $img1_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/' . $files[0]->filename)); @@ -252,10 +253,10 @@ public function testParagraphsCreation() { $img2_mime = \Drupal::service('file.mime_type.guesser')->guess($files[1]->uri); // Check the text and image after publish. - $this->assertText('Test text 1'); - $this->assertRaw('<img src="' . file_url_transform_relative($img1_url)); - $this->assertText('Test text 2'); - $this->assertRaw('<img src="' . file_url_transform_relative($img2_url)); + $this->assertSession()->pageTextContains('Test text 1'); + $this->assertSession()->responseContains('<img src="' . file_url_transform_relative($img1_url)); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->responseContains('<img src="' . file_url_transform_relative($img2_url)); // Tests for "Edit mode" settings. // Test for closed setting. @@ -266,79 +267,81 @@ public function testParagraphsCreation() { $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'); $this->drupalPostForm(NULL, $edit, t('Save')); // Check if the setting is stored. - $this->assertText('Edit mode: Closed', 'Checking the settings value.'); + $this->assertSession()->pageTextContains('Edit mode: Closed', 'Checking the settings value.'); $this->drupalPostForm(NULL, array(), "field_paragraphs_settings_edit"); // Assert the 'Closed' option is selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Updated value correctly.'); + $edit_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed'); + $this->assertTrue($edit_mode_option->hasAttribute('selected'), 'Updated value correctly.'); $this->drupalGet('node/1/edit'); // The textareas for paragraphs should not be visible. - $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertRaw('<span class="summary-content">Test text 1</span>, <span class="summary-content">' . $files[0]->filename); - $this->assertRaw('<span class="summary-content">Test text 2</span>, <span class="summary-content">' . $files[1]->filename); + $this->assertSession()->responseNotContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseContains('<span class="summary-content">Test text 1</span>, <span class="summary-content">' . $files[0]->filename); + $this->assertSession()->responseContains('<span class="summary-content">Test text 2</span>, <span class="summary-content">' . $files[1]->filename); // Test for preview option. $this->drupalGet('admin/structure/types/manage/article/form-display'); $this->drupalPostForm(NULL, array(), "field_paragraphs_settings_edit"); $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'preview'); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Edit mode: Preview', 'Checking the settings value.'); + $this->assertSession()->pageTextContains('Edit mode: Preview', 'Checking the settings value.'); $this->drupalGet('node/1/edit'); // The texts in the paragraphs should be visible. - $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertText('Test text 1'); - $this->assertText('Test text 2'); + $this->assertSession()->responseNotContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->pageTextContains('Test text 1'); + $this->assertSession()->pageTextContains('Test text 2'); // Test for open option. $this->drupalGet('admin/structure/types/manage/article/form-display'); $this->drupalPostForm(NULL, array(), "field_paragraphs_settings_edit"); // Assert the 'Preview' option is selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'preview', 'Updated value correctly.'); + $edit_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'preview'); + $this->assertTrue($edit_mode_option->hasAttribute('selected'), 'Updated value correctly.'); // Restore the value to Open for next test. $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'open'); $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/1/edit'); // The textareas for paragraphs should be visible. - $this->assertRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertRaw('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseContains('field_paragraphs[1][subform][field_text][0][value]'); $paragraphs = Paragraph::loadMultiple(); - $this->assertEqual(count($paragraphs), 2, 'Two paragraphs in article'); + $this->assertEquals(count($paragraphs), 2, 'Two paragraphs in article'); // Check article edit page. $this->drupalGet('node/' . $node->id() . '/edit'); // Check both paragraphs in edit page. - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1'); - $this->assertRaw('<a href="' . $img1_url . '" type="' . $img1_mime . '; length=' . $img1_size . '">' . $files[0]->filename . '</a>'); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2'); - $this->assertRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1'); + $this->assertSession()->responseContains('<a href="' . $img1_url . '" type="' . $img1_mime . '; length=' . $img1_size . '">' . $files[0]->filename . '</a>'); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2'); + $this->assertSession()->responseContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Remove 2nd paragraph. $this->getSession()->getPage()->find('css', '[name="field_paragraphs_1_remove"]')->press(); // Confirm the removal. $this->drupalPostForm(NULL, [], t('Confirm removal')); - $this->assertNoField('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->fieldNotExists('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Assert the paragraph is not deleted unless the user saves the node. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Remove the second paragraph. $this->getSession()->getPage()->find('css', '[name="field_paragraphs_1_remove"]')->press(); // Confirm the removal. $this->drupalPostForm(NULL, [], t('Confirm removal')); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); $edit = [ 'field_paragraphs[0][subform][field_image][0][alt]' => 'test_alt', ]; $this->drupalPostForm(NULL, $edit, t('Save')); // Assert the paragraph is deleted after the user saves the node. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Delete the node. $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertText('Test article has been deleted.'); + $this->assertSession()->pageTextContains('Test article has been deleted.'); // Check if the publish/unpublish option works. $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display'); @@ -350,19 +353,19 @@ public function testParagraphsCreation() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/add/article'); $this->drupalPostForm(NULL, NULL, t('Add text_image')); - $this->assertRaw('edit-field-paragraphs-0-subform-status-value'); + $this->assertSession()->responseContains('edit-field-paragraphs-0-subform-status-value'); $edit = [ 'title[0][value]' => 'Example publish/unpublish', 'field_paragraphs[0][subform][field_text][0][value]' => 'Example published and unpublished', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('Example published and unpublished')); + $this->assertSession()->pageTextContains(t('Example published and unpublished')); $this->clickLink(t('Edit')); $edit = [ 'field_paragraphs[0][subform][status][value]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertNoText(t('Example published and unpublished')); + $this->assertSession()->pageTextNotContains(t('Example published and unpublished')); // Set the fields as required. $this->drupalGet('admin/structure/types/manage/article/fields'); @@ -380,7 +383,7 @@ public function testParagraphsCreation() { ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_subform_field_paragraphs_add_more'); // Test the new field is displayed. - $this->assertFieldByName('files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]'); + $this->assertSession()->fieldExists('files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]'); // Add an image to the required field. $edit = array( @@ -392,14 +395,14 @@ public function testParagraphsCreation() { 'field_paragraphs[0][subform][field_paragraphs][0][subform][field_image_only][0][alt]' => 'Alternative_text', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('test required has been created.'); - $this->assertNoRaw('This value should not be null.'); + $this->assertSession()->pageTextContains('test required has been created.'); + $this->assertSession()->responseNotContains('This value should not be null.'); // Test that unsupported widgets are not displayed. $this->drupalGet('admin/structure/types/manage/article/form-display'); $select = $this->xpath('//*[@id="edit-fields-field-paragraphs-type"]')[0]; $this->assertCount(2, $select->findAll('css', 'option')); - $this->assertRaw('value="entity_reference_paragraphs" selected="selected"'); + $this->assertSession()->responseContains('value="entity_reference_paragraphs" selected="selected"'); // Check that Paragraphs is not displayed as an entity_reference field // reference option. @@ -410,7 +413,7 @@ public function testParagraphsCreation() { 'field_name' => 'unsupportedfield', ]; $this->drupalPostForm(NULL, $edit, t('Save and continue')); - $this->assertNoOption('edit-settings-target-type', 'paragraph'); + $this->assertSession()->optionNotExists('edit-settings-target-type', 'paragraph'); // Test that all Paragraph types can be referenced if none is selected. $this->addParagraphsType('nested_double_test'); @@ -434,8 +437,8 @@ public function testParagraphsCreation() { 'title[0][value]' => 'Nested twins', ); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Nested twins has been created.'); - $this->assertNoText('This entity (paragraph: ) cannot be referenced.'); + $this->assertSession()->pageTextContains('Nested twins has been created.'); + $this->assertSession()->pageTextNotContains('This entity (paragraph: ) cannot be referenced.'); // Set the fields as not required. $this->drupalGet('admin/structure/types/manage/article/fields'); @@ -473,33 +476,33 @@ public function testParagraphsCreation() { $this->clickLink(t('Edit')); // Since we have validation error (reference to deleted node), paragraph is // by default in edit mode. - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); // Assert the validation error message. - $this->assertText('The referenced entity (node: 4) does not exist'); + $this->assertSession()->pageTextContains('The referenced entity (node: 4) does not exist'); // Triggering unrelated button, assert that error message is still present. $this->drupalPostForm(NULL, [], t('Add another item')); - $this->assertText('The referenced entity (node: 4) does not exist'); - $this->assertText('Entity reference (value 1) field is required.'); + $this->assertSession()->pageTextContains('The referenced entity (node: 4) does not exist'); + $this->assertSession()->pageTextContains('Entity reference (value 1) field is required.'); // Try to collapse with an invalid reference. $this->drupalPostForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo'], 'field_paragraphs_0_collapse'); // Paragraph should be still in edit mode. - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); $this->drupalPostForm(NULL, [], t('Add another item')); // Assert the validation message. - $this->assertText('There are no entities matching "foo".'); + $this->assertSession()->pageTextContains('There are no entities matching "foo".'); // Attempt to remove the Paragraph. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); $elements = $this->xpath('//*[@name="field_paragraphs_0_confirm_remove"]'); - $this->assertTrue(!empty($elements), "'Confirm removal' button appears."); + $this->assertNotEmpty($elements, "'Confirm removal' button appears."); // Restore the Paragraph and fix the broken reference. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_restore'); $node = $this->drupalGetNodeByTitle('Example publish/unpublish'); $edit = ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => $node->label() . ' (' . $node->id() . ')']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('choke test has been updated.'); - $this->assertLink('Example publish/unpublish'); + $this->assertSession()->pageTextContains('choke test has been updated.'); + $this->assertSession()->linkExists('Example publish/unpublish'); // Delete the new referenced node. $node->delete(); @@ -514,24 +517,24 @@ public function testParagraphsCreation() { // Try to save with an invalid reference. $edit = ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('There are no entities matching "foo".'); + $this->assertSession()->pageTextContains('There are no entities matching "foo".'); // Remove the Paragraph and save the node. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); $elements = $this->xpath('//*[@name="field_paragraphs_0_confirm_remove"]'); - $this->assertTrue(!empty($elements), "'Confirm removal' button appears."); + $this->assertNotEmpty($elements, "'Confirm removal' button appears."); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_confirm_remove'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('choke test has been updated.'); + $this->assertSession()->pageTextContains('choke test has been updated.'); // Verify that the text displayed is correct when no paragraph has been // added yet. $this->drupalGet('node/add/article'); - $this->assertText('No Paragraph added yet.'); + $this->assertSession()->pageTextContains('No Paragraph added yet.'); $this->drupalGet('admin/content/files'); $this->clickLink('1 place'); $label = $this->xpath('//tbody/tr/td[1]'); - $this->assertEqual(trim(htmlspecialchars_decode(strip_tags($label[0]->getText()))), 'test required > field_paragraphs > Paragraphs'); + $this->assertEquals(trim(htmlspecialchars_decode(strip_tags($label[0]->getText()))), 'test required > field_paragraphs > Paragraphs'); } /** @@ -539,9 +542,9 @@ public function testParagraphsCreation() { */ private function countRevisions($node, $paragraph1, $paragraph2, $revisions_count) { $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute(); - $this->assertEqual($node_revisions_count, $revisions_count); - $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count); - $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count); + $this->assertEquals($node_revisions_count, $revisions_count); + $this->assertEquals(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count); + $this->assertEquals(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsClassicContentModerationTranslationsTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsClassicContentModerationTranslationsTest.php index c8be65e788c3686654e49b534cf46305b0973e85..0d42db68a7861d39f216711882c52c2f7ec4f1ff 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsClassicContentModerationTranslationsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsClassicContentModerationTranslationsTest.php @@ -295,7 +295,9 @@ public function testTranslatableContentEntities() { $assert_session->pageTextContains('Draft paragraph container text EN'); $assert_session->pageTextContains('Untranslatable container draft text'); - entity_get_form_display('node', 'paragraphed_test', 'default') + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + $display_repository->getFormDisplay('node', 'paragraphed_test') ->setComponent('field_paragraphs', [ 'type' => 'entity_reference_paragraphs', 'settings' => [ @@ -306,7 +308,7 @@ public function testTranslatableContentEntities() { ], ]) ->save(); - entity_get_form_display('paragraph', 'container', 'default') + $display_repository->getFormDisplay('paragraph', 'container') ->setComponent('field_paragraphs', [ 'type' => 'entity_reference_paragraphs', 'settings' => [ diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsConfigTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsConfigTest.php index fbaa9db07cc1f57ba80fe9af198e293e24c14dc8..e0cfb8f994dbada77b32c042ae02895ebfc542bd 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsConfigTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsConfigTest.php @@ -61,7 +61,7 @@ public function testFieldTranslationDisabled() { $this->clickLink(t('Add')); // Save the translation. $this->drupalPostForm(NULL, [], t('Save (this translation)')); - $this->assertText('paragraphed_test paragraphed_title has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_test paragraphed_title has been updated.'); } /** @@ -77,14 +77,14 @@ public function testContentTranslationForm() { // Check warning message is displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs'); // Check error message is not displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--error'); // Add a second language. ConfigurableLanguage::create(['id' => 'de'])->save(); @@ -99,12 +99,12 @@ public function testContentTranslationForm() { // Check error message is still not displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--error'); // Check content type field management warning. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field'); - $this->assertText('Paragraphs fields do not support translation.'); + $this->assertSession()->pageTextContains('Paragraphs fields do not support translation.'); // Make the paragraphs field translatable. $edit = [ @@ -116,8 +116,8 @@ public function testContentTranslationForm() { // Check content type field management error. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field'); - $this->assertText('Paragraphs fields do not support translation.'); - $this->assertRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('Paragraphs fields do not support translation.'); + $this->assertSession()->responseContains('<div class="messages messages--error'); // Check a not paragraphs translatable field does not display the message. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field'); @@ -128,8 +128,8 @@ public function testContentTranslationForm() { ]; $this->drupalPostForm(NULL, $edit, t('Save and continue')); $this->drupalPostForm(NULL, [], t('Save field settings')); - $this->assertNoText('Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--warning'); + $this->assertSession()->pageTextNotContains('Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--warning'); } /** @@ -149,19 +149,19 @@ public function testRequiredParagraphsField() { 'required' => TRUE, ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); // Assert that the field is displayed in the form as required. $this->drupalGet('node/add/paragraphed_test'); - $this->assertRaw('<strong class="form-required" data-drupal-selector="edit-paragraphs-title">'); + $this->assertSession()->responseContains('<strong class="form-required" data-drupal-selector="edit-paragraphs-title">'); $edit = [ 'title[0][value]' => 'test_title', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphs field is required.'); + $this->assertSession()->pageTextContains('paragraphs field is required.'); $this->drupalPostForm(NULL, [], 'paragraphs_paragraph_type_test_add_more'); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test test_title has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test test_title has been created.'); } /** @@ -187,8 +187,8 @@ public function testAvoidUsingParagraphsWithWrongEntity() { 'settings[handler_settings][target_bundles][article]' => 'article', ]); $this->drupalGet('admin/structure/types/manage/article/form-display'); - $this->assertNoOption('edit-fields-field-node-reference-type', 'entity_reference_paragraphs'); - $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs'); + $this->assertSession()->optionNotExists('edit-fields-field-node-reference-type', 'entity_reference_paragraphs'); + $this->assertSession()->optionNotExists('edit-fields-field-node-reference-type', 'paragraphs'); } /** @@ -207,11 +207,11 @@ public function testIncludedParagraphTypes() { 'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1, ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Add paragraph_type_test'); - $this->assertNoText('Add text'); + $this->assertSession()->pageTextContains('Add paragraph_type_test'); + $this->assertSession()->pageTextNotContains('Add text'); } /** @@ -230,11 +230,11 @@ public function testExcludedParagraphTypes() { 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1, ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Add paragraph_type_test'); - $this->assertNoText('Add text'); + $this->assertSession()->pageTextContains('Add paragraph_type_test'); + $this->assertSession()->pageTextNotContains('Add text'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsContactTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsContactTest.php index 58a26442e34fcb68acdff3ebf833f09a8f5dbafb..cc19084ea2608385d03119f41a00c654a068d142 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsContactTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsContactTest.php @@ -42,8 +42,8 @@ public function testContactForm() { $this->drupalGet('contact/test_contact_form'); $this->drupalPostForm(NULL, [], 'paragraphs_paragraphs_contact_add_more'); // Check that the paragraph is displayed. - $this->assertText('paragraphs_contact'); + $this->assertSession()->pageTextContains('paragraphs_contact'); $this->drupalPostForm(NULL, [], 'paragraphs_0_remove'); - $this->assertText('Deleted Paragraph: paragraphs_contact'); + $this->assertSession()->pageTextContains('Deleted Paragraph: paragraphs_contact'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEditModesTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEditModesTest.php index e1529bb1cec3391786102327bb196e3297ffc552..724a35ea99cf0d6c86931fd59be3d65c39bf8c69 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEditModesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEditModesTest.php @@ -60,8 +60,8 @@ public function testCollapsedSummary() { // Assert the summary is correctly generated. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">' . $files[0]->filename . '</span>, <span class="summary-content">text_summary</span>'); - $this->assertRaw('<span class="summary-content">Title example'); + $this->assertSession()->responseContains('<span class="summary-content">' . $files[0]->filename . '</span>, <span class="summary-content">text_summary</span>'); + $this->assertSession()->responseContains('<span class="summary-content">Title example'); // Edit and remove alternative text. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); @@ -70,7 +70,7 @@ public function testCollapsedSummary() { ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); // Assert the summary is correctly generated. - $this->assertRaw('<span class="summary-content">alternative_text_summary</span>, <span class="summary-content">text_summary</span>'); + $this->assertSession()->responseContains('<span class="summary-content">alternative_text_summary</span>, <span class="summary-content">text_summary</span>'); // Remove image. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); @@ -79,7 +79,7 @@ public function testCollapsedSummary() { // Assert the summary is correctly generated. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">text_summary'); + $this->assertSession()->responseContains('<span class="summary-content">text_summary'); // Add a Block Paragraphs type. $this->addParagraphsType('block_paragraph'); @@ -94,7 +94,7 @@ public function testCollapsedSummary() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">Breadcrumbs'); + $this->assertSession()->responseContains('<span class="summary-content">Breadcrumbs'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEntityTranslationWithNonTranslatableParagraphs.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEntityTranslationWithNonTranslatableParagraphs.php index 778866561cf87fa27dad71c1632f48afb7765e90..2a0e2edb5dea20146e7823d430644e14eb47d45f 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEntityTranslationWithNonTranslatableParagraphs.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsEntityTranslationWithNonTranslatableParagraphs.php @@ -85,25 +85,25 @@ public function testParagraphsIEFTranslation() { $this->clickLink(t('Translate')); $this->clickLink(t('Add'), 1); // Make sure that the original paragraph text is displayed. - $this->assertText('Title English'); + $this->assertSession()->pageTextContains('Title English'); $edit = array( 'title[0][value]' => 'Title French', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('article Title French has been updated.'); + $this->assertSession()->pageTextContains('article Title French has been updated.'); // Add german translation. $this->clickLink(t('Translate')); $this->clickLink(t('Add')); // Make sure that the original paragraph text is displayed. - $this->assertText('Title English'); + $this->assertSession()->pageTextContains('Title English'); $edit = array( 'title[0][value]' => 'Title German', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('article Title German has been updated.'); + $this->assertSession()->pageTextContains('article Title German has been updated.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsFieldGroupTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsFieldGroupTest.php index 5a564815fb3b2319ddb9adaade97e5629ea67d9b..b7e5d30dd496c803a6a9c1c887a438508c2bc522 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsFieldGroupTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsFieldGroupTest.php @@ -58,8 +58,8 @@ public function testFieldGroup() { $this->drupalPostForm('node/add/' . $content_type, [], 'field_paragraphs_paragraph_type_test_add_more'); // Test if the new field group is displayed. - $this->assertText('field_group'); - $this->assertFieldByXPath("//fieldset", NULL, t('Fieldset present')); + $this->assertSession()->pageTextContains('field_group'); + $this->assertSession()->elementExists('css', 'fieldset'); // Save the node. $edit = [ diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsPreviewTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsPreviewTest.php index e2c2ec782a2c8a751e369e7bb18f2cc6c0eb58df..c147aed92fad531ab48cef209583bbbe9cac7151 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsPreviewTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsPreviewTest.php @@ -35,7 +35,7 @@ public function testParagraphsPreview() { $this->addParagraphsType('text'); // Create field types for the text. $this->fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); $test_text_1 = 'dummy_preview_text_1'; $test_text_2 = 'dummy_preview_text_2'; @@ -50,17 +50,19 @@ public function testParagraphsPreview() { // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); // Check if the text is displayed. - $this->assertRaw($test_text_1); + $this->assertSession()->responseContains($test_text_1); // Check that the parent is set correctly on all paragraphs. - $this->assertNoText('Parent: //'); - $this->assertNoUniqueText('Parent: node//field_paragraphs'); + $this->assertSession()->pageTextNotContains('Parent: //'); + $page_text = $this->getSession()->getPage()->getText(); + $nr_found = substr_count($page_text, 'Parent: node//field_paragraphs'); + $this->assertGreaterThan(1, $nr_found); // Go back to the editing form. $this->clickLink('Back to content editing'); $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0]; - $this->assertEqual($paragraph_1->getValue(), $test_text_1); + $this->assertEquals($paragraph_1->getValue(), $test_text_1); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -71,8 +73,8 @@ public function testParagraphsPreview() { ]; // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); - $this->assertRaw($test_text_1); - $this->assertRaw($test_text_2); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($test_text_2); // Go back to the editing form. $this->clickLink('Back to content editing'); @@ -83,24 +85,26 @@ public function testParagraphsPreview() { ]; // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); - $this->assertRaw($test_text_1); - $this->assertRaw($new_test_text_2); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($new_test_text_2); // Check that the parent is set correctly on all paragraphs. - $this->assertNoText('Parent: //'); - $this->assertNoUniqueText('Parent: node/1/field_paragraphs'); + $this->assertSession()->pageTextNotContains('Parent: //'); + $page_text = $this->getSession()->getPage()->getText(); + $nr_found = substr_count($page_text, 'Parent: node/1/field_paragraphs'); + $this->assertGreaterThan(1, $nr_found); // Go back to the editing form. $this->clickLink('Back to content editing'); $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0]; $paragraph_2 = $this->xpath('//*[@id="edit-field-paragraphs-1-subform-field-text-0-value"]')[0]; - $this->assertEqual($paragraph_1->getValue(), $test_text_1); - $this->assertEqual($paragraph_2->getValue(), $new_test_text_2); + $this->assertEquals($paragraph_1->getValue(), $test_text_1); + $this->assertEquals($paragraph_2->getValue(), $new_test_text_2); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertRaw($test_text_1); - $this->assertRaw($new_test_text_2); - $this->assertRaw('Page_title'); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($new_test_text_2); + $this->assertSession()->responseContains('Page_title'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsSummaryFormatterTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsSummaryFormatterTest.php index 3790ca6a11f8aa033324ec901320ace2ac2cb8e2..e7709e35509e19eb5fd0522f39913247c9051a31 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsSummaryFormatterTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsSummaryFormatterTest.php @@ -62,8 +62,8 @@ public function testParagraphsSummaryFormatter() { $this->drupalPostForm(NULL, $edit, t('Save')); // Assert the summary is correctly generated. - $this->assertText($this->admin_user->label()); - $this->assertText('Title example'); + $this->assertSession()->pageTextContains($this->admin_user->label()); + $this->assertSession()->pageTextContains('Title example'); } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTestBase.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTestBase.php index f053c3d9034ba4a4cb3f529d41b955a9a10e3439..10c2c6424e09b3b8549fcf69cd521514cec9b30d 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTestBase.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTestBase.php @@ -183,7 +183,7 @@ protected function removeDefaultParagraphType($content_type) { $this->drupalGet('node/add/' . $content_type); $this->drupalPostForm(NULL, [], 'Remove'); $this->drupalPostForm(NULL, [], 'Confirm removal'); - $this->assertNoText('No paragraphs added yet.'); + $this->assertSession()->pageTextNotContains('No paragraphs added yet.'); } /** diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTranslationTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTranslationTest.php index 1cd2d009c2cd7d1f9147dd969f4f9357215a8b10..ff7c84bd600d2c14a5e9feeb4950b0d0fda61f2a 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTranslationTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTranslationTest.php @@ -112,11 +112,11 @@ public function testParagraphTranslation() { $this->drupalGet('admin/config/regional/content-language'); // Check the settings are saved correctly. - $this->assertFieldChecked('edit-entity-types-paragraph'); - $this->assertFieldChecked('edit-settings-node-paragraphed-content-demo-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-text-image-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-alt'); - $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-title'); + $this->assertSession()->checkboxChecked('edit-entity-types-paragraph'); + $this->assertSession()->checkboxChecked('edit-settings-node-paragraphed-content-demo-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-text-image-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-images-columns-field-images-demo-alt'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-images-columns-field-images-demo-title'); // Check if the publish/unpublish option works. $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display'); @@ -128,13 +128,13 @@ public function testParagraphTranslation() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text_image')); - $this->assertRaw('edit-field-paragraphs-demo-0-subform-status-value'); + $this->assertSession()->responseContains('edit-field-paragraphs-demo-0-subform-status-value'); $edit = [ 'title[0][value]' => 'example_publish_unpublish', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Example published and unpublished', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('Example published and unpublished')); + $this->assertSession()->pageTextContains(t('Example published and unpublished')); $this->clickLink(t('Edit')); $this->drupalPostForm(NULL, NULL, 'field_paragraphs_demo_nested_paragraph_add_more'); @@ -144,7 +144,7 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[1][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'Dummy text' ]; $this->drupalPostForm(NULL, $edit + ['status[value]' => FALSE], t('Save')); - $this->assertNoText(t('Example published and unpublished')); + $this->assertSession()->pageTextNotContains(t('Example published and unpublished')); // Check the parent fields are set properly. Get the node. $node = $this->drupalGetNodeByTitle('example_publish_unpublish'); @@ -152,16 +152,16 @@ public function testParagraphTranslation() { foreach ($node->field_paragraphs_demo->referencedEntities() as $paragraph) { $node_paragraph = Paragraph::load($paragraph->id())->toArray(); // Check if the fields are set properly. - $this->assertEqual($node_paragraph['parent_id'][0]['value'], $node->id()); - $this->assertEqual($node_paragraph['parent_type'][0]['value'], 'node'); - $this->assertEqual($node_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); + $this->assertEquals($node_paragraph['parent_id'][0]['value'], $node->id()); + $this->assertEquals($node_paragraph['parent_type'][0]['value'], 'node'); + $this->assertEquals($node_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); // If the paragraph is nested type load the child. if ($node_paragraph['type'][0]['target_id'] == 'nested_paragraph') { $nested_paragraph = Paragraph::load($node_paragraph['field_paragraphs_demo'][0]['target_id'])->toArray(); // Check if the fields are properly set. - $this->assertEqual($nested_paragraph['parent_id'][0]['value'], $paragraph->id()); - $this->assertEqual($nested_paragraph['parent_type'][0]['value'], 'paragraph'); - $this->assertEqual($nested_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); + $this->assertEquals($nested_paragraph['parent_id'][0]['value'], $paragraph->id()); + $this->assertEquals($nested_paragraph['parent_type'][0]['value'], 'paragraph'); + $this->assertEquals($nested_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); } } @@ -173,22 +173,22 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Text in english', ); // The button to remove a paragraph is present. - $this->assertRaw(t('Remove')); + $this->assertSession()->responseContains(t('Remove')); $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('Title in english'); // The text is present when editing again. $this->clickLink(t('Edit')); - $this->assertText('Title in english'); - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); // Add french translation. $this->clickLink(t('Translate')); $this->clickLink(t('Add'), 1); // Make sure the Add / Remove paragraph buttons are hidden. - $this->assertNoRaw(t('Remove')); - $this->assertNoRaw(t('Add text_image')); + $this->assertSession()->responseNotContains(t('Remove')); + $this->assertSession()->responseNotContains(t('Add text_image')); // Make sure that the original paragraph text is displayed. - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Text in english'); $edit = array( 'title[0][value]' => 'Title in french', @@ -197,24 +197,24 @@ public function testParagraphTranslation() { 'revision_log[0][value]' => 'french 1', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('paragraphed_content_demo Title in french has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in french has been updated.'); // Check the english translation. $this->drupalGet('node/' . $node->id()); - $this->assertText('Title in english'); - $this->assertText('Text in english'); - $this->assertNoText('Title in french'); - $this->assertNoText('Text in french'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); + $this->assertSession()->pageTextNotContains('Title in french'); + $this->assertSession()->pageTextNotContains('Text in french'); // Check the french translation. $this->drupalGet('fr/node/' . $node->id()); - $this->assertText('Title in french'); - $this->assertText('Text in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // The translation is still present when editing again. $this->clickLink(t('Edit')); - $this->assertText('Title in french'); - $this->assertText('Text in french'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); $edit = array( 'title[0][value]' => 'Title Change in french', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'New text in french', @@ -222,17 +222,17 @@ public function testParagraphTranslation() { 'revision_log[0][value]' => 'french 2', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('Title Change in french'); - $this->assertText('New text in french'); + $this->assertSession()->pageTextContains('Title Change in french'); + $this->assertSession()->pageTextContains('New text in french'); // Back to the source language. $this->drupalGet('node/' . $node->id()); $this->clickLink(t('Edit')); - $this->assertText('Title in english'); - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); // Save the original content on second request. $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('paragraphed_content_demo Title in english has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in english has been updated.'); // Test if reverting to old paragraphs revisions works, make sure that // the reverted node can be saved again. @@ -240,17 +240,17 @@ public function testParagraphTranslation() { $this->clickLink(t('Revert')); $this->drupalPostForm(NULL, ['revert_untranslated_fields' => TRUE], t('Revert')); $this->clickLink(t('Edit')); - $this->assertRaw('Title in french'); - $this->assertText('Text in french'); + $this->assertSession()->responseContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); $this->drupalPostForm(NULL, [], t('Save (this translation)')); - $this->assertNoRaw('The content has either been modified by another user, or you have already submitted modifications'); - $this->assertText('Text in french'); + $this->assertSession()->responseNotContains('The content has either been modified by another user, or you have already submitted modifications'); + $this->assertSession()->pageTextContains('Text in french'); //Add paragraphed content with untranslatable language $this->drupalGet('node/add/paragraphed_content_demo'); $edit = array('langcode[0][value]' => LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->drupalPostForm(NULL, $edit, t('Add text_image')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Make 'Images' paragraph field translatable, enable alt and title fields. $this->drupalGet('admin/structure/paragraphs_type/images/fields'); @@ -285,7 +285,7 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[0][subform][field_images_demo][0][title]' => 'Image title FR', ]; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertRaw('Title FR'); + $this->assertSession()->responseContains('Title FR'); $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, [], t('Add text')); @@ -328,17 +328,17 @@ public function testParagraphTranslation() { ]); $this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_content_demo ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo ' . $node->label() . ' has been updated.'); // Check that first paragraph langcode has been updated. \Drupal::entityTypeManager()->getStorage('paragraph')->resetCache([$paragraph_1->id(), $paragraph_2->id()]); $paragraph = Paragraph::load($paragraph_1->id()); - $this->assertEqual($paragraph->language()->getId(), 'de'); + $this->assertEquals($paragraph->language()->getId(), 'de'); $this->assertFalse($paragraph->hasTranslation('en')); // Check that second paragraph has two translations. $paragraph = Paragraph::load($paragraph_2->id()); $this->assertTrue($paragraph->hasTranslation('de')); $this->assertTrue($paragraph->hasTranslation('en')); - $this->assertRaw('german_text'); + $this->assertSession()->responseContains('german_text'); // Create an english translation of the node. $edit = [ @@ -349,12 +349,12 @@ public function testParagraphTranslation() { // Attempt to create a french translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); // Check that the german translation of the paragraphs is displayed. - $this->assertFieldByName('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_text_1'); - $this->assertFieldByName('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'german_text_2'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_text_1'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'german_text_2'); $this->drupalPostForm(NULL, ['source_langcode[source]' => 'en'], t('Change')); // Check that the english translation of the paragraphs is displayed. - $this->assertFieldByName('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_translation_1'); - $this->assertFieldByName('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'english_translation_2'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_translation_1'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'english_translation_2'); // Create a node with empty Paragraphs. $this->drupalGet('node/add/paragraphed_content_demo'); @@ -365,7 +365,7 @@ public function testParagraphTranslation() { $this->clickLink(t('Translate')); $this->clickLink(t('Add')); // Check the add button is not displayed. - $this->assertEqual(count($this->xpath('//*[@name="field_paragraphs_demo_0_subform_field_paragraphs_demo_images_add_more"]')), 0); + $this->assertEquals(count($this->xpath('//*[@name="field_paragraphs_demo_0_subform_field_paragraphs_demo_images_add_more"]')), 0); // Add a non translatable field to Text Paragraph type. $edit = [ @@ -399,10 +399,10 @@ public function testParagraphTranslation() { // Attempt to add a translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); - $this->assertText('untranslatable_field (all languages)'); - $this->assertText('untranslatable_ref_field (all languages)'); - $this->assertText('untranslatable_link_field (all languages)'); - $this->assertNoText('Text (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_field (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_ref_field (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_link_field (all languages)'); + $this->assertSession()->pageTextNotContains('Text (all languages)'); // Enable translations for the reference and link field. $edit = [ @@ -413,10 +413,10 @@ public function testParagraphTranslation() { // Attempt to add a translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); - $this->assertText('untranslatable_field (all languages)'); - $this->assertNoText('untranslatable_link_field (all languages)'); - $this->assertNoText('untranslatable_ref_field (all languages)'); - $this->assertNoText('Text (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_field (all languages)'); + $this->assertSession()->pageTextNotContains('untranslatable_link_field (all languages)'); + $this->assertSession()->pageTextNotContains('untranslatable_ref_field (all languages)'); + $this->assertSession()->pageTextNotContains('Text (all languages)'); } /** @@ -443,7 +443,7 @@ public function testParagraphTranslationMultilingual() { $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in english'); + $this->assertSession()->pageTextContains('Title in english'); $node = $this->drupalGetNodeByTitle('Title in english'); // Check the paragraph langcode is 'en'. $this->assertParagraphsLangcode($node->id()); @@ -459,9 +459,9 @@ public function testParagraphTranslationMultilingual() { ]; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); - $this->assertText('paragraphed_content_demo Title in french has been updated.'); - $this->assertText('Title in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in french has been updated.'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // Check the original node and the paragraph langcode is still 'en'. $this->assertParagraphsLangcode($node->id()); @@ -476,13 +476,13 @@ public function testParagraphTranslationMultilingual() { $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); $this->assertNoParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('Title in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // Back to the original node. $this->drupalGet('node/' . $node->id()); - $this->assertText('Title in english'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraph langcode are still 'en' and // check that the paragraphs buttons are still displayed. $this->clickLink('Edit'); @@ -511,15 +511,15 @@ public function testParagraphTranslationMultilingual() { $this->assertParagraphsLangcode($node->id()); $this->assertParagraphsButtons(2); $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('Title in english (de)'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english (de)'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraphs langcode are now 'de'. $this->assertParagraphsLangcode($node->id(), 'de'); // Check the french translation. $this->drupalGet('fr/node/' . $node->id()); - $this->assertText('Title in french'); - $this->assertNoText('Title in english (de)'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english (de)'); // Check editing a translation does not affect the source langcode and // check that the paragraphs buttons are still hidden. $this->clickLink('Edit'); @@ -559,13 +559,13 @@ public function testParagraphTranslationMultilingual() { $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); // Check the paragraphs langcode are still 'de' after saving the translation. $this->assertParagraphsLangcode($node->id(), 'de', 'fr'); - $this->assertText('Title in french'); - $this->assertNoText('Title in english (de)'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english (de)'); // Back to the original node. $this->drupalGet('de/node/' . $node->id()); - $this->assertText('Title in english (de)'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english (de)'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraphs langcode are still 'de' and // check that the paragraphs buttons are still displayed. $this->clickLink('Edit'); @@ -589,7 +589,7 @@ public function testParagraphTranslationMultilingual() { $this->assertParagraphsLangcode($node->id(), 'de'); $this->assertParagraphsButtons(3); $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('paragraphed_content_demo Title in english has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in english has been updated.'); // Check the original node and the paragraphs langcode are now 'en'. $this->assertParagraphsLangcode($node->id()); } @@ -609,7 +609,8 @@ public function testParagraphsMultilingualWorkflow() { // Create a node and check that the node langcode is 'english'. $this->drupalGet('node/add/paragraphed_content_demo'); - $this->assertOptionSelected('edit-langcode-0-value', 'en'); + $langcode_option = $this->assertSession()->optionExists('edit-langcode-0-value', 'en'); + $this->assertTrue($langcode_option->hasAttribute('selected')); // Change the node langcode to 'german' and add a 'Nested Paragraph'. $edit = [ 'title[0][value]' => 'Title in german', @@ -627,7 +628,7 @@ public function testParagraphsMultilingualWorkflow() { ], t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in german'); + $this->assertSession()->pageTextContains('Title in german'); $node1 = $this->getNodeByTitle('Title in german'); // Check the paragraph langcode is 'de' and its buttons are displayed. @@ -662,7 +663,8 @@ public function testParagraphsMultilingualWorkflow() { // Create another node. $this->drupalGet('node/add/paragraphed_content_demo'); // Check that the node langcode is 'english' and add a 'Nested Paragraph'. - $this->assertOptionSelected('edit-langcode-0-value', 'en'); + $langcode_option = $this->assertSession()->optionExists('edit-langcode-0-value', 'en'); + $this->assertTrue($langcode_option->hasAttribute('selected')); $this->drupalPostForm(NULL, NULL, t('Add nested_paragraph')); // Check that the paragraphs buttons are displayed and add an 'Images' // paragraph inside the nested paragraph. @@ -677,7 +679,7 @@ public function testParagraphsMultilingualWorkflow() { $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in english'); + $this->assertSession()->pageTextContains('Title in english'); $node2 = $this->drupalGetNodeByTitle('Title in english'); // Check the paragraph langcode is 'en' and its buttons are displayed. @@ -806,10 +808,10 @@ protected function assertParagraphsButtonsHelper($count, $hidden = TRUE) { for ($i = 0; $i < $count; $i++) { $remove_button = $this->xpath('//*[@name="field_paragraphs_demo_' . $i . '_remove"]'); if (!$hidden) { - $this->assertNotEqual(count($remove_button), 0); + $this->assertNotEquals(count($remove_button), 0); } else { - $this->assertEqual(count($remove_button), 0); + $this->assertEquals(count($remove_button), 0); } } @@ -817,10 +819,10 @@ protected function assertParagraphsButtonsHelper($count, $hidden = TRUE) { // the add more buttons presence for this test class. $add_button = $this->xpath('//input[@value="Add images"]'); if (!$hidden) { - $this->assertNotEqual(count($add_button), 0); + $this->assertNotEquals(count($add_button), 0); } else { - $this->assertEqual(count($add_button), 0); + $this->assertEquals(count($add_button), 0); } } @@ -840,13 +842,13 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran /** @var \Drupal\node\NodeInterface $node */ $node = Node::load($node_id); $node_langcode = $node->langcode->value; - $this->assertEqual($node_langcode, $source_lang, 'Host langcode matches.'); + $this->assertEquals($node_langcode, $source_lang, 'Host langcode matches.'); /** @var \Drupal\Core\Entity\ContentEntityBase $paragraph */ foreach ($node->field_paragraphs_demo->referencedEntities() as $paragraph) { $paragraph_langcode = $paragraph->language()->getId(); $message = new FormattableMarkup('Node langcode is "@node", paragraph item langcode is "@item".', ['@node' => $source_lang, '@item' => $paragraph_langcode]); - $this->assertEqual($paragraph_langcode, $source_lang, $message); + $this->assertEquals($paragraph_langcode, $source_lang, $message); } // Check the translation. @@ -856,7 +858,7 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran if ($node->hasTranslation($trans_lang)) { $trans_node = $node->getTranslation($trans_lang); $trans_node_langcode = $trans_node->language()->getId(); - $this->assertEqual($trans_node_langcode, $trans_lang, 'Translated node langcode matches.'); + $this->assertEquals($trans_node_langcode, $trans_lang, 'Translated node langcode matches.'); // Check the paragraph item langcode matching the translated node langcode. foreach ($trans_node->field_paragraphs_demo->referencedEntities() as $paragraph) { @@ -864,7 +866,7 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran $trans_item = $paragraph->getTranslation($trans_lang); $paragraph_langcode = $trans_item->language()->getId(); $message = new FormattableMarkup('Translated node langcode is "@node", paragraph item langcode is "@item".', ['@node' => $trans_lang, '@item' => $paragraph_langcode]); - $this->assertEqual($paragraph_langcode, $trans_lang, $message); + $this->assertEquals($paragraph_langcode, $trans_lang, $message); } } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTypesTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTypesTest.php index ef7d4ec74d38c3e7a9e3bbc17438bb3952752e1e..71ec3fbef3753533005156be210cd7454311a2ac 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTypesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsTypesTest.php @@ -25,7 +25,7 @@ public function testRemoveTypesWithContent() { // Attempt to delete the content type not used yet. $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Delete')); - $this->assertText('This action cannot be undone.'); + $this->assertSession()->pageTextContains('This action cannot be undone.'); $this->clickLink(t('Cancel')); // Add a test node with a Paragraph. @@ -33,12 +33,12 @@ public function testRemoveTypesWithContent() { $this->drupalPostForm(NULL, [], 'paragraphs_paragraph_type_test_add_more'); $edit = ['title[0][value]' => 'test_node']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test test_node has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test test_node has been created.'); // Attempt to delete the paragraph type already used. $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Delete')); - $this->assertText('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); + $this->assertSession()->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); } @@ -60,7 +60,7 @@ public function testParagraphTypeIcon() { $this->drupalLogin($admin_user); // Add the paragraph type with icon. $this->drupalGet('admin/structure/paragraphs_type/add'); - $this->assertText('Paragraph type icon'); + $this->assertSession()->pageTextContains('Paragraph type icon'); $test_files = $this->getTestFiles('image'); $fileSystem = \Drupal::service('file_system'); $edit = [ @@ -69,24 +69,24 @@ public function testParagraphTypeIcon() { 'files[icon_file]' => $fileSystem->realpath($test_files[0]->uri), ]; $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); - $this->assertText('Saved the Test paragraph type Paragraphs type.'); + $this->assertSession()->pageTextContains('Saved the Test paragraph type Paragraphs type.'); // Check if the icon has been saved. $this->drupalGet('admin/structure/paragraphs_type'); - $this->assertRaw('image-test.png'); + $this->assertSession()->responseContains('image-test.png'); $this->clickLink('Edit'); - $this->assertText('image-test.png'); + $this->assertSession()->pageTextContains('image-test.png'); // Check that the icon file usage has been registered. $paragraph_type = ParagraphsType::load('test_paragraph_type_icon'); $file = $entity_repository->loadEntityByUuid('file', $paragraph_type->get('icon_uuid')); $usages = $file_usage->listUsage($file); - $this->assertEqual($usages['paragraphs']['paragraphs_type']['test_paragraph_type_icon'], 1); + $this->assertEquals($usages['paragraphs']['paragraphs_type']['test_paragraph_type_icon'], 1); // Tests calculateDependencies method. $dependencies = $paragraph_type->getDependencies(); $dependencies_uuid[] = explode(':', $dependencies['content'][0]); - $this->assertEqual($paragraph_type->get('icon_uuid'), $dependencies_uuid[0][2]); + $this->assertEquals($paragraph_type->get('icon_uuid'), $dependencies_uuid[0][2]); // Delete the icon. $this->drupalGet('admin/structure/paragraphs_type/test_paragraph_type_icon'); @@ -95,7 +95,7 @@ public function testParagraphTypeIcon() { // Check that the icon file usage has been deregistered. $usages = $file_usage->listUsage($file); - $this->assertEqual($usages, []); + $this->assertEquals($usages, []); } /** @@ -112,7 +112,7 @@ public function testParagraphTypeDefaultIcon() { $this->drupalLogin($admin_user); // Add the paragraph type with icon. $this->drupalGet('admin/structure/paragraphs_type/add'); - $this->assertText('Paragraph type icon'); + $this->assertSession()->pageTextContains('Paragraph type icon'); $test_files = $this->getTestFiles('image'); $fileSystem = \Drupal::service('file_system'); $edit = [ @@ -121,7 +121,7 @@ public function testParagraphTypeDefaultIcon() { 'files[icon_file]' => $fileSystem->realpath($test_files[0]->uri), ]; $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); - $this->assertText('Saved the Test paragraph type Paragraphs type.'); + $this->assertSession()->pageTextContains('Saved the Test paragraph type Paragraphs type.'); // Check if the icon is created from defaults if not exists. $paragraph_type = ParagraphsType::load('test_paragraph_type_icon'); @@ -131,11 +131,11 @@ public function testParagraphTypeDefaultIcon() { $this->drupalGet('admin/structure/paragraphs_type'); // New default icon name. $default_icon_name = 'test_paragraph_type_icon-default-icon.png'; - $this->assertRaw($default_icon_name); + $this->assertSession()->responseContains($default_icon_name); $this->clickLink('Edit'); - $this->assertText($default_icon_name); + $this->assertSession()->pageTextContains($default_icon_name); $file = $entity_repository->loadEntityByUuid('file', $paragraph_type->get('icon_uuid')); - $this->assertTrue($file); + $this->assertNotEmpty($file); } /** @@ -146,7 +146,7 @@ public function testParagraphTypeDescription() { $this->drupalLogin($admin_user); // Add the paragraph type with description. $this->drupalGet('admin/structure/paragraphs_type/add'); - $this->assertText('Description'); + $this->assertSession()->pageTextContains('Description'); $label = 'Test paragraph type'; $description_markup = 'Use <em>Test paragraph type</em> to test the functionality of descriptions.'; $description_text = 'Use Test paragraph type to test the functionality of descriptions.'; @@ -156,19 +156,19 @@ public function testParagraphTypeDescription() { 'description' => $description_markup, ]; $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); - $this->assertText("Saved the $label Paragraphs type."); + $this->assertSession()->pageTextContains("Saved the $label Paragraphs type."); // Check if the description has been saved. $this->drupalGet('admin/structure/paragraphs_type'); - $this->assertText('Description'); - $this->assertText($description_text); - $this->assertRaw($description_markup); + $this->assertSession()->pageTextContains('Description'); + $this->assertSession()->pageTextContains($description_text); + $this->assertSession()->responseContains($description_markup); // Check if description is at Description column. $header_position = count($this->xpath('//table/thead/tr/th[.="Description"]/preceding-sibling::th')); $row_position = count($this->xpath('//table/tbody/tr/td[.="' . $description_text . '"]/preceding-sibling::td')); - $this->assertEqual($header_position, $row_position); + $this->assertEquals($header_position, $row_position); $this->clickLink('Edit'); - $this->assertText('Use <em>Test paragraph type</em> to test the functionality of descriptions.'); + $this->assertSession()->responseContains('Use <em>Test paragraph type</em> to test the functionality of descriptions.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsUiTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsUiTest.php index b4939e237ee55fa3188821cc50d241c788777099..dfe62893aa67e34330131750310adca2e4f0e868 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsUiTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsUiTest.php @@ -99,7 +99,7 @@ public function testEmptyRequiredField() { $title = 'Empty'; $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save')); - $this->assertText($field_title . ' field is required'); + $this->assertSession()->pageTextContains($field_title . ' field is required'); // Attempt to create a paragraphed node with only a paragraph in the // "remove" mode in the required field. @@ -107,9 +107,9 @@ public function testEmptyRequiredField() { $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, [], 'field_content_text_image_add_more'); $this->drupalPostForm(NULL, [], 'field_content_0_remove'); - $this->assertNoText($field_title . ' field is required'); + $this->assertSession()->pageTextNotContains($field_title . ' field is required'); $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save')); - $this->assertText($field_title . ' field is required'); + $this->assertSession()->pageTextContains($field_title . ' field is required'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsWidgetButtonsTest.php b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsWidgetButtonsTest.php index aeb7786d3850b9d48c66d71885246045c373282f..220af02df097400641c3a220881137371c5fab4f 100644 --- a/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsWidgetButtonsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Classic/ParagraphsWidgetButtonsTest.php @@ -37,9 +37,9 @@ public function testWidgetButtons() { // Test the 'Open' mode. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText($text); + $this->assertSession()->pageTextContains($text); // Test the 'Closed' mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); @@ -47,7 +47,7 @@ public function testWidgetButtons() { // Click "Edit" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_1_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text); $closed_mode_text = 'closed_mode_text'; // Click "Collapse" button on both paragraphs. $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $closed_mode_text]; @@ -55,54 +55,56 @@ public function testWidgetButtons() { $edit = ['field_paragraphs[1][subform][field_text][0][value]' => $closed_mode_text]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_1_collapse'); // Verify that we have warning message for each paragraph. - $this->assertNoUniqueText('You have unsaved changes on this Paragraph item.'); - $this->assertRaw('<span class="summary-content">' . $closed_mode_text); + $page_text = $this->getSession()->getPage()->getText(); + $nr_found = substr_count($page_text, 'You have unsaved changes on this Paragraph item.'); + $this->assertGreaterThan(1, $nr_found); + $this->assertSession()->responseContains('<span class="summary-content">' . $closed_mode_text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertText($closed_mode_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains($closed_mode_text); // Test the 'Preview' mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'preview'); $this->drupalGet('node/' . $node->id() . '/edit'); // Click "Edit" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text); $preview_mode_text = 'preview_mode_text'; $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $preview_mode_text]; // Click "Collapse" button. $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); - $this->assertText('You have unsaved changes on this Paragraph item.'); - $this->assertText($preview_mode_text); + $this->assertSession()->pageTextContains('You have unsaved changes on this Paragraph item.'); + $this->assertSession()->pageTextContains($preview_mode_text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertText($preview_mode_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains($preview_mode_text); // Test the remove/restore function. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertText($preview_mode_text); + $this->assertSession()->pageTextContains($preview_mode_text); // Click "Remove" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); - $this->assertText('Deleted Paragraph: text_paragraph'); + $this->assertSession()->pageTextContains('Deleted Paragraph: text_paragraph'); // Click "Restore" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_restore'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $preview_mode_text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $preview_mode_text); $restore_text = 'restore_text'; $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $restore_text]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertText($restore_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains($restore_text); // Test the remove/confirm remove function. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertText($restore_text); + $this->assertSession()->pageTextContains($restore_text); // Click "Remove" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); - $this->assertText('Deleted Paragraph: text_paragraph'); + $this->assertSession()->pageTextContains('Deleted Paragraph: text_paragraph'); // Click "Confirm Removal" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_confirm_remove'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertNoText($restore_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextNotContains($restore_text); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAccessTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAccessTest.php index 0d5e062fe270e7a486594d2c906255f234a1ecd3..afd218c0537ea5fb52d715a9156565d317b6fb1c 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAccessTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAccessTest.php @@ -74,8 +74,8 @@ protected function setUp() { ]; $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); - $view_display = entity_get_display('paragraph', 'images', 'default') - ->setComponent('field_images_demo', ['settings' => ['image_style' => 'medium']]); + $view_display = \Drupal::service('entity_display.repository')->getViewDisplay('paragraph', 'images'); + $view_display->setComponent('field_images_demo', ['settings' => ['image_style' => 'medium']]); $view_display->save(); } @@ -146,7 +146,7 @@ public function testParagraphAccessCheck() { $image_style = ImageStyle::load('medium'); $img1_url = $image_style->buildUrl('private://' . date('Y-m') . '/privateImage.jpg'); $image_url = file_url_transform_relative($img1_url); - $this->assertRaw($image_url, 'Image was found in preview'); + $this->assertSession()->responseContains($image_url, 'Image was found in preview'); $this->clickLink(t('Back to content editing')); $this->drupalPostForm(NULL, [], t('Save')); @@ -155,10 +155,10 @@ public function testParagraphAccessCheck() { $this->drupalGet('node/' . $node->id()); // Check the text and image after publish. - $this->assertRaw($image_url, 'Image was found in content'); + $this->assertSession()->responseContains($image_url, 'Image was found in content'); $this->drupalGet($img1_url); - $this->assertResponse(200, 'Image could be downloaded'); + $this->assertSession()->statusCodeEquals(200); // Logout to become anonymous. $this->drupalLogout(); @@ -168,17 +168,17 @@ public function testParagraphAccessCheck() { $img_url = $image_style->buildUrl('private://' . date('Y-m') . '/privateImage2.jpg'); $image_url = file_url_transform_relative($img_url); // Check the text and image after publish. Anonymous should not see content. - $this->assertNoRaw($image_url, 'Image was not found in content'); + $this->assertSession()->responseNotContains($image_url, 'Image was not found in content'); $this->drupalGet($img_url); - $this->assertResponse(403, 'Image could not be downloaded'); + $this->assertSession()->statusCodeEquals(403); // Login as admin with no delete permissions. $this->loginAsAdmin($permissions); // Create a new demo node. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertText('Text'); + $this->assertSession()->pageTextContains('Text'); $edit = [ 'title[0][value]' => 'delete_permissions', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Test', @@ -192,7 +192,7 @@ public function testParagraphAccessCheck() { $this->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_remove'); $this->drupalPostForm(NULL, [], t('Save')); $node = $this->getNodeByTitle('delete_permissions'); - $this->assertUrl('node/' . $node->id()); + $this->assertSession()->addressEquals('node/' . $node->id()); // Create an unpublished Paragraph and assert if it is displayed for the // user. @@ -210,15 +210,15 @@ public function testParagraphAccessCheck() { $this->drupalPostForm('admin/structure/paragraphs_type/text/form-display', $edit, 'Save'); $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertText('Text'); + $this->assertSession()->pageTextContains('Text'); $edit = [ 'title[0][value]' => 'unpublished_permissions', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'recognizable_test', 'field_paragraphs_demo[0][subform][status][value]' => FALSE ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('recognizable_test'); - $this->assertRaw('paragraph--unpublished'); + $this->assertSession()->pageTextContains('recognizable_test'); + $this->assertSession()->responseContains('paragraph--unpublished'); $this->drupalLogout(); $node = $this->drupalGetNodeByTitle('unpublished_permissions'); @@ -230,14 +230,14 @@ public function testParagraphAccessCheck() { $this->drupalLogin($user); // Assert that the Paragraph is not displayed. $this->drupalGet('node/' . $node->id()); - $this->assertNoText('recognizable_test'); - $this->assertNoRaw('paragraph--unpublished'); + $this->assertSession()->pageTextNotContains('recognizable_test'); + $this->assertSession()->responseNotContains('paragraph--unpublished'); // Grant to the user the view unpublished Paragraph permission. $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), ['view unpublished paragraphs']); // Assert that the Paragraph is displayed. $this->drupalGet('node/' . $node->id()); - $this->assertText('recognizable_test'); - $this->assertRaw('paragraph--unpublished'); + $this->assertSession()->pageTextContains('recognizable_test'); + $this->assertSession()->responseContains('paragraph--unpublished'); // Grant to the user the administer Paragraphs settings permission. $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), ['administer paragraphs settings']); @@ -246,15 +246,15 @@ public function testParagraphAccessCheck() { // Assert that the Paragraph is not displayed even if the user has the // permission to do so. $this->drupalGet('node/' . $node->id()); - $this->assertNoText('recognizable_test'); - $this->assertNoRaw('paragraph--unpublished'); + $this->assertSession()->pageTextNotContains('recognizable_test'); + $this->assertSession()->responseNotContains('paragraph--unpublished'); // Enable the show unpublished Paragraphs setting. $this->drupalPostForm('admin/config/content/paragraphs', ['show_unpublished' => TRUE], 'Save configuration'); // Assert that the Paragraph is displayed when the user has the permission // to do so. $this->drupalGet('node/' . $node->id()); - $this->assertText('recognizable_test'); - $this->assertRaw('paragraph--unpublished'); + $this->assertSession()->pageTextContains('recognizable_test'); + $this->assertSession()->responseContains('paragraph--unpublished'); } /** @@ -275,13 +275,13 @@ public function testParagraphsTextFormatValidation() { // Create a node with a Text Paragraph using the filtered html format. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertText('Text'); + $this->assertSession()->pageTextContains('Text'); $edit = [ 'title[0][value]' => 'access_validation_test', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Test', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_content_demo access_validation_test has been created.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo access_validation_test has been created.'); $this->drupalLogout(); // Login as an user without the Text Format permission. $user = $this->drupalCreateUser([ @@ -292,12 +292,12 @@ public function testParagraphsTextFormatValidation() { $node = $this->getNodeByTitle('access_validation_test'); $this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_content_demo access_validation_test has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo access_validation_test has been updated.'); $this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_collapse'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_content_demo access_validation_test has been updated.'); - $this->assertNoText('The value you selected is not a valid choice.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo access_validation_test has been updated.'); + $this->assertSession()->pageTextNotContains('The value you selected is not a valid choice.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAddModesTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAddModesTest.php index d524c644bbadab17d6026d0dc7ea3d91aa6ccb0c..baa1cdcd8c77f90b877e358811bf21834f35e9ab 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAddModesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAddModesTest.php @@ -22,10 +22,10 @@ public function testNoDefaultValue() { $this->clickLink(t('Edit')); // Check that the current field does not allow to add default values. - $this->assertText('No widget available for: field_paragraphs.'); + $this->assertSession()->pageTextContains('No widget available for: field_paragraphs.'); $this->drupalPostForm(NULL, [], t('Save settings')); - $this->assertText('Saved field_paragraphs configuration.'); - $this->assertResponse(200); + $this->assertSession()->pageTextContains('Saved field_paragraphs configuration.'); + $this->assertSession()->statusCodeEquals(200); } /** @@ -39,7 +39,7 @@ public function testEmptyAllowedTypes() { $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields'); $this->clickLink(t('Edit')); $this->drupalPostForm(NULL, [], t('Save settings')); - $this->assertText('Saved field_paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved field_paragraphs configuration.'); } /** @@ -118,12 +118,12 @@ public function testSelectMode() { */ protected function assertAddButtons($options) { $this->drupalGet('node/add/paragraphed_test'); - $buttons = $this->xpath('//input[@class="field-add-more-submit paragraphs-add-wrapper button js-form-submit form-submit"]'); + $buttons = $this->xpath('//input[@class="field-add-more-submit button js-form-submit form-submit"]'); // Check if the buttons are in the same order as the given array. foreach ($buttons as $key => $button) { - $this->assertEqual($button->getValue(), $options[$key]); + $this->assertEquals($button->getValue(), $options[$key]); } - $this->assertTrue(count($buttons) == count($options), 'The amount of drop down options matches with the given array'); + $this->assertEquals(count($buttons), count($options), 'The amount of drop down options matches with the given array'); } /** @@ -139,10 +139,10 @@ protected function assertSelectOptions($options, $paragraphs_field) { $buttons = $this->xpath('//*[@name="' . $paragraphs_field . '[add_more][add_more_select]"]/option'); // Check if the options are in the same order as the given array. foreach ($buttons as $key => $button) { - $this->assertEqual($button->getValue(), $options[$key]); + $this->assertEquals($button->getValue(), $options[$key]); } - $this->assertTrue(count($buttons) == count($options), 'The amount of select options matches with the given array'); - $this->assertNotEqual($this->xpath('//*[@name="' . $paragraphs_field .'_add_more"]'), [], 'The add button is displayed'); + $this->assertEquals(count($buttons), count($options), 'The amount of select options matches with the given array'); + $this->assertNotEquals($this->xpath('//*[@name="' . $paragraphs_field .'_add_more"]'), [], 'The add button is displayed'); } /** @@ -172,7 +172,7 @@ public function testSettingDefaultParagraphType() { // Check if default paragraph type is showing. $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Text + Image'); + $this->assertSession()->pageTextContains('Text + Image'); $this->removeDefaultParagraphType('paragraphed_test'); // Disable text_image as default paragraph type. @@ -182,8 +182,8 @@ public function testSettingDefaultParagraphType() { $this->drupalGet('node/add/paragraphed_test'); $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody'); $header = $this->xpath('//table[@id="paragraphs-values"]/thead'); - $this->assertEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertEquals($elements, []); + $this->assertNotEquals($header, []); // Check if default type is created only for new host $this->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', 'text_image'); @@ -193,8 +193,8 @@ public function testSettingDefaultParagraphType() { $this->drupalGet('node/1/edit'); $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody'); $header = $this->xpath('//table[@id="paragraphs-values"]/thead'); - $this->assertEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertEquals($elements, []); + $this->assertNotEquals($header, []); } /** @@ -220,8 +220,8 @@ public function testDefaultParagraphTypeWithSingleType() { $this->drupalGet('node/add/paragraphed_test'); $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody'); $header = $this->xpath('//table[@id="paragraphs-values"]/thead'); - $this->assertNotEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertNotEquals($elements, []); + $this->assertNotEquals($header, []); // Check that no paragraph type is automatically added, if the defaut // setting was set to '- None -'. @@ -229,7 +229,7 @@ public function testDefaultParagraphTypeWithSingleType() { $this->drupalGet('node/add/paragraphed_test'); $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody'); $header = $this->xpath('//table[@id="paragraphs-values"]/thead'); - $this->assertEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertEquals($elements, []); + $this->assertNotEquals($header, []); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAdministrationTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAdministrationTest.php index 8c3189703ba0b8f6d17d3ff069b9de10f42874b8..7d3bf6d61fb3aecb92e69c4b28159e40aba9823b 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAdministrationTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAdministrationTest.php @@ -50,7 +50,7 @@ public function testParagraphsRevisions() { $this->addParagraphsType('text'); // Create field types for the text. static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); // Create an article with paragraphs field. static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array( @@ -103,25 +103,25 @@ public function testParagraphsRevisions() { $this->countRevisions($node, $paragraph1, $paragraph2, 2); // Assert the paragraphs have been changed. - $this->assertNoText('Foo Bar 1'); - $this->assertText('Test text 2'); - $this->assertText('Foo Bar 2'); - $this->assertText('TEST TITLE'); + $this->assertSession()->pageTextNotContains('Foo Bar 1'); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->pageTextContains('Foo Bar 2'); + $this->assertSession()->pageTextContains('TEST TITLE'); // Check out the revisions page and assert there are 2 revisions. $this->drupalGet('node/' . $node->id() . '/revisions'); $rows = $this->xpath('//tbody/tr'); // Make sure two revisions available. - $this->assertEqual(count($rows), 2); + $this->assertEquals(count($rows), 2); // Revert to the old version. $this->clickLink(t('Revert')); $this->drupalPostForm(NULL, [], t('Revert')); $this->drupalGet('node/' . $node->id()); // Assert the node has been reverted. - $this->assertNoText('Foo Bar 2'); - $this->assertText('Test text 2'); - $this->assertText('Foo Bar 1'); - $this->assertText('TEST TITEL'); + $this->assertSession()->pageTextNotContains('Foo Bar 2'); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->pageTextContains('Foo Bar 1'); + $this->assertSession()->pageTextContains('TEST TITEL'); } @@ -144,7 +144,7 @@ public function testParagraphsCreation() { // Assert suggested 'Add a paragraph type' link when there is no type yet. $this->drupalGet('admin/structure/paragraphs_type'); - $this->assertText('There are no Paragraphs types yet.'); + $this->assertSession()->pageTextContains('There are no Paragraphs types yet.'); $this->drupalGet('admin/structure/types/manage/paragraphs/fields/add-field'); $edit = [ 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph', @@ -153,22 +153,22 @@ public function testParagraphsCreation() { ]; $this->drupalPostForm(NULL, $edit, 'Save and continue'); $this->drupalPostForm(NULL, [], 'Save field settings'); - $this->assertLinkByHref('admin/structure/paragraphs_type/add'); + $this->assertSession()->linkByHrefExists('admin/structure/paragraphs_type/add'); $this->clickLink('here'); - $this->assertUrl('admin/structure/paragraphs_type/add'); + $this->assertSession()->addressEquals('admin/structure/paragraphs_type/add'); $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Add paragraph type')); - $this->assertTitle('Add Paragraphs type | Drupal'); + $this->assertSession()->titleEquals('Add Paragraphs type | Drupal'); // Create paragraph type text + image. $this->addParagraphsType('text_image'); $this->drupalGet('admin/structure/paragraphs_type/text_image'); - $this->assertTitle('Edit text_image paragraph type | Drupal'); + $this->assertSession()->titleEquals('Edit text_image paragraph type | Drupal'); // Create field types for text and image. static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text', 'Text', 'text_long', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image', 'Image', 'image', array(), array('settings[alt_field_required]' => FALSE)); - $this->assertText('Saved Image configuration.'); + $this->assertSession()->pageTextContains('Saved Image configuration.'); // Create paragraph type Nested test. $this->addParagraphsType('nested_test'); @@ -188,21 +188,21 @@ public function testParagraphsCreation() { $this->addParagraphsType('image'); // Create field types for image. static::fieldUIAddNewField('admin/structure/paragraphs_type/image', 'image_only', 'Image only', 'image', array(), array()); - $this->assertText('Saved Image only configuration.'); + $this->assertSession()->pageTextContains('Saved Image only configuration.'); $this->drupalGet('admin/structure/paragraphs_type'); $rows = $this->xpath('//tbody/tr'); // Make sure 2 types are available with their label. - $this->assertEqual(count($rows), 3); - $this->assertText('text_image'); - $this->assertText('image'); + $this->assertEquals(count($rows), 3); + $this->assertSession()->pageTextContains('text_image'); + $this->assertSession()->pageTextContains('image'); // Make sure there is an edit link for each type. $this->clickLink(t('Edit')); // Make sure the field UI appears. - $this->assertLink('Manage fields'); - $this->assertLink('Manage form display'); - $this->assertLink('Manage display'); - $this->assertTitle('Edit image paragraph type | Drupal'); + $this->assertSession()->linkExists('Manage fields'); + $this->assertSession()->linkExists('Manage form display'); + $this->assertSession()->linkExists('Manage display'); + $this->assertSession()->titleEquals('Edit image paragraph type | Drupal'); // Test for "Add mode" setting. $this->drupalGet('admin/structure/types/manage/article/form-display'); @@ -217,11 +217,12 @@ public function testParagraphsCreation() { // Check if the setting is stored. $this->drupalGet('admin/structure/types/manage/article/form-display'); - $this->assertText('Add mode: Buttons', 'Checking the settings value.'); + $this->assertSession()->pageTextContains('Add mode: Buttons', 'Checking the settings value.'); $this->drupalPostForm(NULL, array(), $field_name . "_settings_edit"); // Assert the 'Buttons' option is selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.'); + $add_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button'); + $this->assertTrue($add_mode_option->hasAttribute('selected'), 'Updated value is correct!.'); // Add two Text + Image paragraphs in article. $this->drupalGet('node/add/article'); @@ -240,7 +241,7 @@ public function testParagraphsCreation() { 'files[field_paragraphs_1_subform_field_image_0]' => $file_system->realpath($files[1]->uri), ); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('article Test article has been created.'); + $this->assertSession()->pageTextContains('article Test article has been created.'); $node = $this->drupalGetNodeByTitle('Test article'); $img1_url = file_create_url(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/' . $files[0]->filename)); @@ -251,10 +252,10 @@ public function testParagraphsCreation() { $img2_mime = \Drupal::service('file.mime_type.guesser')->guess($files[1]->uri); // Check the text and image after publish. - $this->assertText('Test text 1'); - $this->assertRaw('<img src="' . file_url_transform_relative($img1_url)); - $this->assertText('Test text 2'); - $this->assertRaw('<img src="' . file_url_transform_relative($img2_url)); + $this->assertSession()->pageTextContains('Test text 1'); + $this->assertSession()->responseContains('<img src="' . file_url_transform_relative($img1_url)); + $this->assertSession()->pageTextContains('Test text 2'); + $this->assertSession()->responseContains('<img src="' . file_url_transform_relative($img2_url)); // Tests for "Edit mode" settings. // Test for closed setting. @@ -265,16 +266,17 @@ public function testParagraphsCreation() { $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'); $this->drupalPostForm(NULL, $edit, t('Save')); // Check if the setting is stored. - $this->assertText('Edit mode: Closed', 'Checking the settings value.'); + $this->assertSession()->pageTextContains('Edit mode: Closed', 'Checking the settings value.'); $this->drupalPostForm(NULL, array(), "field_paragraphs_settings_edit"); // Assert the 'Closed' option is selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Updated value correctly.'); + $edit_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed'); + $this->assertTrue($edit_mode_option->hasAttribute('selected'), 'Updated value correctly.'); $this->drupalGet('node/1/edit'); // The textareas for paragraphs should not be visible. - $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertRaw('<span class="summary-content">Test text 1</span>, <span class="summary-content">' . $files[0]->filename); - $this->assertRaw('<span class="summary-content">Test text 2</span>, <span class="summary-content">' . $files[1]->filename); + $this->assertSession()->responseNotContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseContains('<span class="summary-content">Test text 1</span>, <span class="summary-content">' . $files[0]->filename); + $this->assertSession()->responseContains('<span class="summary-content">Test text 2</span>, <span class="summary-content">' . $files[1]->filename); // Test for preview option. $this->drupalGet('admin/structure/types/manage/article/form-display'); @@ -284,61 +286,63 @@ public function testParagraphsCreation() { 'fields[field_paragraphs][settings_edit_form][settings][closed_mode]' => 'preview', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Edit mode: Closed', 'Checking the "Edit mode" setting value.'); - $this->assertText('Closed mode: Preview', 'Checking the "Closed mode" settings value.'); + $this->assertSession()->pageTextContains('Edit mode: Closed', 'Checking the "Edit mode" setting value.'); + $this->assertSession()->pageTextContains('Closed mode: Preview', 'Checking the "Closed mode" settings value.'); $this->drupalGet('node/1/edit'); // The texts in the paragraphs should be visible. - $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertNoRaw('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertText('Test text 1'); - $this->assertText('Test text 2'); + $this->assertSession()->responseNotContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->pageTextContains('Test text 1'); + $this->assertSession()->pageTextContains('Test text 2'); // Test for open option. $this->drupalGet('admin/structure/types/manage/article/form-display'); $this->drupalPostForm(NULL, array(), "field_paragraphs_settings_edit"); // Assert the "Closed" and "Preview" options are selected. - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Correctly updated the "Edit mode" value.'); - $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-closed-mode', 'preview', 'Correctly updated the "Closed mode" value.'); + $edit_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed'); + $this->assertTrue($edit_mode_option->hasAttribute('selected'), 'Correctly updated the "Edit mode" value.'); + $closed_mode_option = $this->assertSession()->optionExists('edit-fields-field-paragraphs-settings-edit-form-settings-closed-mode', 'preview'); + $this->assertTrue($closed_mode_option->hasAttribute('selected'),'Correctly updated the "Closed mode" value.'); // Restore the value to Open for next test. $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'open'); $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/1/edit'); // The textareas for paragraphs should be visible. - $this->assertRaw('field_paragraphs[0][subform][field_text][0][value]'); - $this->assertRaw('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseContains('field_paragraphs[0][subform][field_text][0][value]'); + $this->assertSession()->responseContains('field_paragraphs[1][subform][field_text][0][value]'); $paragraphs = Paragraph::loadMultiple(); - $this->assertEqual(count($paragraphs), 2, 'Two paragraphs in article'); + $this->assertEquals(count($paragraphs), 2, 'Two paragraphs in article'); // Check article edit page. $this->drupalGet('node/' . $node->id() . '/edit'); // Check both paragraphs in edit page. - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1'); - $this->assertRaw('<a href="' . $img1_url . '" type="' . $img1_mime . '; length=' . $img1_size . '">' . $files[0]->filename . '</a>'); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2'); - $this->assertRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'Test text 1'); + $this->assertSession()->responseContains('<a href="' . $img1_url . '" type="' . $img1_mime . '; length=' . $img1_size . '">' . $files[0]->filename . '</a>'); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_text][0][value]', 'Test text 2'); + $this->assertSession()->responseContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Remove 2nd paragraph. $this->getSession()->getPage()->find('css', '[name="field_paragraphs_1_remove"]')->press(); - $this->assertNoField('field_paragraphs[1][subform][field_text][0][value]'); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->fieldNotExists('field_paragraphs[1][subform][field_text][0][value]'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Assert the paragraph is not deleted unless the user saves the node. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Remove the second paragraph. $this->getSession()->getPage()->find('css', '[name="field_paragraphs_1_remove"]')->press(); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); $edit = [ 'field_paragraphs[0][subform][field_image][0][alt]' => 'test_alt', ]; $this->drupalPostForm(NULL, $edit, t('Save')); // Assert the paragraph is deleted after the user saves the node. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoRaw('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); + $this->assertSession()->responseNotContains('<a href="' . $img2_url . '" type="' . $img2_mime . '; length=' . $img2_size . '">' . $files[1]->filename . '</a>'); // Delete the node. $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertText('Test article has been deleted.'); + $this->assertSession()->pageTextContains('Test article has been deleted.'); // Check if the publish/unpublish option works. $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display'); @@ -350,19 +354,19 @@ public function testParagraphsCreation() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/add/article'); $this->drupalPostForm(NULL, NULL, t('Add text_image')); - $this->assertRaw('edit-field-paragraphs-0-subform-status-value'); + $this->assertSession()->responseContains('edit-field-paragraphs-0-subform-status-value'); $edit = [ 'title[0][value]' => 'Example publish/unpublish', 'field_paragraphs[0][subform][field_text][0][value]' => 'Example published and unpublished', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('Example published and unpublished')); + $this->assertSession()->pageTextContains(t('Example published and unpublished')); $this->clickLink(t('Edit')); $edit = [ 'field_paragraphs[0][subform][status][value]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertNoText(t('Example published and unpublished')); + $this->assertSession()->pageTextNotContains(t('Example published and unpublished')); // Set the fields as required. $this->drupalGet('admin/structure/types/manage/article/fields'); @@ -377,14 +381,14 @@ public function testParagraphsCreation() { $this->drupalPostForm(NULL, [], 'field_paragraphs_nested_test_add_more'); // Ensure that nested header actions do not add a visible weight field. - $this->assertNoFieldByName('field_paragraphs[0][subform][field_paragraphs][header_actions][_weight]'); + $this->assertSession()->fieldNotExists('field_paragraphs[0][subform][field_paragraphs][header_actions][_weight]'); $edit = [ 'field_paragraphs[0][subform][field_paragraphs][add_more][add_more_select]' => 'image', ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_subform_field_paragraphs_add_more'); // Test the new field is displayed. - $this->assertFieldByName('files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]'); + $this->assertSession()->fieldExists('files[field_paragraphs_0_subform_field_paragraphs_0_subform_field_image_only_0]'); // Add an image to the required field. $edit = array( @@ -396,14 +400,14 @@ public function testParagraphsCreation() { 'field_paragraphs[0][subform][field_paragraphs][0][subform][field_image_only][0][alt]' => 'Alternative_text', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('test required has been created.'); - $this->assertNoRaw('This value should not be null.'); + $this->assertSession()->pageTextContains('test required has been created.'); + $this->assertSession()->responseNotContains('This value should not be null.'); // Test that unsupported widgets are not displayed. $this->drupalGet('admin/structure/types/manage/article/form-display'); $select = $this->xpath('//*[@id="edit-fields-field-paragraphs-type"]')[0]; $this->assertCount(2, $select->findAll('css', 'option')); - $this->assertRaw('value="paragraphs" selected="selected"'); + $this->assertSession()->responseContains('value="paragraphs" selected="selected"'); // Check that Paragraphs is not displayed as an entity_reference field // reference option. @@ -414,7 +418,7 @@ public function testParagraphsCreation() { 'field_name' => 'unsupportedfield', ]; $this->drupalPostForm(NULL, $edit, t('Save and continue')); - $this->assertNoOption('edit-settings-target-type', 'paragraph'); + $this->assertSession()->optionNotExists('edit-settings-target-type', 'paragraph'); // Test that all Paragraph types can be referenced if none is selected. $this->addParagraphsType('nested_double_test'); @@ -438,8 +442,8 @@ public function testParagraphsCreation() { 'title[0][value]' => 'Nested twins', ); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Nested twins has been created.'); - $this->assertNoText('This entity (paragraph: ) cannot be referenced.'); + $this->assertSession()->pageTextContains('Nested twins has been created.'); + $this->assertSession()->pageTextNotContains('This entity (paragraph: ) cannot be referenced.'); // Set the fields as not required. $this->drupalGet('admin/structure/types/manage/article/fields'); @@ -482,29 +486,29 @@ public function testParagraphsCreation() { // Adding another required paragraph and deleting that again should not // validate closed paragraphs but trying to save the node should. $this->drupalPostForm(NULL, array(), 'field_paragraphs_node_test_add_more'); - $this->assertNoText('The referenced entity (node: ' . $node->id() . ') does not exist.'); - $this->assertFieldByName('field_paragraphs[1][subform][field_entity_reference][0][target_id]'); + $this->assertSession()->pageTextNotContains('The referenced entity (node: ' . $node->id() . ') does not exist.'); + $this->assertSession()->fieldExists('field_paragraphs[1][subform][field_entity_reference][0][target_id]'); $this->drupalPostForm(NULL, array(), 'field_paragraphs_1_remove'); - $this->assertNoText('The referenced entity (node: ' . $node->id() . ') does not exist.'); - $this->assertNoFieldByName('field_paragraphs[1][subform][field_entity_reference][0][target_id]'); + $this->assertSession()->pageTextNotContains('The referenced entity (node: ' . $node->id() . ') does not exist.'); + $this->assertSession()->fieldNotExists('field_paragraphs[1][subform][field_entity_reference][0][target_id]'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('Validation error on collapsed paragraph field_entity_reference.0.target_id: The referenced entity (node: ' . $node->id() . ') does not exist.'); + $this->assertSession()->pageTextContains('Validation error on collapsed paragraph field_entity_reference.0.target_id: The referenced entity (node: ' . $node->id() . ') does not exist.'); // Attempt to edit the Paragraph. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); // Try to collapse with an invalid reference. $this->drupalPostForm(NULL, ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo'], 'field_paragraphs_0_collapse'); // Paragraph should be still in edit mode. - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); - $this->assertFieldByName('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][0][target_id]'); + $this->assertSession()->fieldExists('field_paragraphs[0][subform][field_entity_reference][1][target_id]'); // Assert the validation message. - $this->assertText('There are no entities matching "foo".'); + $this->assertSession()->pageTextContains('There are no entities matching "foo".'); // Fix the broken reference. $node = $this->drupalGetNodeByTitle('Example publish/unpublish'); $edit = ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => $node->label() . ' (' . $node->id() . ')']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('choke test has been updated.'); - $this->assertLink('Example publish/unpublish'); + $this->assertSession()->pageTextContains('choke test has been updated.'); + $this->assertSession()->linkExists('Example publish/unpublish'); // Delete the new referenced node. $node->delete(); @@ -523,11 +527,11 @@ public function testParagraphsCreation() { // Try to save with an invalid reference. $edit = ['field_paragraphs[0][subform][field_entity_reference][0][target_id]' => 'foo']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('There are no entities matching "foo".'); + $this->assertSession()->pageTextContains('There are no entities matching "foo".'); // Remove the Paragraph and save the node. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('choke test has been updated.'); + $this->assertSession()->pageTextContains('choke test has been updated.'); $this->drupalGet('admin/structure/types/manage/article/fields'); $this->clickLink('Edit'); @@ -535,16 +539,16 @@ public function testParagraphsCreation() { // Verify that the text displayed is correct when no paragraph has been // added yet. $this->drupalGet('node/add/article'); - $this->assertText('This is the description of the field.'); + $this->assertSession()->pageTextContains('This is the description of the field.'); $elements = $this->xpath('//table[@id="field-paragraphs-values"]/tbody'); $header = $this->xpath('//table[@id="field-paragraphs-values"]/thead'); - $this->assertEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertEquals($elements, []); + $this->assertNotEquals($header, []); $this->drupalGet('admin/content/files'); $this->clickLink('1 place'); $label = $this->xpath('//tbody/tr/td[1]'); - $this->assertEqual(trim(htmlspecialchars_decode(strip_tags($label[0]->getText()))), 'test required > field_paragraphs > Paragraphs'); + $this->assertEquals(trim(htmlspecialchars_decode(strip_tags($label[0]->getText()))), 'test required > field_paragraphs > Paragraphs'); } /** @@ -552,9 +556,9 @@ public function testParagraphsCreation() { */ private function countRevisions($node, $paragraph1, $paragraph2, $revisions_count) { $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute(); - $this->assertEqual($node_revisions_count, $revisions_count); - $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count); - $this->assertEqual(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count); + $this->assertEquals($node_revisions_count, $revisions_count); + $this->assertEquals(\Drupal::entityQuery('paragraph')->condition('id', $paragraph1)->allRevisions()->count()->execute(), $revisions_count); + $this->assertEquals(\Drupal::entityQuery('paragraph')->condition('id', $paragraph2)->allRevisions()->count()->execute(), $revisions_count); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAlterByTypeTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAlterByTypeTest.php index ceaa62f3c44a1299d3a5d12a247edd857af85688..ad78b8cc33168d39d8cdf5ed5e03ae8a1d0e816f 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAlterByTypeTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalAlterByTypeTest.php @@ -36,6 +36,6 @@ public function testAlterBasedOnType() { // Check that the form alteration based on Paragraphs type works. // See paragraphs_test_field_widget_entity_reference_paragraphs_form_alter() $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Altered title'); + $this->assertSession()->pageTextContains('Altered title'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalBehaviorsTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalBehaviorsTest.php index 207a5eb58181e15739daccf2a3da36f97d4a58ce..c320af2fc6debb9bb8633ff5a3d49b2c39220886 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalBehaviorsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalBehaviorsTest.php @@ -32,9 +32,9 @@ public function testBehaviorPluginsFields() { // Check default configuration. $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); - $this->assertFieldByName('behavior_plugins[test_text_color][settings][default_color]', 'blue'); + $this->assertSession()->fieldValueEquals('behavior_plugins[test_text_color][settings][default_color]', 'blue'); - $this->assertText('Behavior plugins are only supported by the EXPERIMENTAL paragraphs widget'); + $this->assertSession()->pageTextContains('Behavior plugins are only supported by the EXPERIMENTAL paragraphs widget'); // Enable the test plugins, with an invalid configuration value. $edit = [ 'behavior_plugins[test_bold_text][enabled]' => TRUE, @@ -42,7 +42,7 @@ public function testBehaviorPluginsFields() { 'behavior_plugins[test_text_color][settings][default_color]' => 'red', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Red can not be used as the default color.'); + $this->assertSession()->pageTextContains('Red can not be used as the default color.'); // Ensure the form can be saved with an invalid configuration value when // the plugin is not selected. @@ -52,14 +52,14 @@ public function testBehaviorPluginsFields() { 'behavior_plugins[test_text_color][settings][default_color]' => 'red', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Saved the text_paragraph Paragraphs type.'); + $this->assertSession()->pageTextContains('Saved the text_paragraph Paragraphs type.'); // Ensure it can be saved with a valid value and that the defaults are // correct. $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); - $this->assertFieldChecked('edit-behavior-plugins-test-bold-text-enabled'); - $this->assertNoFieldChecked('edit-behavior-plugins-test-text-color-enabled'); - $this->assertFieldByName('behavior_plugins[test_text_color][settings][default_color]', 'blue'); + $this->assertSession()->checkboxChecked('edit-behavior-plugins-test-bold-text-enabled'); + $this->assertSession()->checkboxNotChecked('edit-behavior-plugins-test-text-color-enabled'); + $this->assertSession()->fieldValueEquals('behavior_plugins[test_text_color][settings][default_color]', 'blue'); $edit = [ 'behavior_plugins[test_bold_text][enabled]' => TRUE, @@ -67,13 +67,13 @@ public function testBehaviorPluginsFields() { 'behavior_plugins[test_text_color][settings][default_color]' => 'green', ]; $this->drupalPostForm('admin/structure/paragraphs_type/' . $paragraph_type, $edit, t('Save')); - $this->assertText('Saved the text_paragraph Paragraphs type.'); + $this->assertSession()->pageTextContains('Saved the text_paragraph Paragraphs type.'); $this->drupalGet('node/add/paragraphed_test'); // Behavior plugin settings is not available to users without // "edit behavior plugin settings" permission. - $this->assertNoFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'green'); + $this->assertSession()->fieldNotExists('field_paragraphs[0][behavior_plugins][test_text_color][text_color]'); $this->loginAsAdmin([ 'create paragraphed_test content', @@ -83,7 +83,7 @@ public function testBehaviorPluginsFields() { // Create a node with a Paragraph. $this->drupalGet('node/add/paragraphed_test'); - $this->assertFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'green'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'green'); // Setting a not allowed value in the text color plugin text field. $plugin_text = 'green'; $edit = [ @@ -93,11 +93,11 @@ public function testBehaviorPluginsFields() { ]; // Assert that the behavior form is after the dropbutton. $behavior_xpath = $this->xpath("//div[@id = 'edit-field-paragraphs-0-top']/following-sibling::*[1][@id = 'edit-field-paragraphs-0-behavior-plugins-test-bold-text']"); - $this->assertNotEqual($behavior_xpath, FALSE, 'Behavior form position incorrect'); + $this->assertNotEquals($behavior_xpath, FALSE, 'Behavior form position incorrect'); $this->drupalPostForm(NULL, $edit, t('Save')); // Asserting that the error message is shown. - $this->assertText('The only allowed values are blue and red.'); + $this->assertSession()->pageTextContains('The only allowed values are blue and red.'); // Updating the text color to an allowed value. $plugin_text = 'red'; $edit = [ @@ -105,11 +105,11 @@ public function testBehaviorPluginsFields() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); // Assert that the class has been added to the element. - $this->assertRaw('class="red_plugin_text'); + $this->assertSession()->responseContains('class="red_plugin_text'); $this->clickLink('Edit'); // Assert the plugin fields populate the stored values. - $this->assertFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', $plugin_text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', $plugin_text); // Update the value of both plugins. $updated_text = 'blue'; @@ -118,12 +118,12 @@ public function testBehaviorPluginsFields() { 'field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]' => TRUE, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertNoRaw('class="red_plugin_text'); - $this->assertRaw('class="bold_plugin_text blue_plugin_text'); + $this->assertSession()->responseNotContains('class="red_plugin_text'); + $this->assertSession()->responseContains('class="bold_plugin_text blue_plugin_text'); $this->clickLink('Edit'); // Assert the plugin fields populate the stored values. - $this->assertFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', $updated_text); - $this->assertFieldByName('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]', TRUE); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', $updated_text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]', TRUE); $this->loginAsAdmin([ 'edit any paragraphed_test content', @@ -132,16 +132,16 @@ public function testBehaviorPluginsFields() { $node = $this->getNodeByTitle('paragraphs_plugins_test'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', $updated_text); - $this->assertNoFieldByName('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]', TRUE); + $this->assertSession()->fieldNotExists('field_paragraphs[0][behavior_plugins][test_text_color][text_color]'); + $this->assertSession()->fieldNotExists('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]'); $this->drupalPostForm(NULL, [], t('Save')); // Make sure that values don't change if a user without the 'edit behavior // plugin settings' permission saves a node with paragraphs and enabled // behaviors. - $this->assertRaw('class="bold_plugin_text blue_plugin_text'); - $this->assertNoRaw('class="red_plugin_text'); + $this->assertSession()->responseContains('class="bold_plugin_text blue_plugin_text'); + $this->assertSession()->responseNotContains('class="red_plugin_text'); // Test plugin applicability. Add a paragraph type. $paragraph_type = 'text_paragraph_test'; @@ -151,15 +151,15 @@ public function testBehaviorPluginsFields() { static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'image', 'Image', 'image', [], []); // Assert if the plugin is listed on the edit form of the paragraphs type. $this->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type); - $this->assertNoFieldByName('behavior_plugins[test_bold_text][enabled]'); - $this->assertFieldByName('behavior_plugins[test_text_color][enabled]'); - $this->assertFieldByName('behavior_plugins[test_field_selection][enabled]'); - $this->assertText('Choose paragraph field to be applied.'); + $this->assertSession()->fieldNotExists('behavior_plugins[test_bold_text][enabled]'); + $this->assertSession()->fieldExists('behavior_plugins[test_text_color][enabled]'); + $this->assertSession()->fieldExists('behavior_plugins[test_field_selection][enabled]'); + $this->assertSession()->pageTextContains('Choose paragraph field to be applied.'); // Assert that Field Selection Filter plugin properly filters field types. - $this->assertOptionByText('edit-behavior-plugins-test-field-selection-settings-field-selection-filter', t('Image')); + $this->assertSession()->optionExists('edit-behavior-plugins-test-field-selection-settings-field-selection-filter', t('Image')); // Check that Field Selection Plugin does not filter any field types. - $this->assertOptionByText('edit-behavior-plugins-test-field-selection-settings-field-selection', t('Image')); - $this->assertOptionByText('edit-behavior-plugins-test-field-selection-settings-field-selection', t('Text')); + $this->assertSession()->optionExists('edit-behavior-plugins-test-field-selection-settings-field-selection', t('Image')); + $this->assertSession()->optionExists('edit-behavior-plugins-test-field-selection-settings-field-selection', t('Text')); // Test a plugin without behavior fields. $edit = [ @@ -173,7 +173,7 @@ public function testBehaviorPluginsFields() { 'field_paragraphs[0][subform][field_text_test][0][value]' => 'my behavior plugin does not have any field', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw('dummy_plugin_text'); + $this->assertSession()->responseContains('dummy_plugin_text'); // Tests behavior plugin on paragraph type with no fields. $this->addParagraphsType('fieldless'); @@ -184,7 +184,7 @@ public function testBehaviorPluginsFields() { $edit = ['title[0][value]' => t('Fieldless')]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Add a paragraphed content. $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_test_add_more'); @@ -196,7 +196,7 @@ public function testBehaviorPluginsFields() { // Check that the summary does not have the user displayed. $node = $this->getNodeByTitle('field_override_test'); $this->drupalPostForm('node/' . $node->id() . '/edit', [], 'field_paragraphs_0_collapse'); - $this->assertRaw('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">This is a test'); + $this->assertSession()->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">This is a test'); } /** @@ -236,8 +236,8 @@ public function testCollapsedSummary() { $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_nested_paragraph_add_more'); $this->drupalPostForm(NULL, [], 'field_paragraphs_1_subform_paragraphs_text_paragraph_add_more'); - $this->assertField('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]'); - $this->assertField('field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]'); + $this->assertSession()->fieldExists('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]'); + $this->assertSession()->fieldExists('field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]'); $edit = [ 'title[0][value]' => 'collapsed_test', @@ -251,13 +251,13 @@ public function testCollapsedSummary() { $this->clickLink('Edit'); // Assert that info section includes the information from behavior plugins. - $this->assertFieldByXPath('//*[@id="edit-field-paragraphs-0-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]'); - $this->assertFieldByXPath('//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-badge" and @title="1 child"]'); - $this->assertFieldByXPath('//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]'); + $this->assertSession()->elementExists('xpath', '//*[@id="edit-field-paragraphs-0-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]'); + $this->assertSession()->elementExists('xpath', '//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-badge" and @title="1 child"]'); + $this->assertSession()->elementExists('xpath', '//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]'); // Assert that the summary includes the text of the behavior plugins. - $this->assertRaw('first_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span><span class="summary-plugin"><span class="summary-plugin-label">Text color</span>blue</span>'); - $this->assertRaw('nested_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span></div></div>'); + $this->assertSession()->responseContains('first_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span><span class="summary-plugin"><span class="summary-plugin-label">Text color</span>blue</span>'); + $this->assertSession()->responseContains('nested_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span></div></div>'); // Add an empty nested paragraph. $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_nested_paragraph_add_more'); @@ -268,7 +268,7 @@ public function testCollapsedSummary() { // Check an empty nested paragraph summary. $this->clickLink('Edit'); - $this->assertRaw('class="paragraphs-description paragraphs-collapsed-description">'); + $this->assertSession()->responseContains('class="paragraphs-description paragraphs-collapsed-description">'); } @@ -329,7 +329,7 @@ public function testBehaviorSubform() { ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->clickLink('Edit'); - $this->assertFieldByName('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'red'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'red'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalConfigTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalConfigTest.php index 252b63923c0dc6392863f3c1013089acc17da78f..1e044b26d93704116fe8d6944fd881ca57ce117d 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalConfigTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalConfigTest.php @@ -62,7 +62,7 @@ public function testFieldTranslationDisabled() { $this->clickLink(t('Add')); // Save the translation. $this->drupalPostForm(NULL, [], t('Save (this translation)')); - $this->assertText('paragraphed_test paragraphed_title has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_test paragraphed_title has been updated.'); } /** @@ -78,13 +78,13 @@ public function testContentTranslationForm() { // Check warning message is displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); $this->addParagraphedContentType('paragraphed_test'); // Check error message is not displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--error'); // Add a second language. ConfigurableLanguage::create(['id' => 'de'])->save(); @@ -99,12 +99,12 @@ public function testContentTranslationForm() { // Check error message is still not displayed. $this->drupalGet('admin/config/regional/content-language'); - $this->assertText('(* unsupported) Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('(* unsupported) Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--error'); // Check content type field management warning. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs'); - $this->assertText('Paragraphs fields do not support translation.'); + $this->assertSession()->pageTextContains('Paragraphs fields do not support translation.'); // Make the paragraphs field translatable. $edit = [ @@ -116,8 +116,8 @@ public function testContentTranslationForm() { // Check content type field management error. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs'); - $this->assertText('Paragraphs fields do not support translation.'); - $this->assertRaw('<div class="messages messages--error'); + $this->assertSession()->pageTextContains('Paragraphs fields do not support translation.'); + $this->assertSession()->responseContains('<div class="messages messages--error'); // Check a not paragraphs translatable field does not display the message. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field'); @@ -128,8 +128,8 @@ public function testContentTranslationForm() { ]; $this->drupalPostForm(NULL, $edit, t('Save and continue')); $this->drupalPostForm(NULL, [], t('Save field settings')); - $this->assertNoText('Paragraphs fields do not support translation.'); - $this->assertNoRaw('<div class="messages messages--warning'); + $this->assertSession()->pageTextNotContains('Paragraphs fields do not support translation.'); + $this->assertSession()->responseNotContains('<div class="messages messages--warning'); } /** @@ -155,8 +155,8 @@ public function testAvoidUsingParagraphsWithWrongEntity() { 'settings[handler_settings][target_bundles][article]' => 'article', ]); $this->drupalGet('admin/structure/types/manage/article/form-display'); - $this->assertNoOption('edit-fields-field-node-reference-type', 'entity_reference_paragraphs'); - $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs'); + $this->assertSession()->optionNotExists('edit-fields-field-node-reference-type', 'entity_reference_paragraphs'); + $this->assertSession()->optionNotExists('edit-fields-field-node-reference-type', 'paragraphs'); } /** @@ -175,16 +175,16 @@ public function testIncludedParagraphTypes() { 'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1, ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Add paragraph_type_test'); - $this->assertNoText('Add text'); + $this->assertSession()->pageTextContains('Add paragraph_type_test'); + $this->assertSession()->pageTextNotContains('Add text'); $edit = [ 'title[0][value]' => 'Testing included types' ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Testing included types has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Testing included types has been created.'); // Include all types. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs'); @@ -203,7 +203,7 @@ public function testIncludedParagraphTypes() { 'title[0][value]' => 'Testing all excluded types' ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Testing all excluded types has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Testing all excluded types has been created.'); } /** @@ -222,16 +222,16 @@ public function testExcludedParagraphTypes() { 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1, ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); - $this->assertText('Saved paragraphs configuration.'); + $this->assertSession()->pageTextContains('Saved paragraphs configuration.'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('Add paragraph_type_test'); - $this->assertNoText('Add text'); + $this->assertSession()->pageTextContains('Add paragraph_type_test'); + $this->assertSession()->pageTextNotContains('Add text'); $edit = [ 'title[0][value]' => 'Testing excluded types' ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Testing excluded types has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Testing excluded types has been created.'); // Exclude all types. $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs'); @@ -242,11 +242,11 @@ public function testExcludedParagraphTypes() { ]; $this->drupalPostForm(NULL, $edit, 'Save settings'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertText('You are not allowed to add any of the Paragraph types.'); + $this->assertSession()->pageTextContains('You are not allowed to add any of the Paragraph types.'); $edit = [ 'title[0][value]' => 'Testing all excluded types' ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Testing all excluded types has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Testing all excluded types has been created.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContactTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContactTest.php index 9b84214317d34aee13fac4594060422ba4987a97..23c1ac17213b9bb21242304c4fe1e544176b1dc3 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContactTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContactTest.php @@ -41,11 +41,11 @@ public function testContactForm() { $this->drupalGet('contact/test_contact_form'); $this->drupalPostForm(NULL, [], 'paragraphs_paragraphs_contact_add_more'); // Check that the paragraph is displayed. - $this->assertText('paragraphs_contact'); + $this->assertSession()->pageTextContains('paragraphs_contact'); $this->drupalPostForm(NULL, [], 'paragraphs_0_remove'); $elements = $this->xpath('//table[starts-with(@id, :id)]/tbody', [':id' => 'paragraphs-values']); $header = $this->xpath('//table[starts-with(@id, :id)]/thead', [':id' => 'paragraphs-values']); - $this->assertEqual($elements, []); - $this->assertNotEqual($header, []); + $this->assertEquals($elements, []); + $this->assertNotEquals($header, []); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContentModerationTranslationsTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContentModerationTranslationsTest.php index d734de56f940f4cb1f2eebd473c780f3aaea445a..fed2b6e0a62029aa227445ec3b5f362e9b8f80c9 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContentModerationTranslationsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalContentModerationTranslationsTest.php @@ -304,7 +304,9 @@ public function testTranslatableContentEntities() { $assert_session->pageTextContains('Draft paragraph container text EN'); $assert_session->pageTextContains('Untranslatable container draft text'); - entity_get_form_display('node', 'paragraphed_test', 'default') + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + $display_repository->getFormDisplay('node', 'paragraphed_test') ->setComponent('field_paragraphs', [ 'type' => 'paragraphs', 'settings' => [ @@ -317,7 +319,7 @@ public function testTranslatableContentEntities() { ], ]) ->save(); - entity_get_form_display('paragraph', 'container', 'default') + $display_repository->getFormDisplay('paragraph', 'container') ->setComponent('field_paragraphs', [ 'type' => 'paragraphs', 'settings' => [ diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php index ef93e2fc67344442ae11f5447bcbcadece5abccc..bf13604b201d63f8d0c2d425c8c2210a6cde3311 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\paragraphs\Functional\Experimental; +use Drupal\field\Entity\FieldStorageConfig; + /** * Tests paragraphs duplicate feature. * @@ -35,8 +37,6 @@ public function testDuplicateButton() { $this->drupalPostForm(NULL, [], 'field_paragraphs_text_paragraph_add_more'); // Create a node with a Paragraph. - $text_01 = 'recognizable_text_01'; - $text_02 = 'recognizable_text_02'; $edit = [ 'title[0][value]' => 'paragraphs_mode_test', 'field_paragraphs[0][subform][field_text][0][value]' => 'A', @@ -51,14 +51,14 @@ public function testDuplicateButton() { // Click "Duplicate" button on A and move C to the first position. $edit = ['field_paragraphs[2][_weight]' => -1]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_duplicate'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); - $this->assertFieldByName('field_paragraphs[0][_weight]', 1); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'B'); - $this->assertFieldByName('field_paragraphs[1][_weight]', 3); - $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); - $this->assertFieldByName('field_paragraphs[2][_weight]', 0); - $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'A'); - $this->assertFieldByName('field_paragraphs[3][_weight]', 2); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][_weight]', 1); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_text][0][value]', 'B'); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][_weight]', 3); + $this->assertSession()->fieldValueEquals('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertSession()->fieldValueEquals('field_paragraphs[2][_weight]', 0); + $this->assertSession()->fieldValueEquals('field_paragraphs[3][subform][field_text][0][value]', 'A'); + $this->assertSession()->fieldValueEquals('field_paragraphs[3][_weight]', 2); // Move C after the A's and save. $edit = [ @@ -71,10 +71,10 @@ public function testDuplicateButton() { // Save and check if all paragraphs are present in the correct order. $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'A'); - $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); - $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'B'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_text][0][value]', 'A'); + $this->assertSession()->fieldValueEquals('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertSession()->fieldValueEquals('field_paragraphs[3][subform][field_text][0][value]', 'B'); // Delete the second A, then duplicate C. $this->drupalPostForm(NULL, [], 'field_paragraphs_1_remove'); @@ -82,36 +82,36 @@ public function testDuplicateButton() { $this->drupalPostForm(NULL, [], t('Save')); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'C'); - $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); - $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'B'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_text][0][value]', 'C'); + $this->assertSession()->fieldValueEquals('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertSession()->fieldValueEquals('field_paragraphs[3][subform][field_text][0][value]', 'B'); // Check that the duplicate action is present. - $this->assertField('field_paragraphs_0_duplicate'); + $this->assertSession()->buttonExists('field_paragraphs_0_duplicate'); // Disable show duplicate action. $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display'); - $this->assertText('Features: Duplicate, Collapse / Edit all'); + $this->assertSession()->pageTextContains('Features: Duplicate, Collapse / Edit all'); $this->drupalPostForm(NULL, [], 'field_paragraphs_settings_edit'); $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][features][duplicate]' => FALSE], t('Update')); - $this->assertText('Features: Collapse / Edit all'); + $this->assertSession()->pageTextContains('Features: Collapse / Edit all'); $this->drupalPostForm(NULL, [], 'Save'); $this->drupalGet('node/' . $node->id() . '/edit'); // Check that the duplicate action is not present. - $this->assertNoField('field_paragraphs_0_duplicate'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertSession()->buttonNotExists('field_paragraphs_0_duplicate'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'A'); // Enable show duplicate action. $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display'); - $this->assertText('Features: Collapse / Edit all'); + $this->assertSession()->pageTextContains('Features: Collapse / Edit all'); $this->drupalPostForm(NULL, [], 'field_paragraphs_settings_edit'); $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][features][duplicate]' => TRUE], t('Update')); - $this->assertText('Features: Duplicate, Collapse / Edit all'); + $this->assertSession()->pageTextContains('Features: Duplicate, Collapse / Edit all'); $this->drupalPostForm(NULL, [], 'Save'); $this->drupalGet('node/' . $node->id() . '/edit'); // Check that the duplicate action is present. - $this->assertField('field_paragraphs_0_duplicate'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertSession()->buttonExists('field_paragraphs_0_duplicate'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'A'); } /** @@ -160,8 +160,8 @@ public function testDuplicateButtonWithNesting() { // Click "Duplicate" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_duplicate'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]', $text); - $this->assertFieldByName('field_paragraphs[1][subform][field_nested][0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[1][subform][field_nested][0][subform][field_text][0][value]', $text); // Change the text paragraph value of duplicated nested paragraph. $second_paragraph_text = 'duplicated_text'; @@ -172,8 +172,46 @@ public function testDuplicateButtonWithNesting() { // Save and check if the changed text paragraph value of the duplicated // paragraph is not the same as in the original paragraph. $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertUniqueText($text); - $this->assertUniqueText($second_paragraph_text); + + $page_text = $this->getSession()->getPage()->getText(); + $text_nr_found = substr_count($page_text, $text); + $this->assertSame(1, $text_nr_found); + + $page_text = $this->getSession()->getPage()->getText(); + $second_paragraph_text_nr_found = substr_count($page_text, $second_paragraph_text); + $this->assertSame(1, $second_paragraph_text_nr_found); + + } + + /** + * Tests duplicate paragraph feature for fields with a limited cardinality. + */ + public function testDuplicateButtonWithLimitedCardinality() { + $this->addParagraphedContentType('paragraphed_test'); + /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */ + $field_storage = FieldStorageConfig::load('node.field_paragraphs'); + $field_storage->setCardinality(2)->save(); + + $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']); + // Add a Paragraph type. + $paragraph_type = 'text_paragraph'; + $this->addParagraphsType($paragraph_type); + + // Add a text field to the text_paragraph type. + static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []); + $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_add_more'); + + $edit = [ + 'title[0][value]' => 'paragraphs_mode_test', + 'field_paragraphs[0][subform][field_text][0][value]' => 'A', + 'field_paragraphs[1][subform][field_text][0][value]' => 'B', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $node = $this->drupalGetNodeByTitle('paragraphs_mode_test'); + + $this->drupalGet('node/' . $node->id() . '/edit'); + $this->assertNoField('field_paragraphs_0_duplicate'); + $this->assertNoField('field_paragraphs_1_duplicate'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEditModesTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEditModesTest.php index 590d27dc6b3bc6f56535ff706fcf7dd1ac676ee0..6db5857c76c83af38220acedf33880486ae0f5a7 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEditModesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEditModesTest.php @@ -75,9 +75,9 @@ public function testCollapsedSummary() { // Assert the summary is correctly generated. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">' . $files[0]->filename . '</span>, <span class="summary-content">text_summary</span>'); - $this->assertRaw('<span class="summary-content">' . $this->admin_user->label()); - $this->assertRaw('<span class="summary-content">Title example'); + $this->assertSession()->responseContains('<span class="summary-content">' . $files[0]->filename . '</span>, <span class="summary-content">text_summary</span>'); + $this->assertSession()->responseContains('<span class="summary-content">' . $this->admin_user->label()); + $this->assertSession()->responseContains('<span class="summary-content">Title example'); // Edit and remove alternative text. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); @@ -86,7 +86,7 @@ public function testCollapsedSummary() { ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); // Assert the summary is correctly generated. - $this->assertRaw('<span class="summary-content">alternative_text_summary</span>, <span class="summary-content">text_summary</span>'); + $this->assertSession()->responseContains('<span class="summary-content">alternative_text_summary</span>, <span class="summary-content">text_summary</span>'); // Remove image. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); @@ -95,7 +95,7 @@ public function testCollapsedSummary() { // Assert the summary is correctly generated. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">text_summary'); + $this->assertSession()->responseContains('<span class="summary-content">text_summary'); $this->addParagraphsType('nested_paragraph'); static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_paragraph', 'nested_content', 'Nested Content', 'entity_reference_revisions', ['settings[target_type]' => 'paragraph'], []); @@ -120,7 +120,7 @@ public function testCollapsedSummary() { $this->drupalGet('node/' . current($nodes)->id() . '/edit'); $this->drupalPostForm(NULL, [], t('field_paragraphs_0_edit')); $this->drupalPostForm(NULL, [], t('field_paragraphs_0_collapse')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Add a Block Paragraphs type. $this->addParagraphsType('block_paragraph'); @@ -141,7 +141,7 @@ public function testCollapsedSummary() { 'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'block_content:' . $after_block2->uuid(), ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); - $this->assertRaw('<span class="summary-content">Llama custom block'); + $this->assertSession()->responseContains('<span class="summary-content">Llama custom block'); $edit = ['title[0][value]' => 'Test llama block']; $this->drupalPostForm(NULL, $edit, t('Save')); // Delete the block. @@ -149,7 +149,7 @@ public function testCollapsedSummary() { // Attempt to edit the node when the node is deleted. $node = $this->getNodeByTitle('Test llama block'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Test the summary of a Block field. $paragraph_type = 'link_paragraph'; @@ -164,7 +164,7 @@ public function testCollapsedSummary() { $this->drupalPostForm(NULL, $edit, t('Save')); // Check the summary when no link title is provided. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">http://www.google.com'); + $this->assertSession()->responseContains('<span class="summary-content">http://www.google.com'); // Set a link title. $this->drupalPostForm(NULL, NULL, 'field_paragraphs_0_edit'); $edit = [ @@ -173,7 +173,7 @@ public function testCollapsedSummary() { $this->drupalPostForm(NULL, $edit, t('Save')); // Check the summary when the link title is set. $this->clickLink(t('Edit')); - $this->assertRaw('<span class="summary-content">Link title'); + $this->assertSession()->responseContains('<span class="summary-content">Link title'); // Allow the user to select if the paragraphs is published or not. $edit = [ @@ -196,11 +196,11 @@ public function testCollapsedSummary() { 'field_paragraphs[0][subform][status][value]' => FALSE, ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertNoText('memorable_summary_title'); + $this->assertSession()->pageTextNotContains('memorable_summary_title'); $node = $this->getNodeByTitle('Access summary test'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('<span class="summary-content">memorable_summary_title'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); + $this->assertSession()->responseContains('<span class="summary-content">memorable_summary_title'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); $this->drupalPostForm('node/add/paragraphed_test', [], 'field_paragraphs_nested_paragraph_add_more'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_subform_field_nested_content_title_add_more'); @@ -214,15 +214,15 @@ public function testCollapsedSummary() { 'field_paragraphs[0][subform][field_nested_content][0][subform][field_title][0][value]' => 'memorable_nested_summary_title', ]; $this->drupalPostForm(NULL, $edit, 'Save'); - $this->assertNoText('memorable_nested_summary_title'); + $this->assertSession()->pageTextNotContains('memorable_nested_summary_title'); $node = $this->getNodeByTitle('Access nested summary test'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('<span class="summary-content">memorable_nested_summary_title'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); + $this->assertSession()->responseContains('<span class="summary-content">memorable_nested_summary_title'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_subform_field_nested_content_0_collapse'); - $this->assertRaw('<span class="summary-content">memorable_nested_summary_title'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); + $this->assertSession()->responseContains('<span class="summary-content">memorable_nested_summary_title'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); // Assert the unpublished icon. $permissions = [ @@ -230,12 +230,12 @@ public function testCollapsedSummary() { ]; $this->loginAsAdmin($permissions); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertRaw('<span class="summary-content">memorable_nested_summary_title'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); + $this->assertSession()->responseContains('<span class="summary-content">memorable_nested_summary_title'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_subform_field_nested_content_0_collapse'); - $this->assertRaw('<span class="summary-content">memorable_nested_summary_title'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); + $this->assertSession()->responseContains('<span class="summary-content">memorable_nested_summary_title'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-view')]"))); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEntityTranslationWithNonTranslatableParagraphs.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEntityTranslationWithNonTranslatableParagraphs.php index 7465b193b88404374829d10f94650238eba0ea8d..766535c702bd01bde8757db34815aef616a8439a 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEntityTranslationWithNonTranslatableParagraphs.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalEntityTranslationWithNonTranslatableParagraphs.php @@ -85,25 +85,25 @@ public function testParagraphsIEFTranslation() { $this->clickLink(t('Translate')); $this->clickLink(t('Add'), 1); // Make sure that the original paragraph text is displayed. - $this->assertText('Title English'); + $this->assertSession()->pageTextContains('Title English'); $edit = array( 'title[0][value]' => 'Title French', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('article Title French has been updated.'); + $this->assertSession()->pageTextContains('article Title French has been updated.'); // Add german translation. $this->clickLink(t('Translate')); $this->clickLink(t('Add')); // Make sure that the original paragraph text is displayed. - $this->assertText('Title English'); + $this->assertSession()->pageTextContains('Title English'); $edit = array( 'title[0][value]' => 'Title German', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('article Title German has been updated.'); + $this->assertSession()->pageTextContains('article Title German has been updated.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalFieldGroupTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalFieldGroupTest.php index 26c91310190672f56874be28d0e5628c5cb0a81c..a80cbd0ed1d26d0c2446aff8e47f398232539bb9 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalFieldGroupTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalFieldGroupTest.php @@ -59,8 +59,8 @@ public function testFieldGroup() { $this->drupalPostForm('node/add/' . $content_type, [], 'field_paragraphs_paragraph_type_test_add_more'); // Test if the new field group is displayed. - $this->assertText('field_group'); - $this->assertFieldByXPath("//fieldset", NULL, t('Fieldset present')); + $this->assertSession()->pageTextContains('field_group'); + $this->assertSession()->elementExists('css', 'fieldset'); // Save the node. $edit = [ diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalHeaderActionsTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalHeaderActionsTest.php index 9e6d0b7444815b48012306f4eed4b8ee55df38e6..cf8063d59701fd7cdaeede00ea27fb3a91f14514 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalHeaderActionsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalHeaderActionsTest.php @@ -53,18 +53,18 @@ public function testHeaderActions() { // Add 2 paragraphs and check for Collapse/Edit all button. $this->drupalGet('node/add/paragraphed_test'); - $this->assertNoRaw('field_paragraphs_collapse_all'); - $this->assertNoRaw('field_paragraphs_edit_all'); - $this->assertRaw('field_paragraphs_dragdrop_mode'); + $this->assertSession()->responseNotContains('field_paragraphs_collapse_all'); + $this->assertSession()->responseNotContains('field_paragraphs_edit_all'); + $this->assertSession()->responseContains('field_paragraphs_dragdrop_mode'); // Ensure there is only a single table row. $table_rows = $this->xpath('//table[contains(@class, :class)]/tbody/tr', [':class' => 'field-multiple-table']); - $this->assertEqual(1, count($table_rows)); + $this->assertEquals(1, count($table_rows)); // Add second paragraph and check for Collapse/Edit all button. $this->drupalPostForm(NULL, [], 'field_paragraphs_text_paragraph_add_more'); - $this->assertRaw('field_paragraphs_collapse_all'); - $this->assertRaw('field_paragraphs_edit_all'); + $this->assertSession()->responseContains('field_paragraphs_collapse_all'); + $this->assertSession()->responseContains('field_paragraphs_edit_all'); $edit = [ 'field_paragraphs[0][subform][field_text][0][value]' => 'First text', @@ -73,24 +73,24 @@ public function testHeaderActions() { $this->drupalPostForm(NULL, $edit, 'Collapse all'); // Checks that after collapsing all we can edit again these paragraphs. - $this->assertRaw('field_paragraphs_0_edit'); - $this->assertRaw('field_paragraphs_1_edit'); + $this->assertSession()->responseContains('field_paragraphs_0_edit'); + $this->assertSession()->responseContains('field_paragraphs_1_edit'); // Test Edit all button. $this->drupalPostForm(NULL, [], 'field_paragraphs_edit_all'); - $this->assertRaw('field_paragraphs_0_collapse'); - $this->assertRaw('field_paragraphs_1_collapse'); + $this->assertSession()->responseContains('field_paragraphs_0_collapse'); + $this->assertSession()->responseContains('field_paragraphs_1_collapse'); $edit = [ 'title[0][value]' => 'Test', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Test has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Test has been created.'); $node = $this->getNodeByTitle('Test'); $this->drupalGet('node/' . $node->id()); $this->clickLink('Edit'); - $this->assertNoText('No Paragraph added yet.'); + $this->assertSession()->pageTextNotContains('No Paragraph added yet.'); // Add and remove another paragraph. $this->drupalPostForm(NULL, [], 'field_paragraphs_text_paragraph_add_more'); @@ -102,26 +102,26 @@ public function testHeaderActions() { // Check that pressing "Collapse all" does not restore the removed // paragraph. $this->drupalPostForm(NULL, [], 'field_paragraphs_edit_all'); - $this->assertText('First text'); - $this->assertText('Second text'); - $this->assertNoText('Third text'); + $this->assertSession()->pageTextContains('First text'); + $this->assertSession()->pageTextContains('Second text'); + $this->assertSession()->pageTextNotContains('Third text'); // Check that pressing "Edit all" does not restore the removed paragraph, // either. $this->drupalPostForm(NULL, [], 'field_paragraphs_collapse_all'); - $this->assertText('First text'); - $this->assertText('Second text'); - $this->assertNoText('Third text'); - $this->assertField('field_paragraphs_collapse_all'); - $this->assertField('field_paragraphs_edit_all'); + $this->assertSession()->pageTextContains('First text'); + $this->assertSession()->pageTextContains('Second text'); + $this->assertSession()->pageTextNotContains('Third text'); + $this->assertSession()->buttonExists('field_paragraphs_collapse_all'); + $this->assertSession()->buttonExists('field_paragraphs_edit_all'); $this->drupalPostForm(NULL, [], t('Save')); // Check that the drag and drop button is present when there is a paragraph // and that it is not shown when the paragraph is deleted. $this->drupalGet('node/add/paragraphed_test'); - $this->assertRaw('name="field_paragraphs_dragdrop_mode"'); + $this->assertSession()->responseContains('name="field_paragraphs_dragdrop_mode"'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); - $this->assertNoRaw('name="field_paragraphs_dragdrop_mode"'); + $this->assertSession()->responseNotContains('name="field_paragraphs_dragdrop_mode"'); // Disable show multiple actions. $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display'); @@ -130,9 +130,9 @@ public function testHeaderActions() { $this->drupalPostForm(NULL, [], 'Save'); $this->drupalGet('node/' . $node->id() . '/edit'); // Check that the collapse/edit all actions are not present. - $this->assertNoField('field_paragraphs_collapse_all'); - $this->assertNoField('field_paragraphs_edit_all'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'First text'); + $this->assertSession()->buttonNotExists('field_paragraphs_collapse_all'); + $this->assertSession()->buttonNotExists('field_paragraphs_edit_all'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'First text'); // Enable show "Collapse / Edit all" actions. $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display'); @@ -141,9 +141,9 @@ public function testHeaderActions() { $this->drupalPostForm(NULL, [], 'Save'); $this->drupalGet('node/' . $node->id() . '/edit'); // Check that the collapse/edit all actions are present. - $this->assertField('field_paragraphs_collapse_all'); - $this->assertField('field_paragraphs_edit_all'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'First text'); + $this->assertSession()->buttonExists('field_paragraphs_collapse_all'); + $this->assertSession()->buttonExists('field_paragraphs_edit_all'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', 'First text'); } /** @@ -193,33 +193,33 @@ public function testHeaderActionsWithNesting() { $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, [], 'field_paragraphs_nested_paragraph_add_more'); $this->drupalPostForm(NULL, [], 'field_paragraphs_text_add_more'); - $this->assertRaw('field_paragraphs_collapse_all'); - $this->assertRaw('field_paragraphs_edit_all'); + $this->assertSession()->responseContains('field_paragraphs_collapse_all'); + $this->assertSession()->responseContains('field_paragraphs_edit_all'); $this->drupalPostForm(NULL, [], 'field_paragraphs_text_add_more'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_subform_field_nested_text_add_more'); - $this->assertNoRaw('field_paragraphs_0_collapse_all'); - $this->assertNoRaw('field_paragraphs_0_edit_all'); + $this->assertSession()->responseNotContains('field_paragraphs_0_collapse_all'); + $this->assertSession()->responseNotContains('field_paragraphs_0_edit_all'); $edit = [ 'field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]' => 'Nested text', 'field_paragraphs[1][subform][field_text][0][value]' => 'Second text paragraph', ]; $this->drupalPostForm(NULL, $edit, 'Collapse all'); - $this->assertRaw('field-paragraphs-0-edit'); - $this->assertFieldByXPath((new CssSelectorConverter())->toXPath('[name="field_paragraphs_1_edit"] + .paragraphs-dropdown')); + $this->assertSession()->responseContains('field-paragraphs-0-edit'); + $this->assertSession()->elementExists('css', '[name="field_paragraphs_1_edit"] + .paragraphs-dropdown'); $this->drupalPostForm(NULL, [], 'field_paragraphs_edit_all'); - $this->assertRaw('field-paragraphs-0-collapse'); + $this->assertSession()->responseContains('field-paragraphs-0-collapse'); $edit = [ 'title[0][value]' => 'Test', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Test has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Test has been created.'); $node = $this->getNodeByTitle('Test'); $this->drupalGet('node/' . $node->id()); $this->clickLink('Edit'); - $this->assertNoText('No Paragraph added yet.'); + $this->assertSession()->pageTextNotContains('No Paragraph added yet.'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_subform_field_nested_text_add_more'); $edit = [ @@ -227,8 +227,8 @@ public function testHeaderActionsWithNesting() { ]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); - $this->assertRaw('field_paragraphs_0_subform_field_nested_collapse_all'); - $this->assertRaw('field_paragraphs_0_subform_field_nested_edit_all'); + $this->assertSession()->responseContains('field_paragraphs_0_subform_field_nested_collapse_all'); + $this->assertSession()->responseContains('field_paragraphs_0_subform_field_nested_edit_all'); } /** @@ -275,10 +275,10 @@ public function testHeaderActionsWithMultiFields() { $this->drupalPostForm(NULL, [], 'field_second_text_paragraph_add_more'); // Checks that we have Collapse\Edit all for each field. - $this->assertRaw('field_paragraphs_collapse_all'); - $this->assertRaw('field_paragraphs_edit_all'); - $this->assertRaw('field_second_collapse_all'); - $this->assertRaw('field_second_edit_all'); + $this->assertSession()->responseContains('field_paragraphs_collapse_all'); + $this->assertSession()->responseContains('field_paragraphs_edit_all'); + $this->assertSession()->responseContains('field_second_collapse_all'); + $this->assertSession()->responseContains('field_second_edit_all'); $edit = [ 'field_second[0][subform][field_text][0][value]' => 'Second field', @@ -286,26 +286,26 @@ public function testHeaderActionsWithMultiFields() { $this->drupalPostForm(NULL, $edit, 'field_second_collapse_all'); // Checks that we collapsed only children from second field. - $this->assertNoRaw('field_paragraphs_0_edit'); - $this->assertRaw('field_second_0_edit'); + $this->assertSession()->responseNotContains('field_paragraphs_0_edit'); + $this->assertSession()->responseContains('field_second_0_edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_collapse_all'); - $this->assertRaw('field_paragraphs_0_edit'); - $this->assertRaw('field_second_0_edit'); + $this->assertSession()->responseContains('field_paragraphs_0_edit'); + $this->assertSession()->responseContains('field_second_0_edit'); $this->drupalPostForm(NULL, [], 'field_second_edit_all'); - $this->assertRaw('field_second_0_collapse'); + $this->assertSession()->responseContains('field_second_0_collapse'); $edit = [ 'title[0][value]' => 'Test', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test Test has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test Test has been created.'); $node = $this->getNodeByTitle('Test'); $this->drupalGet('node/' . $node->id()); $this->clickLink('Edit'); - $this->assertNoText('No Paragraph added yet.'); + $this->assertSession()->pageTextNotContains('No Paragraph added yet.'); } /** @@ -342,7 +342,7 @@ function testHeaderActionsWhileTranslating() { $this->drupalGet('node/add/paragraphed_test'); // Assert that the drag and drop button is present. - $this->assertRaw('name="field_paragraphs_dragdrop_mode"'); + $this->assertSession()->responseContains('name="field_paragraphs_dragdrop_mode"'); $edit = [ 'title[0][value]' => 'Title', 'field_paragraphs[0][subform][field_text][0][value]' => 'First', @@ -351,8 +351,8 @@ function testHeaderActionsWhileTranslating() { $this->clickLink('Translate'); $this->clickLink('Add'); // Assert that the drag and drop button is not present while translating. - $this->assertNoRaw('name="field_paragraphs_dragdrop_mode"'); - $this->assertText('First'); + $this->assertSession()->responseNotContains('name="field_paragraphs_dragdrop_mode"'); + $this->assertSession()->pageTextContains('First'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalPreviewTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalPreviewTest.php index 4e80a4a51cc3b428d22419f6e956df833ea82a87..c94aabdee41abdc25ac5b81c9f51dcbe521505bc 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalPreviewTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalPreviewTest.php @@ -38,7 +38,7 @@ public function testParagraphsPreview() { $this->addParagraphsType('text'); // Create field types for the text. $this->fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array()); - $this->assertText('Saved Text configuration.'); + $this->assertSession()->pageTextContains('Saved Text configuration.'); $test_text_1 = 'dummy_preview_text_1'; $test_text_2 = 'dummy_preview_text_2'; @@ -53,17 +53,19 @@ public function testParagraphsPreview() { // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); // Check if the text is displayed. - $this->assertRaw($test_text_1); + $this->assertSession()->responseContains($test_text_1); // Check that the parent is set correctly on all paragraphs. - $this->assertNoText('Parent: //'); - $this->assertNoUniqueText('Parent: node//field_paragraphs'); + $this->assertSession()->pageTextNotContains('Parent: //'); + $page_text = $this->getSession()->getPage()->getText(); + $nr_found = substr_count($page_text, 'Parent: node//field_paragraphs'); + $this->assertGreaterThan(1, $nr_found); // Go back to the editing form. $this->clickLink('Back to content editing'); $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0]; - $this->assertEqual($paragraph_1->getValue(), $test_text_1); + $this->assertEquals($paragraph_1->getValue(), $test_text_1); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -74,8 +76,8 @@ public function testParagraphsPreview() { ]; // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); - $this->assertRaw($test_text_1); - $this->assertRaw($test_text_2); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($test_text_2); // Go back to the editing form. $this->clickLink('Back to content editing'); @@ -86,24 +88,26 @@ public function testParagraphsPreview() { ]; // Preview the article. $this->drupalPostForm(NULL, $edit, t('Preview')); - $this->assertRaw($test_text_1); - $this->assertRaw($new_test_text_2); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($new_test_text_2); // Check that the parent is set correctly on all paragraphs. - $this->assertNoText('Parent: //'); - $this->assertNoUniqueText('Parent: node/1/field_paragraphs'); + $this->assertSession()->pageTextNotContains('Parent: //'); + $page_text = $this->getSession()->getPage()->getText(); + $nr_found = substr_count($page_text, 'Parent: node/1/field_paragraphs'); + $this->assertGreaterThan(1, $nr_found); // Go back to the editing form. $this->clickLink('Back to content editing'); $paragraph_1 = $this->xpath('//*[@id="edit-field-paragraphs-0-subform-field-text-0-value"]')[0]; $paragraph_2 = $this->xpath('//*[@id="edit-field-paragraphs-1-subform-field-text-0-value"]')[0]; - $this->assertEqual($paragraph_1->getValue(), $test_text_1); - $this->assertEqual($paragraph_2->getValue(), $new_test_text_2); + $this->assertEquals($paragraph_1->getValue(), $test_text_1); + $this->assertEquals($paragraph_2->getValue(), $new_test_text_2); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertRaw($test_text_1); - $this->assertRaw($new_test_text_2); - $this->assertRaw('Page_title'); + $this->assertSession()->responseContains($test_text_1); + $this->assertSession()->responseContains($new_test_text_2); + $this->assertSession()->responseContains('Page_title'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalSummaryFormatterTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalSummaryFormatterTest.php index c02b7c805d1e1b45e074430dff4956efad9d5198..8402f6e31059a24f1a4c043e20a354a4600ac76e 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalSummaryFormatterTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalSummaryFormatterTest.php @@ -61,8 +61,8 @@ public function testParagraphsSummaryFormatter() { $this->drupalPostForm(NULL, $edit, t('Save')); // Assert the summary is correctly generated. - $this->assertText($this->admin_user->label()); - $this->assertText('Title example'); + $this->assertSession()->pageTextContains($this->admin_user->label()); + $this->assertSession()->pageTextContains('Title example'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTestBase.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTestBase.php index 389d461b72276034f415d089773c45bbeb0e894e..681658117d586580f513173a998718beea0fd871 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTestBase.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTestBase.php @@ -41,7 +41,7 @@ protected function setAddMode($content_type, $paragraphs_field, $mode) { protected function removeDefaultParagraphType($content_type) { $this->drupalGet('node/add/' . $content_type); $this->drupalPostForm(NULL, [], 'Remove'); - $this->assertNoText('No paragraphs added yet.'); + $this->assertSession()->pageTextNotContains('No paragraphs added yet.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTranslationTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTranslationTest.php index 5b0bbd6cc8f71839e7c666572d415111e49941bb..cd34ddf56087402ab488d9e3349f66919cbc71e9 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTranslationTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTranslationTest.php @@ -98,11 +98,11 @@ public function testParagraphTranslation() { $this->drupalGet('admin/config/regional/content-language'); // Check the settings are saved correctly. - $this->assertFieldChecked('edit-entity-types-paragraph'); - $this->assertFieldChecked('edit-settings-node-paragraphed-content-demo-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-text-image-translatable'); - $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-alt'); - $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-title'); + $this->assertSession()->checkboxChecked('edit-entity-types-paragraph'); + $this->assertSession()->checkboxChecked('edit-settings-node-paragraphed-content-demo-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-text-image-translatable'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-images-columns-field-images-demo-alt'); + $this->assertSession()->checkboxChecked('edit-settings-paragraph-images-columns-field-images-demo-title'); // Check if the publish/unpublish option works. $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display'); @@ -125,13 +125,13 @@ public function testParagraphTranslation() { $this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add text_image')); - $this->assertRaw('edit-field-paragraphs-demo-0-subform-status-value'); + $this->assertSession()->responseContains('edit-field-paragraphs-demo-0-subform-status-value'); $edit = [ 'title[0][value]' => 'example_publish_unpublish', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Example published and unpublished', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('Example published and unpublished')); + $this->assertSession()->pageTextContains(t('Example published and unpublished')); $this->clickLink(t('Edit')); $this->drupalPostForm(NULL, NULL, 'field_paragraphs_demo_nested_paragraph_add_more'); @@ -141,7 +141,7 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[1][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'Dummy text' ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertNoText(t('Example published and unpublished')); + $this->assertSession()->pageTextNotContains(t('Example published and unpublished')); // Check the parent fields are set properly. Get the node. $node = $this->drupalGetNodeByTitle('example_publish_unpublish'); @@ -149,16 +149,16 @@ public function testParagraphTranslation() { foreach ($node->field_paragraphs_demo->referencedEntities() as $paragraph) { $node_paragraph = Paragraph::load($paragraph->id())->toArray(); // Check if the fields are set properly. - $this->assertEqual($node_paragraph['parent_id'][0]['value'], $node->id()); - $this->assertEqual($node_paragraph['parent_type'][0]['value'], 'node'); - $this->assertEqual($node_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); + $this->assertEquals($node_paragraph['parent_id'][0]['value'], $node->id()); + $this->assertEquals($node_paragraph['parent_type'][0]['value'], 'node'); + $this->assertEquals($node_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); // If the paragraph is nested type load the child. if ($node_paragraph['type'][0]['target_id'] == 'nested_paragraph') { $nested_paragraph = Paragraph::load($node_paragraph['field_paragraphs_demo'][0]['target_id'])->toArray(); // Check if the fields are properly set. - $this->assertEqual($nested_paragraph['parent_id'][0]['value'], $paragraph->id()); - $this->assertEqual($nested_paragraph['parent_type'][0]['value'], 'paragraph'); - $this->assertEqual($nested_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); + $this->assertEquals($nested_paragraph['parent_id'][0]['value'], $paragraph->id()); + $this->assertEquals($nested_paragraph['parent_type'][0]['value'], 'paragraph'); + $this->assertEquals($nested_paragraph['parent_field_name'][0]['value'], 'field_paragraphs_demo'); } } @@ -170,22 +170,22 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Text in english', ); // The button to remove a paragraph is present. - $this->assertRaw(t('Remove')); + $this->assertSession()->responseContains(t('Remove')); $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('Title in english'); // The text is present when editing again. $this->clickLink(t('Edit')); - $this->assertText('Title in english'); - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); // Add french translation. $this->clickLink(t('Translate')); $this->clickLink(t('Add'), 1); // Make sure the Add / Remove paragraph buttons are hidden. - $this->assertNoRaw(t('Remove')); - $this->assertNoRaw(t('Add text_image')); + $this->assertSession()->responseNotContains(t('Remove')); + $this->assertSession()->responseNotContains(t('Add text_image')); // Make sure that the original paragraph text is displayed. - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Text in english'); $edit = array( 'title[0][value]' => 'Title in french', @@ -194,24 +194,24 @@ public function testParagraphTranslation() { 'revision_log[0][value]' => 'french 1', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('paragraphed_content_demo Title in french has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in french has been updated.'); // Check the english translation. $this->drupalGet('node/' . $node->id()); - $this->assertText('Title in english'); - $this->assertText('Text in english'); - $this->assertNoText('Title in french'); - $this->assertNoText('Text in french'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); + $this->assertSession()->pageTextNotContains('Title in french'); + $this->assertSession()->pageTextNotContains('Text in french'); // Check the french translation. $this->drupalGet('fr/node/' . $node->id()); - $this->assertText('Title in french'); - $this->assertText('Text in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // The translation is still present when editing again. $this->clickLink(t('Edit')); - $this->assertText('Title in french'); - $this->assertText('Text in french'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); $edit = array( 'title[0][value]' => 'Title Change in french', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'New text in french', @@ -219,17 +219,17 @@ public function testParagraphTranslation() { 'revision_log[0][value]' => 'french 2', ); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertText('Title Change in french'); - $this->assertText('New text in french'); + $this->assertSession()->pageTextContains('Title Change in french'); + $this->assertSession()->pageTextContains('New text in french'); // Back to the source language. $this->drupalGet('node/' . $node->id()); $this->clickLink(t('Edit')); - $this->assertText('Title in english'); - $this->assertText('Text in english'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextContains('Text in english'); // Save the original content on second request. $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('paragraphed_content_demo Title in english has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in english has been updated.'); // Test if reverting to old paragraphs revisions works, make sure that // the reverted node can be saved again. @@ -237,17 +237,17 @@ public function testParagraphTranslation() { $this->clickLink(t('Revert')); $this->drupalPostForm(NULL, ['revert_untranslated_fields' => TRUE], t('Revert')); $this->clickLink(t('Edit')); - $this->assertRaw('Title in french'); - $this->assertText('Text in french'); + $this->assertSession()->responseContains('Title in french'); + $this->assertSession()->pageTextContains('Text in french'); $this->drupalPostForm(NULL, [], t('Save (this translation)')); - $this->assertNoRaw('The content has either been modified by another user, or you have already submitted modifications'); - $this->assertText('Text in french'); + $this->assertSession()->responseNotContains('The content has either been modified by another user, or you have already submitted modifications'); + $this->assertSession()->pageTextContains('Text in french'); //Add paragraphed content with untranslatable language $this->drupalGet('node/add/paragraphed_content_demo'); $edit = array('langcode[0][value]' => LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->drupalPostForm(NULL, $edit, t('Add text_image')); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Make 'Images' paragraph field translatable, enable alt and title fields. $this->drupalGet('admin/structure/paragraphs_type/images/fields'); @@ -282,7 +282,7 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[0][subform][field_images_demo][0][title]' => 'Image title FR', ]; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); - $this->assertRaw('Title FR'); + $this->assertSession()->responseContains('Title FR'); $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, [], t('Add text')); @@ -325,17 +325,17 @@ public function testParagraphTranslation() { ]); $this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_content_demo ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo ' . $node->label() . ' has been updated.'); // Check that first paragraph langcode has been updated. \Drupal::entityTypeManager()->getStorage('paragraph')->resetCache([$paragraph_1->id(), $paragraph_2->id()]); $paragraph = Paragraph::load($paragraph_1->id()); - $this->assertEqual($paragraph->language()->getId(), 'de'); + $this->assertEquals($paragraph->language()->getId(), 'de'); $this->assertFalse($paragraph->hasTranslation('en')); // Check that second paragraph has two translations. $paragraph = Paragraph::load($paragraph_2->id()); $this->assertTrue($paragraph->hasTranslation('de')); $this->assertTrue($paragraph->hasTranslation('en')); - $this->assertRaw('german_text'); + $this->assertSession()->responseContains('german_text'); // Create an english translation of the node. $edit = [ @@ -346,12 +346,12 @@ public function testParagraphTranslation() { // Attempt to create a french translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); // Check that the german translation of the paragraphs is displayed. - $this->assertFieldByName('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_text_1'); - $this->assertFieldByName('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'german_text_2'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_text_1'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'german_text_2'); $this->drupalPostForm(NULL, ['source_langcode[source]' => 'en'], t('Change')); // Check that the english translation of the paragraphs is displayed. - $this->assertFieldByName('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_translation_1'); - $this->assertFieldByName('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'english_translation_2'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[0][subform][field_text_demo][0][value]', 'english_translation_1'); + $this->assertSession()->fieldValueEquals('field_paragraphs_demo[1][subform][field_text_demo][0][value]', 'english_translation_2'); // Create a node with empty Paragraphs. $this->drupalGet('node/add/paragraphed_content_demo'); @@ -362,7 +362,7 @@ public function testParagraphTranslation() { $this->clickLink(t('Translate')); $this->clickLink(t('Add')); // Check the add button is not displayed. - $this->assertEqual(count($this->xpath('//*[@name="field_paragraphs_demo_0_subform_field_paragraphs_demo_images_add_more"]')), 0); + $this->assertEquals(count($this->xpath('//*[@name="field_paragraphs_demo_0_subform_field_paragraphs_demo_images_add_more"]')), 0); // Add a non translatable field to Text Paragraph type. $edit = [ @@ -396,10 +396,10 @@ public function testParagraphTranslation() { // Attempt to add a translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); - $this->assertText('untranslatable_field (all languages)'); - $this->assertText('untranslatable_ref_field (all languages)'); - $this->assertText('untranslatable_link_field (all languages)'); - $this->assertNoText('Text (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_field (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_ref_field (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_link_field (all languages)'); + $this->assertSession()->pageTextNotContains('Text (all languages)'); // Enable translations for the reference and link field. $edit = [ @@ -410,10 +410,10 @@ public function testParagraphTranslation() { // Attempt to add a translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); - $this->assertText('untranslatable_field (all languages)'); - $this->assertNoText('untranslatable_link_field (all languages)'); - $this->assertNoText('untranslatable_ref_field (all languages)'); - $this->assertNoText('Text (all languages)'); + $this->assertSession()->pageTextContains('untranslatable_field (all languages)'); + $this->assertSession()->pageTextNotContains('untranslatable_link_field (all languages)'); + $this->assertSession()->pageTextNotContains('untranslatable_ref_field (all languages)'); + $this->assertSession()->pageTextNotContains('Text (all languages)'); // Test the summary in multilingual scenarios. // Case 1: Nested Paragraphs. @@ -430,7 +430,7 @@ public function testParagraphTranslation() { 'field_paragraphs_demo[1][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'EN nested text llama', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_content_demo EN llama has been created.'); + $this->assertSession()->pageTextContains('paragraphed_content_demo EN llama has been created.'); // Create a german translation. $node = $this->drupalGetNodeByTitle('EN llama'); $this->drupalGet('node/' . $node->id() . '/translations/add/en/de'); @@ -443,9 +443,9 @@ public function testParagraphTranslation() { $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); // Assert that the summary is displayed in the current language. $this->drupalGet('de/node/' . $node->id() . '/edit'); - $this->assertFieldByName('title[0][value]', 'DE llama'); - $this->assertRaw('<span class="summary-content">DE text llama</span></div></div>'); - $this->assertRaw('<span class="summary-content">DE nested text llama</span></div></div>'); + $this->assertSession()->fieldValueEquals('title[0][value]', 'DE llama'); + $this->assertSession()->responseContains('<span class="summary-content">DE text llama</span></div></div>'); + $this->assertSession()->responseContains('<span class="summary-content">DE nested text llama</span></div></div>'); // Case 2: Referenced entities. $this->addParagraphsType('node_reference'); @@ -473,7 +473,7 @@ public function testParagraphTranslation() { $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); // Edit the node again and check the paragraph summary. $this->drupalGet('de/node/' . $referencing_node->id() . '/edit'); - $this->assertRaw('<span class="summary-content">DE llama</span></div></div>'); + $this->assertSession()->responseContains('<span class="summary-content">DE llama</span></div></div>'); } /** @@ -512,7 +512,7 @@ public function testParagraphTranslationMultilingual() { $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in english'); + $this->assertSession()->pageTextContains('Title in english'); $node = $this->drupalGetNodeByTitle('Title in english'); // Check the paragraph langcode is 'en'. $this->assertParagraphsLangcode($node->id()); @@ -528,9 +528,9 @@ public function testParagraphTranslationMultilingual() { ]; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); - $this->assertText('paragraphed_content_demo Title in french has been updated.'); - $this->assertText('Title in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('paragraphed_content_demo Title in french has been updated.'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // Check the original node and the paragraph langcode is still 'en'. $this->assertParagraphsLangcode($node->id()); @@ -545,13 +545,13 @@ public function testParagraphTranslationMultilingual() { $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); $this->assertNoParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('Title in french'); - $this->assertNoText('Title in english'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english'); // Back to the original node. $this->drupalGet('node/' . $node->id()); - $this->assertText('Title in english'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraph langcode are still 'en' and // check that the paragraphs buttons are still displayed. $this->clickLink('Edit'); @@ -580,15 +580,15 @@ public function testParagraphTranslationMultilingual() { $this->assertParagraphsLangcode($node->id()); $this->assertParagraphsButtons(2); $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); - $this->assertText('Title in english (de)'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english (de)'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraphs langcode are now 'de'. $this->assertParagraphsLangcode($node->id(), 'de'); // Check the french translation. $this->drupalGet('fr/node/' . $node->id()); - $this->assertText('Title in french'); - $this->assertNoText('Title in english (de)'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english (de)'); // Check editing a translation does not affect the source langcode and // check that the paragraphs buttons are still hidden. $this->clickLink('Edit'); @@ -628,13 +628,13 @@ public function testParagraphTranslationMultilingual() { $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); // Check the paragraphs langcode are still 'de' after saving the translation. $this->assertParagraphsLangcode($node->id(), 'de', 'fr'); - $this->assertText('Title in french'); - $this->assertNoText('Title in english (de)'); + $this->assertSession()->pageTextContains('Title in french'); + $this->assertSession()->pageTextNotContains('Title in english (de)'); // Back to the original node. $this->drupalGet('de/node/' . $node->id()); - $this->assertText('Title in english (de)'); - $this->assertNoText('Title in french'); + $this->assertSession()->pageTextContains('Title in english (de)'); + $this->assertSession()->pageTextNotContains('Title in french'); // Check the original node and the paragraphs langcode are still 'de' and // check that the paragraphs buttons are still displayed. $this->clickLink('Edit'); @@ -688,7 +688,8 @@ public function testParagraphsMultilingualWorkflow() { $form_display->save(); // Create a node and check that the node langcode is 'english'. $this->drupalGet('node/add/paragraphed_content_demo'); - $this->assertOptionSelected('edit-langcode-0-value', 'en'); + $option_field = $this->assertSession()->optionExists('edit-langcode-0-value', 'en'); + $this->assertTrue($option_field->hasAttribute('selected')); // Change the node langcode to 'german' and add a 'Nested Paragraph'. $edit = [ 'title[0][value]' => 'Title in german', @@ -706,7 +707,7 @@ public function testParagraphsMultilingualWorkflow() { ], t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in german'); + $this->assertSession()->pageTextContains('Title in german'); $node1 = $this->getNodeByTitle('Title in german'); // Check the paragraph langcode is 'de' and its buttons are displayed. @@ -741,7 +742,8 @@ public function testParagraphsMultilingualWorkflow() { // Create another node. $this->drupalGet('node/add/paragraphed_content_demo'); // Check that the node langcode is 'english' and add a 'Nested Paragraph'. - $this->assertOptionSelected('edit-langcode-0-value', 'en'); + $option_field = $this->assertSession()->optionExists('edit-langcode-0-value', 'en'); + $this->assertTrue($option_field->hasAttribute('selected')); $this->drupalPostForm(NULL, NULL, t('Add nested_paragraph')); // Check that the paragraphs buttons are displayed and add an 'Images' // paragraph inside the nested paragraph. @@ -756,7 +758,7 @@ public function testParagraphsMultilingualWorkflow() { $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); $this->drupalPostForm(NULL, NULL, t('Save')); - $this->assertText('Title in english'); + $this->assertSession()->pageTextContains('Title in english'); $node2 = $this->drupalGetNodeByTitle('Title in english'); // Check the paragraph langcode is 'en' and its buttons are displayed. @@ -885,10 +887,10 @@ protected function assertParagraphsButtonsHelper($count, $hidden = TRUE) { for ($i = 0; $i < $count; $i++) { $remove_button = $this->xpath('//*[@name="field_paragraphs_demo_' . $i . '_remove"]'); if (!$hidden) { - $this->assertNotEqual(count($remove_button), 0); + $this->assertNotEquals(count($remove_button), 0); } else { - $this->assertEqual(count($remove_button), 0); + $this->assertEquals(count($remove_button), 0); } } @@ -896,10 +898,10 @@ protected function assertParagraphsButtonsHelper($count, $hidden = TRUE) { // the add more buttons presence for this test class. $add_button = $this->xpath('//input[@value="Add images"]'); if (!$hidden) { - $this->assertNotEqual(count($add_button), 0); + $this->assertNotEquals(count($add_button), 0); } else { - $this->assertEqual(count($add_button), 0); + $this->assertEquals(count($add_button), 0); } } @@ -919,13 +921,13 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran /** @var \Drupal\node\NodeInterface $node */ $node = Node::load($node_id); $node_langcode = $node->langcode->value; - $this->assertEqual($node_langcode, $source_lang, 'Host langcode matches.'); + $this->assertEquals($node_langcode, $source_lang, 'Host langcode matches.'); /** @var \Drupal\Core\Entity\ContentEntityBase $paragraph */ foreach ($node->field_paragraphs_demo->referencedEntities() as $paragraph) { $paragraph_langcode = $paragraph->language()->getId(); $message = new FormattableMarkup('Node langcode is "@node", paragraph item langcode is "@item".', ['@node' => $source_lang, '@item' => $paragraph_langcode]); - $this->assertEqual($paragraph_langcode, $source_lang, $message); + $this->assertEquals($paragraph_langcode, $source_lang, $message); } // Check the translation. @@ -935,7 +937,7 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran if ($node->hasTranslation($trans_lang)) { $trans_node = $node->getTranslation($trans_lang); $trans_node_langcode = $trans_node->language()->getId(); - $this->assertEqual($trans_node_langcode, $trans_lang, 'Translated node langcode matches.'); + $this->assertEquals($trans_node_langcode, $trans_lang, 'Translated node langcode matches.'); // Check the paragraph item langcode matching the translated node langcode. foreach ($trans_node->field_paragraphs_demo->referencedEntities() as $paragraph) { @@ -943,7 +945,7 @@ protected function assertParagraphsLangcode($node_id, $source_lang = 'en', $tran $trans_item = $paragraph->getTranslation($trans_lang); $paragraph_langcode = $trans_item->language()->getId(); $message = new FormattableMarkup('Translated node langcode is "@node", paragraph item langcode is "@item".', ['@node' => $trans_lang, '@item' => $paragraph_langcode]); - $this->assertEqual($paragraph_langcode, $trans_lang, $message); + $this->assertEquals($paragraph_langcode, $trans_lang, $message); } } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTypesTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTypesTest.php index 1a66f4f828ae530fb8e7745036549787356e0217..ceee3ba906a2380686d500d881ba7cc22651105d 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTypesTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalTypesTest.php @@ -23,7 +23,7 @@ public function testRemoveTypesWithContent() { // Attempt to delete the content type not used yet. $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Delete')); - $this->assertText('This action cannot be undone.'); + $this->assertSession()->pageTextContains('This action cannot be undone.'); $this->clickLink(t('Cancel')); // Add a test node with a Paragraph. @@ -31,22 +31,22 @@ public function testRemoveTypesWithContent() { $this->drupalPostForm(NULL, [], 'paragraphs_paragraph_type_test_add_more'); $edit = ['title[0][value]' => 'test_node']; $table_rows = $this->xpath('//table[contains(@class, :class)]/tbody/tr', [':class' => 'field-multiple-table']); - $this->assertEqual(1, count($table_rows)); + $this->assertEquals(1, count($table_rows)); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('paragraphed_test test_node has been created.'); + $this->assertSession()->pageTextContains('paragraphed_test test_node has been created.'); // Attempt to delete the paragraph type already used. $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Delete')); - $this->assertText('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); + $this->assertSession()->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); // Delete all entities of that Paragraph type. $this->drupalPostForm(NULL, [], t('Delete existing Paragraph')); - $this->assertText('Entity is successfully deleted.'); + $this->assertSession()->pageTextContains('Entity is successfully deleted.'); $node = $this->drupalGetNodeByTitle('test_node'); $this->drupalGet('node/' . $node->id() . '/edit'); $table_rows = $this->xpath('//table[contains(@class, :class)]/tbody/tr', [':class' => 'field-multiple-table']); - $this->assertEqual(0, count($table_rows)); + $this->assertEquals(0, count($table_rows)); // @todo Remove this when https://www.drupal.org/node/2846549 is resolved. $this->drupalPostForm(NULL, $edit, t('Save')); @@ -56,22 +56,22 @@ public function testRemoveTypesWithContent() { $this->drupalPostForm(NULL, [], 'paragraphs_paragraph_type_test_add_more'); $this->drupalPostForm(NULL, [], 'paragraphs_text_add_more'); $table_rows = $this->xpath('//table[contains(@class, :class)]/tbody/tr', [':class' => 'field-multiple-table']); - $this->assertEqual(2, count($table_rows)); + $this->assertEquals(2, count($table_rows)); $this->drupalPostForm(NULL, [], t('Save')); // Attempt to delete the Paragraph type. $this->drupalGet('admin/structure/paragraphs_type'); $this->clickLink(t('Delete')); - $this->assertText('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); + $this->assertSession()->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.'); $this->drupalPostForm(NULL, [], t('Delete existing Paragraph')); - $this->assertText('Entity is successfully deleted.'); + $this->assertSession()->pageTextContains('Entity is successfully deleted.'); $this->drupalPostForm(NULL, [], t('Delete')); // Check that the Paragraph of the deleted type is removed and the rest // remains. $node = $this->drupalGetNodeByTitle('test_node'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoText('paragraph_type_test'); + $this->assertSession()->pageTextNotContains('paragraph_type_test'); $table_rows = $this->xpath('//table[contains(@class, :class)]/tbody/tr', [':class' => 'field-multiple-table']); - $this->assertEqual(1, count($table_rows)); + $this->assertEquals(1, count($table_rows)); } /** @@ -89,9 +89,9 @@ public function testCreateParagraphType() { 'id' => 'test_name_with_more_than_32_characters' ]; $this->drupalPostForm(NULL, $edit, 'Save and manage fields'); - $this->assertText('Machine-readable name cannot be longer than 32 characters but is currently 38 characters long.'); + $this->assertSession()->pageTextContains('Machine-readable name cannot be longer than 32 characters but is currently 38 characters long.'); $edit['id'] = 'new_test_id'; $this->drupalPostForm(NULL, $edit, 'Save and manage fields'); - $this->assertText('Saved the Test Paragraphs type.'); + $this->assertSession()->pageTextContains('Saved the Test Paragraphs type.'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalUiTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalUiTest.php index 1b32d292ebd756e96ecc7fe7f27a28e0fb0b5e57..066007d473e18a048cc52bdfcda996bb5d970d86 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalUiTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalUiTest.php @@ -96,7 +96,7 @@ public function testEmptyRequiredField() { $title = 'Empty'; $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save')); - $this->assertText($field_title . ' field is required'); + $this->assertSession()->pageTextContains($field_title . ' field is required'); // Attempt to create a paragraphed node with only a paragraph in the // "remove" mode in the required field. @@ -104,9 +104,9 @@ public function testEmptyRequiredField() { $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, [], 'field_content_text_image_add_more'); $this->drupalPostForm(NULL, [], 'field_content_0_remove'); - $this->assertNoText($field_title . ' field is required'); + $this->assertSession()->pageTextNotContains($field_title . ' field is required'); $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save')); - $this->assertText($field_title . ' field is required'); + $this->assertSession()->pageTextContains($field_title . ' field is required'); // Attempt to create a paragraphed node with a valid paragraph and a // removed paragraph. @@ -115,9 +115,9 @@ public function testEmptyRequiredField() { $this->drupalPostForm(NULL, [], 'field_content_text_image_add_more'); $this->drupalPostForm(NULL, [], 'field_content_text_image_add_more'); $this->drupalPostForm(NULL, [], 'field_content_1_remove'); - $this->assertNoText($field_title . ' field is required'); + $this->assertSession()->pageTextNotContains($field_title . ' field is required'); $this->drupalPostForm(NULL, ['title[0][value]' => $title], t('Save')); - $this->assertNoText($field_title . ' field is required'); + $this->assertSession()->pageTextNotContains($field_title . ' field is required'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalWidgetButtonsTest.php b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalWidgetButtonsTest.php index ef7df522bb789faa0aeeca9e60e19b660bad1042..989c0dd87d8bc9aee3f6779beb4154c951163d5a 100644 --- a/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalWidgetButtonsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/Experimental/ParagraphsExperimentalWidgetButtonsTest.php @@ -60,9 +60,9 @@ public function testWidgetButtons() { // Test the 'Open' edit mode. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText($text); + $this->assertSession()->pageTextContains($text); // Test the 'Closed' edit mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); @@ -70,7 +70,7 @@ public function testWidgetButtons() { // Click "Edit" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); $this->drupalPostForm(NULL, [], 'field_paragraphs_1_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text); $closed_mode_text = 'closed_mode_text'; // Click "Collapse" button on both paragraphs. $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $closed_mode_text]; @@ -78,36 +78,36 @@ public function testWidgetButtons() { $edit = ['field_paragraphs[1][subform][field_text][0][value]' => $closed_mode_text]; $this->drupalPostForm(NULL, $edit, 'field_paragraphs_1_collapse'); // Verify that we have warning message for each paragraph. - $this->assertEqual(2, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]"))); - $this->assertRaw('<span class="summary-content">' . $closed_mode_text); + $this->assertEquals(2, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]"))); + $this->assertSession()->responseContains('<span class="summary-content">' . $closed_mode_text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertText($closed_mode_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains($closed_mode_text); // Test the 'Preview' closed mode. $this->setParagraphsWidgetSettings('paragraphed_test', 'field_paragraphs', ['closed_mode' => 'preview']); $this->drupalGet('node/' . $node->id() . '/edit'); // Click "Edit" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text); $preview_mode_text = 'preview_mode_text'; $edit = ['field_paragraphs[0][subform][field_text][0][value]' => $preview_mode_text]; // Click "Collapse" button. $this->drupalPostForm(NULL, $edit, 'field_paragraphs_0_collapse'); - $this->assertText('You have unsaved changes on this Paragraph item.'); - $this->assertEqual(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]"))); - $this->assertText($preview_mode_text); + $this->assertSession()->pageTextContains('You have unsaved changes on this Paragraph item.'); + $this->assertEquals(1, count($this->xpath("//*[contains(@class, 'paragraphs-icon-changed')]"))); + $this->assertSession()->pageTextContains($preview_mode_text); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertText($preview_mode_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextContains($preview_mode_text); // Test the remove function. $this->drupalGet('node/' . $node->id() . '/edit'); // Click "Remove" button. $this->drupalPostForm(NULL, [], 'field_paragraphs_0_remove'); $this->drupalPostForm(NULL, [], t('Save')); - $this->assertText('paragraphed_test ' . $node->label() . ' has been updated.'); - $this->assertNoText($preview_mode_text); + $this->assertSession()->pageTextContains('paragraphed_test ' . $node->label() . ' has been updated.'); + $this->assertSession()->pageTextNotContains($preview_mode_text); } /** @@ -149,23 +149,23 @@ public function testButtonsVisibility() { // Checking visible buttons on "Open" mode. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertField('field_paragraphs_0_collapse'); - $this->assertField('field_paragraphs_0_remove'); - $this->assertField('field_paragraphs_0_duplicate'); + $this->assertSession()->buttonExists('field_paragraphs_0_collapse'); + $this->assertSession()->buttonExists('field_paragraphs_0_remove'); + $this->assertSession()->buttonExists('field_paragraphs_0_duplicate'); // Checking visible buttons on "Closed" mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertField('field_paragraphs_0_edit'); - $this->assertField('field_paragraphs_0_remove'); - $this->assertField('field_paragraphs_0_duplicate'); + $this->assertSession()->buttonExists('field_paragraphs_0_edit'); + $this->assertSession()->buttonExists('field_paragraphs_0_remove'); + $this->assertSession()->buttonExists('field_paragraphs_0_duplicate'); // Checking visible buttons on "Preview" mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertField('field_paragraphs_0_edit'); - $this->assertField('field_paragraphs_0_remove'); - $this->assertField('field_paragraphs_0_duplicate'); + $this->assertSession()->buttonExists('field_paragraphs_0_edit'); + $this->assertSession()->buttonExists('field_paragraphs_0_remove'); + $this->assertSession()->buttonExists('field_paragraphs_0_duplicate'); // Checking always show collapse and edit actions. $this->addParagraphsType('nested_paragraph'); @@ -182,17 +182,17 @@ public function testButtonsVisibility() { $this->drupalPostForm(NULL, [], 'field_paragraphs_nested_paragraph_add_more'); $this->drupalPostForm(NULL, [], 'field_paragraphs_2_subform_field_nested_nested_paragraph_add_more'); // Collapse is present on each nesting level. - $this->assertFieldByName('field_paragraphs_2_collapse'); - $this->assertFieldByName('field_paragraphs_2_subform_field_nested_0_collapse'); + $this->assertSession()->buttonExists('field_paragraphs_2_collapse'); + $this->assertSession()->buttonExists('field_paragraphs_2_subform_field_nested_0_collapse'); // Tests hook_paragraphs_widget_actions_alter. $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertNoField('edit-field-paragraphs-0-top-links-test-button'); + $this->assertSession()->buttonNotExists('edit-field-paragraphs-0-top-links-test-button'); \Drupal::state()->set('paragraphs_test_dropbutton', TRUE); $this->drupalGet('node/add/paragraphed_test'); $this->drupalPostForm(NULL, NULL, t('Add text')); - $this->assertNoField('edit-field-paragraphs-0-top-links-test-button'); + $this->assertSession()->buttonNotExists('edit-field-paragraphs-0-top-links-test-button'); ConfigurableLanguage::createFromLangcode('sr')->save(); @@ -206,11 +206,11 @@ public function testButtonsVisibility() { // Check that operation is hidden during translation. $this->drupalGet('sr/node/' . $node->id() . '/translations/add/en/sr'); - $this->assertNoField('edit-field-paragraphs-1-top-actions-dropdown-actions-test-button'); + $this->assertSession()->buttonNotExists('edit-field-paragraphs-1-top-actions-dropdown-actions-test-button'); // Check that "Duplicate" is hidden during translation. - $this->assertNoField('field_paragraphs_0_duplicate'); - $this->assertNoRaw('value="Duplicate"'); + $this->assertSession()->buttonNotExists('field_paragraphs_0_duplicate'); + $this->assertSession()->responseNotContains('value="Duplicate"'); } /** @@ -256,11 +256,13 @@ public function testButtonsVisibilityException() { ]); $field->save(); - $form_display = entity_get_form_display($entity_type, $content_type_name, 'default') + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + $form_display = $display_repository->getFormDisplay($entity_type, $content_type_name) ->setComponent($paragraphs_field_name, ['type' => $widget_type]); $form_display->save(); - $view_display = entity_get_display($entity_type, $content_type_name, 'default') + $view_display = $display_repository->getViewDisplay($entity_type, $content_type_name) ->setComponent($paragraphs_field_name, ['type' => 'entity_reference_revisions_entity_view']); $view_display->save(); @@ -285,18 +287,18 @@ public function testButtonsVisibilityException() { // Checking hidden button on "Open" mode. $this->drupalGet('node/add/paragraphed_test'); - $this->assertNoField('field_paragraphs_0_remove'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', ''); + $this->assertSession()->buttonNotExists('field_paragraphs_0_remove'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', ''); // Checking hidden button on "Closed" mode. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); $this->drupalGet('node/add/paragraphed_test'); - $this->assertNoField('field_paragraphs_0_remove'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', ''); + $this->assertSession()->buttonNotExists('field_paragraphs_0_remove'); + $this->assertSession()->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', ''); // Checking that the "Duplicate" button is not shown when cardinality is 1. $this->drupalGet('node/add/paragraphed_test'); - $this->assertNoField('field_paragraphs_0_duplicate'); + $this->assertSession()->buttonNotExists('field_paragraphs_0_duplicate'); } } diff --git a/web/modules/paragraphs/tests/src/Functional/ParagraphsExperimentalBehaviorsTest.php b/web/modules/paragraphs/tests/src/Functional/ParagraphsExperimentalBehaviorsTest.php index 1a769a6b69f79daba25cc6fd70780b5cfd06862f..f7a83d2d543a5f705e390112e70e6a84d799c534 100644 --- a/web/modules/paragraphs/tests/src/Functional/ParagraphsExperimentalBehaviorsTest.php +++ b/web/modules/paragraphs/tests/src/Functional/ParagraphsExperimentalBehaviorsTest.php @@ -46,6 +46,7 @@ public function testBehaviorPluginsSettingsFiltering() { 'behavior_plugins[test_bold_text][enabled]' => TRUE, ]; $this->drupalPostForm(NULL, $edit, 'Save'); + $this->assertSame(['test_bold_text' => ['enabled' => TRUE]], \Drupal::config("paragraphs.paragraphs_type.$paragraph_type")->get('behavior_plugins')); // Add a note that uses the behavior plugin give it an empty setting. $this->drupalGet('node/add/paragraphed_test'); @@ -56,7 +57,7 @@ public function testBehaviorPluginsSettingsFiltering() { ]; $this->drupalPostForm(NULL, $edit, 'Save'); $bolded_elements = $this->getSession()->getPage()->findAll('css', '.bold_plugin_text'); - $this->assertFalse(count($bolded_elements), 'Test plugin did not add a CSS class.'); + $this->assertEmpty(count($bolded_elements), 'Test plugin did not add a CSS class.'); // Check that empty leaves are not saved in the behavior settings. $node = $this->getNodeByTitle('Test Node', TRUE); @@ -74,7 +75,7 @@ public function testBehaviorPluginsSettingsFiltering() { ]; $this->drupalPostForm(NULL, $edit, 'Save'); $bolded_elements = $this->getSession()->getPage()->findAll('css', '.bold_plugin_text'); - $this->assertTrue(count($bolded_elements), 'Test plugin added a CSS class.'); + $this->assertGreaterThan(0, count($bolded_elements), 'Test plugin added a CSS class.'); // Check that non-empty leaves are saved in the behavior settings. \Drupal::entityTypeManager()->getStorage('paragraph')->resetCache(); diff --git a/web/modules/paragraphs/tests/src/Functional/ParagraphsUninstallTest.php b/web/modules/paragraphs/tests/src/Functional/ParagraphsUninstallTest.php index b09f181360920fd7e158f1c9122c92a867372996..37e98bdd783a27775e2d9f5d896ff7bb4df017f9 100644 --- a/web/modules/paragraphs/tests/src/Functional/ParagraphsUninstallTest.php +++ b/web/modules/paragraphs/tests/src/Functional/ParagraphsUninstallTest.php @@ -60,10 +60,10 @@ public function testUninstall() { // Uninstall the module paragraphs. $this->drupalPostForm('admin/modules/uninstall', ['uninstall[paragraphs]' => TRUE], t('Uninstall')); $this->drupalPostForm(NULL, [], t('Uninstall')); - $this->assertText(t('The selected modules have been uninstalled.')); - $this->assertNoText(t('Paragraphs demo')); - $this->assertNoText(t('Paragraphs library')); - $this->assertNoText(t('Paragraphs')); + $this->assertSession()->pageTextContains(t('The selected modules have been uninstalled.')); + $this->assertSession()->pageTextNotContains(t('Paragraphs demo')); + $this->assertSession()->pageTextNotContains(t('Paragraphs library')); + $this->assertSession()->pageTextNotContains(t('Paragraphs')); } } diff --git a/web/modules/paragraphs/tests/src/Functional/ParagraphsUpdateTest.php b/web/modules/paragraphs/tests/src/Functional/ParagraphsUpdateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e15a6830260ce15944e7e4e8c6c0ae2fe0dcb882 --- /dev/null +++ b/web/modules/paragraphs/tests/src/Functional/ParagraphsUpdateTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\Tests\paragraphs\Functional; + +use Drupal\FunctionalTests\Update\UpdatePathTestBase; + +/** + * Tests Paragraphs update path from 8.x-1.1. + * + * @group paragraphs + * @group legacy + */ +class ParagraphsUpdateTest extends UpdatePathTestBase { + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + __DIR__ . '/../../fixtures/update/drupal-8.8.standard.paragraphs_demo.php.gz', + ]; + } + + /** + * Tests the update path. + */ + public function testUpdatePath() { + // Run updates. + $this->runUpdates(); + } + +} diff --git a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php index 1d508adb94aab360671526bfc75adf0139138e1e..55244887a07c1b18f829d6a229817ca5270f0456 100644 --- a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php +++ b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php @@ -133,11 +133,11 @@ public function testAddWidgetButton() { // Verify that the paragraphs type icons are being displayed. $button_one = $this->assertSession()->buttonExists($paragraph_type); $button_two = $this->assertSession()->buttonExists('text'); - $this->assertContains($icon_one->getFilename(), $button_one->getAttribute('style')); - $this->assertContains($icon_two->getFilename(), $button_two->getAttribute('style')); + $this->assertStringContainsString($icon_one->getFilename(), $button_one->getAttribute('style')); + $this->assertStringContainsString($icon_two->getFilename(), $button_two->getAttribute('style')); // Find the add button in the nested paragraph with xpath. - $element = $this->xpath('//div[contains(@class, "form-item")]/div/div[contains(@class, "paragraph-type-add-modal")]/input'); + $element = $this->xpath('//div[contains(@class, "form-item")]/div/div/div[contains(@class, "paragraph-type-add-modal")]/input'); $element[0]->click(); $this->assertSession()->assertWaitOnAjaxRequest(); diff --git a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalClientsideButtonsTest.php b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalClientsideButtonsTest.php index cdfd77a05077aa3fa29ce1c608a887601d461c78..1ca60d565f4ed9ecb1edebb05def97cefa959c19 100644 --- a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalClientsideButtonsTest.php +++ b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalClientsideButtonsTest.php @@ -66,7 +66,7 @@ public function testAddParagraphAboveButton() { 'create paragraphed_test content', ]); // Set the add mode on the content type to modal form widget. - $form_display = entity_get_form_display('node', 'paragraphed_test', 'default'); + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('node', 'paragraphed_test'); $form_display->setComponent('field_paragraphs', [ 'type' => 'paragraphs', 'settings' => [ @@ -213,8 +213,8 @@ public function testAddParagraphAboveButton() { $this->addParagraphsType('rich_paragraph'); $this->addFieldtoParagraphType('rich_paragraph', 'field_intermediate_text', 'text'); $this->addFieldtoParagraphType('rich_paragraph', 'field_nested_paragraphs', 'entity_reference_revisions', ['target_type' => 'paragraph']); - entity_get_form_display('paragraph', 'rich_paragraph', 'default') - ->setComponent('field_nested_paragraphs', [ + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('paragraph', 'rich_paragraph'); + $form_display->setComponent('field_nested_paragraphs', [ 'type' => 'paragraphs', 'settings' => [ 'title' => 'Paragraph', diff --git a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalEditPerspectivesUiTest.php b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalEditPerspectivesUiTest.php index 99fa1789143d19f15e21f0397f1577a916e646c8..f6217e53c084aebe609ca098017e5b44b6db320a 100644 --- a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalEditPerspectivesUiTest.php +++ b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalEditPerspectivesUiTest.php @@ -65,10 +65,7 @@ public function testEditPerspectives() { $this->addFieldtoParagraphType('testplugin', 'body', 'string_long'); $this->drupalGet('node/add/testcontent'); - $add_wrapper = $page->find('css', '.paragraphs-add-wrapper'); - $this->assertTrue($add_wrapper->isVisible()); $this->clickLink('Behavior'); - $this->assertFalse($add_wrapper->isVisible()); $style_selector = $page->find('css', '.form-item-field-testparagraphfield-0-behavior-plugins-test-text-color-text-color'); $this->assertTrue($style_selector->isVisible()); $this->clickLink('Content'); @@ -116,6 +113,61 @@ public function testEditPerspectives() { $this->assertSession()->assertNotVisibleInViewport('css', '.field-add-more-submit'); } + /** + * Tests visibility of add modes actions when switching perspectives. + */ + public function testPerspectivesAddModesVisibility() { + $this->loginAsAdmin([ + 'edit behavior plugin settings' + ]); + + $page = $this->getSession()->getPage(); + $this->drupalGet('admin/structure/paragraphs_type/add'); + $page->fillField('label', 'TestPlugin'); + $this->assertSession()->waitForElementVisible('css', '#edit-name-machine-name-suffix .link'); + $page->pressButton('Edit'); + $page->fillField('id', 'testplugin'); + $page->checkField('behavior_plugins[test_text_color][enabled]'); + $page->pressButton('Save and manage fields'); + + $this->addParagraphedContentType('testcontent', 'field_testparagraphfield'); + $this->addFieldtoParagraphType('testplugin', 'body', 'string_long'); + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('node', 'testcontent'); + $component = $form_display->getComponent('field_testparagraphfield'); + + $component['settings']['add_mode'] = 'button'; + $form_display->setComponent('field_testparagraphfield', $component)->save(); + $this->drupalGet('node/add/testcontent'); + $add_wrapper = $page->find('css', '.paragraphs-add-wrapper'); + $this->assertTrue($add_wrapper->isVisible()); + $this->clickLink('Behavior'); + $this->assertFalse($add_wrapper->isVisible()); + + $component['settings']['add_mode'] = 'select'; + $form_display->setComponent('field_testparagraphfield', $component)->save(); + $this->drupalGet('node/add/testcontent'); + $add_wrapper = $page->find('css', '.paragraphs-add-wrapper'); + $this->assertTrue($add_wrapper->isVisible()); + $this->clickLink('Behavior'); + $this->assertFalse($add_wrapper->isVisible()); + + $component['settings']['add_mode'] = 'modal'; + $form_display->setComponent('field_testparagraphfield', $component)->save(); + $this->drupalGet('node/add/testcontent'); + $add_wrapper = $page->find('css', '.paragraphs-add-wrapper'); + $this->assertTrue($add_wrapper->isVisible()); + $this->clickLink('Behavior'); + $this->assertFalse($add_wrapper->isVisible()); + + $component['settings']['add_mode'] = 'dropdown'; + $form_display->setComponent('field_testparagraphfield', $component)->save(); + $this->drupalGet('node/add/testcontent'); + $add_wrapper = $page->find('css', '.paragraphs-add-wrapper'); + $this->assertTrue($add_wrapper->isVisible()); + $this->clickLink('Behavior'); + $this->assertFalse($add_wrapper->isVisible()); + } + /** * Test if tabs are visible with no behavior elements. */ diff --git a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalWidgetElementsTest.php b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalWidgetElementsTest.php index 1e46df361a7601436ea5a777547a5e034bc6c36a..2e9e7efac1028b6b98c19b7eb2faa1d6dbed4f84 100644 --- a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalWidgetElementsTest.php +++ b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsExperimentalWidgetElementsTest.php @@ -87,7 +87,7 @@ public function testDragHandler() { $this->drupalGet('node/' . $node->id() . '/translations/add/en/sr'); $page = $this->getSession()->getPage(); // Assert that the draghandle is not displayed. - $this->assertNull($page->find('css', '.tabledrag-handle')); + $this->assertEmpty($page->find('css', '.tabledrag-handle')); } } diff --git a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php index 201df18ab17aabf7346a1042cefcd7077f62631c..e872e300bcc993186bedb2dc109c1923cfeaf41e 100644 --- a/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php +++ b/web/modules/paragraphs/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php @@ -87,12 +87,12 @@ protected function addParagraphsField($bundle, $paragraphs_field_name, $entity_t ]); $field->save(); - $form_display = entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($paragraphs_field_name, ['type' => $widget_type]); + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay($entity_type, $bundle); + $form_display = $form_display->setComponent($paragraphs_field_name, ['type' => $widget_type]); $form_display->save(); - $view_display = entity_get_display($entity_type, $bundle, 'default') - ->setComponent($paragraphs_field_name, ['type' => 'entity_reference_revisions_entity_view']); + $view_display = \Drupal::service('entity_display.repository')->getViewDisplay($entity_type, $bundle); + $view_display->setComponent($paragraphs_field_name, ['type' => 'entity_reference_revisions_entity_view']); $view_display->save(); } @@ -175,13 +175,13 @@ protected function addFieldtoParagraphType($paragraph_type_id, $field_name, $fie $field_type_definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_type); - entity_get_form_display('paragraph', $paragraph_type_id, 'default') - ->setComponent($field_name, ['type' => $field_type_definition['default_widget']]) + $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('paragraph', $paragraph_type_id); + $form_display->setComponent($field_name, ['type' => $field_type_definition['default_widget']]) ->save(); - entity_get_display('paragraph', $paragraph_type_id, 'default') - ->setComponent($field_name, ['type' => $field_type_definition['default_formatter']]) - ->save(); + $view_display = \Drupal::service('entity_display.repository')->getViewDisplay('paragraph', $paragraph_type_id); + $view_display->setComponent($field_name, ['type' => $field_type_definition['default_formatter']]); + $view_display->save(); } /** diff --git a/web/modules/paragraphs/tests/src/Kernel/migrate/ParagraphsFieldMigrationTest.php b/web/modules/paragraphs/tests/src/Kernel/migrate/ParagraphsFieldMigrationTest.php index 9c2ad1b18f324fbf9b28b877dd450359dafb9ec0..e4d93d7a24873db6dece757bca6b5318fe37baa6 100644 --- a/web/modules/paragraphs/tests/src/Kernel/migrate/ParagraphsFieldMigrationTest.php +++ b/web/modules/paragraphs/tests/src/Kernel/migrate/ParagraphsFieldMigrationTest.php @@ -64,8 +64,6 @@ public function testParagrahsFieldInstanceMigration() { $total_bundles = count(ParagraphsType::loadMultiple()); - $bundles_from_field_collections = count($this->getMigration('d7_field_collection_type')->getSourcePlugin()); - $this->assertFieldInstanceExists('node', 'paragraphs_test', 'field_field_collection_test'); $field = FieldConfig::loadByName('node', 'paragraphs_test', 'field_field_collection_test'); @@ -79,7 +77,7 @@ public function testParagrahsFieldInstanceMigration() { $field = FieldConfig::loadByName('node', 'paragraphs_test', 'field_any_paragraph'); $handler_settings = $field->getSetting('handler_settings'); $this->assertEquals(0, $handler_settings['negate']); - $this->assertNULL($handler_settings['target_bundles']); + $this->assertEmpty($handler_settings['target_bundles']); $this->assertCount($total_bundles, $handler_settings['target_bundles_drag_drop']); $this->assertFieldInstanceExists('node', 'paragraphs_test', 'field_paragraph_one_only'); @@ -140,7 +138,7 @@ public function testParagraphFormatters() { $field_paragraph_one_only = $viewDisplay->getComponent('field_paragraph_one_only'); $this->assertNotNull($field_any_paragraph); $this->assertNotNull($field_collection_test); - $this->assertNull($field_paragraph_one_only); + $this->assertEmpty($field_paragraph_one_only); $this->assertEquals('paragraphs_editor_preview', $field_any_paragraph['settings']['view_mode']); } diff --git a/web/modules/paragraphs/tests/src/Unit/migrate/FieldCollectionsFieldInstanceSettingsTest.php b/web/modules/paragraphs/tests/src/Unit/migrate/FieldCollectionsFieldInstanceSettingsTest.php index 2da6e2f47d8df4751ea09cbc0d322cf9e7272453..1a845317e2d998dd59c0acccb987ca1bddc17c02 100644 --- a/web/modules/paragraphs/tests/src/Unit/migrate/FieldCollectionsFieldInstanceSettingsTest.php +++ b/web/modules/paragraphs/tests/src/Unit/migrate/FieldCollectionsFieldInstanceSettingsTest.php @@ -56,7 +56,8 @@ public function testFieldCollectionBadBundle() { ['type', 'field_collection'], ['bundle', 'non_existent_bundle'], ]); - $this->setExpectedException(MigrateSkipRowException::class, 'No target paragraph bundle found for field_collection'); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage("No target paragraph bundle found for field_collection"); $this->plugin->transform([], $this->migrateExecutable, $this->row, 'settings'); }