diff --git a/core/composer.json b/core/composer.json index 85bac13..7cfb286 100644 --- a/core/composer.json +++ b/core/composer.json @@ -141,7 +141,7 @@ "drupal/user": "self.version", "drupal/views": "self.version", "drupal/views_ui": "self.version", - "drupal/worflow": "self.version" + "drupal/workflow": "self.version" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 9b7c753..ff2c2d3 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -2,7 +2,7 @@ namespace Drupal\content_moderation; -use Drupal\content_moderation\Entity\ContentModerationState; +use Drupal\content_moderation\Entity\ContentModerationState as ContentModerationStateEntity; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; @@ -190,7 +190,7 @@ protected function updateOrCreateFromEntity(EntityInterface $entity) { // Create the ContentModerationState entity for the inserted entity. $content_moderation_state->set('content_entity_revision_id', $entity_revision_id); $content_moderation_state->set('moderation_state', $moderation_state); - ContentModerationState::updateOrCreateFromEntity($content_moderation_state); + ContentModerationStateEntity::updateOrCreateFromEntity($content_moderation_state); } /** diff --git a/core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.all_revisions.yml b/core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.all_revisions.yml new file mode 100644 index 0000000..94fc5d3 --- /dev/null +++ b/core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.all_revisions.yml @@ -0,0 +1,372 @@ +langcode: en +status: true +dependencies: + config: + - system.menu.main + module: + - content_moderation + - user +id: all_revisions +label: All +module: views +description: '' +tag: '' +base_table: node_field_revision +base_field: vid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'view all revisions' + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: full + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: '‹ Previous' + next: 'Next ›' + first: '« First' + last: 'Last »' + quantity: 9 + style: + type: table + row: + type: fields + fields: + nid: + id: nid + table: node_field_revision + field: nid + relationship: none + group_type: group + admin_label: '' + label: 'Node ID' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: nid + plugin_id: field + vid: + id: vid + table: node_field_revision + field: vid + relationship: none + group_type: group + admin_label: '' + label: 'Revision ID' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: vid + plugin_id: field + title: + id: title + table: node_field_revision + field: title + entity_type: node + entity_field: title + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + settings: + link_to_entity: false + plugin_id: field + relationship: none + group_type: group + admin_label: '' + label: Title + exclude: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_alter_empty: true + click_sort_column: value + type: string + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + moderation_state: + id: moderation_state + table: content_moderation_state_field_revision + field: moderation_state + relationship: moderation_state + group_type: group + admin_label: '' + label: 'Moderation state' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: true + group_column: target_id + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: content_moderation_state + entity_field: moderation_state + plugin_id: field + filters: { } + sorts: { } + title: 'All Revisions' + header: { } + footer: { } + empty: { } + relationships: + moderation_state: + id: moderation_state + table: node_field_revision + field: moderation_state + relationship: none + group_type: group + admin_label: 'Content moderation state' + required: false + entity_type: node + plugin_id: standard + arguments: { } + display_extenders: { } + cache_metadata: + max-age: 0 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: all + menu: + type: normal + title: Drafts + description: '' + expanded: false + parent: '' + weight: 0 + context: '0' + menu_name: main + cache_metadata: + max-age: 0 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/core/modules/content_moderation/src/Tests/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php similarity index 83% rename from core/modules/content_moderation/src/Tests/ModerationFormTest.php rename to core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php index 16da4e4..7a3f88f 100644 --- a/core/modules/content_moderation/src/Tests/ModerationFormTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php @@ -1,6 +1,6 @@ drupalGet($latest_version_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); // Update the draft. $this->drupalPostForm($edit_path, [ @@ -56,7 +56,7 @@ public function testModerationForm() { // The latest version page should not show, because there is still no // forward revision. $this->drupalGet($latest_version_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); // Publish the draft. $this->drupalPostForm($edit_path, [ @@ -66,13 +66,13 @@ public function testModerationForm() { // The published view should not have a moderation form, because it is the // default revision. $this->drupalGet($canonical_path); - $this->assertResponse(200); - $this->assertNoText('Status', 'The node view page has no moderation form.'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextNotContains('Status'); // The latest version page should not show, because there is still no // forward revision. $this->drupalGet($latest_version_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); // Make a forward revision. $this->drupalPostForm($edit_path, [ @@ -82,15 +82,15 @@ public function testModerationForm() { // The published view should not have a moderation form, because it is the // default revision. $this->drupalGet($canonical_path); - $this->assertResponse(200); - $this->assertNoText('Status', 'The node view page has no moderation form.'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextNotContains('Status'); // The latest version page should show the moderation form and have "Draft" // status, because the forward revision is in "Draft". $this->drupalGet($latest_version_path); - $this->assertResponse(200); - $this->assertText('Status', 'Form text found on the latest-version page.'); - $this->assertText('Draft', 'Correct status found on the latest-version page.'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('Status'); + $this->assertSession()->pageTextContains('Draft'); // Submit the moderation form to change status to published. $this->drupalPostForm($latest_version_path, [ @@ -100,7 +100,7 @@ public function testModerationForm() { // The latest version page should not show, because there is no // forward revision. $this->drupalGet($latest_version_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); } } diff --git a/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php similarity index 76% rename from core/modules/content_moderation/src/Tests/ModerationLocaleTest.php rename to core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php index a78c104..0e4f5ca 100644 --- a/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php @@ -1,6 +1,6 @@ 'en', ]; $this->drupalPostForm('node/add/article', $edit, t('Save and Publish')); - $this->assertText(t('Article Published English node has been created.')); + $this->assertSession()->pageTextContains(t('Article Published English node has been created.')); $english_node = $this->drupalGetNodeByTitle('Published English node'); // Add a French translation. @@ -68,7 +68,7 @@ public function testTranslateModeratedContent() { // Here the error has occurred "The website encountered an unexpected error. // Please try again later." // If the translation has got lost. - $this->assertText(t('Article French node Draft has been updated.')); + $this->assertSession()->pageTextContains(t('Article French node Draft has been updated.')); // Create an article in English. $edit = [ @@ -76,7 +76,7 @@ public function testTranslateModeratedContent() { 'langcode[0][value]' => 'en', ]; $this->drupalPostForm('node/add/article', $edit, t('Save and Create New Draft')); - $this->assertText(t('Article English node has been created.')); + $this->assertSession()->pageTextContains(t('Article English node has been created.')); $english_node = $this->drupalGetNodeByTitle('English node'); // Add a French translation. @@ -86,20 +86,20 @@ public function testTranslateModeratedContent() { 'title[0][value]' => 'French node', ]; $this->drupalPostForm(NULL, $edit, t('Save and Create New Draft (this translation)')); - $this->assertText(t('Article French node has been updated.')); + $this->assertSession()->pageTextContains(t('Article French node has been updated.')); $english_node = $this->drupalGetNodeByTitle('English node', TRUE); // Publish the English article and check that the translation stays // unpublished. $this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Publish (this translation)')); - $this->assertText(t('Article English node has been updated.')); + $this->assertSession()->pageTextContains(t('Article English node has been updated.')); $english_node = $this->drupalGetNodeByTitle('English node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual('French node', $french_node->label()); + $this->assertEquals('French node', $french_node->label()); - $this->assertEqual($english_node->moderation_state->value, 'published'); + $this->assertEquals($english_node->moderation_state->value, 'published'); $this->assertTrue($english_node->isPublished()); - $this->assertEqual($french_node->moderation_state->value, 'draft'); + $this->assertEquals($french_node->moderation_state->value, 'draft'); $this->assertFalse($french_node->isPublished()); // Create another article with its translation. This time we will publish @@ -108,7 +108,7 @@ public function testTranslateModeratedContent() { 'title[0][value]' => 'Another node', ]; $this->drupalPostForm('node/add/article', $edit, t('Save and Create New Draft')); - $this->assertText(t('Article Another node has been created.')); + $this->assertSession()->pageTextContains(t('Article Another node has been created.')); $english_node = $this->drupalGetNodeByTitle('Another node'); // Add a French translation. @@ -118,18 +118,18 @@ public function testTranslateModeratedContent() { 'title[0][value]' => 'Translated node', ]; $this->drupalPostForm(NULL, $edit, t('Save and Create New Draft (this translation)')); - $this->assertText(t('Article Translated node has been updated.')); + $this->assertSession()->pageTextContains(t('Article Translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); // Publish the translation and check that the source language version stays // unpublished. $this->drupalPostForm('fr/node/' . $english_node->id() . '/edit', [], t('Save and Publish (this translation)')); - $this->assertText(t('Article Translated node has been updated.')); + $this->assertSession()->pageTextContains(t('Article Translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEquals($french_node->moderation_state->value, 'published'); $this->assertTrue($french_node->isPublished()); - $this->assertEqual($english_node->moderation_state->value, 'draft'); + $this->assertEquals($english_node->moderation_state->value, 'draft'); $this->assertFalse($english_node->isPublished()); // Now check that we can create a new draft of the translation. @@ -137,41 +137,41 @@ public function testTranslateModeratedContent() { 'title[0][value]' => 'New draft of translated node', ]; $this->drupalPostForm('fr/node/' . $english_node->id() . '/edit', $edit, t('Save and Create New Draft (this translation)')); - $this->assertText(t('Article New draft of translated node has been updated.')); + $this->assertSession()->pageTextContains(t('Article New draft of translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEquals($french_node->moderation_state->value, 'published'); $this->assertTrue($french_node->isPublished()); - $this->assertEqual($french_node->getTitle(), 'Translated node', 'The default revision of the published translation remains the same.'); + $this->assertEquals($french_node->getTitle(), 'Translated node', 'The default revision of the published translation remains the same.'); // Publish the draft. $edit = [ 'new_state' => 'published', ]; $this->drupalPostForm('fr/node/' . $english_node->id() . '/latest', $edit, t('Apply')); - $this->assertText(t('The moderation state has been updated.')); + $this->assertSession()->pageTextContains(t('The moderation state has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEquals($french_node->moderation_state->value, 'published'); $this->assertTrue($french_node->isPublished()); - $this->assertEqual($french_node->getTitle(), 'New draft of translated node', 'The draft has replaced the published revision.'); + $this->assertEquals($french_node->getTitle(), 'New draft of translated node', 'The draft has replaced the published revision.'); // Publish the English article before testing the archive transition. $this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Publish (this translation)')); - $this->assertText(t('Article Another node has been updated.')); + $this->assertSession()->pageTextContains(t('Article Another node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); - $this->assertEqual($english_node->moderation_state->value, 'published'); + $this->assertEquals($english_node->moderation_state->value, 'published'); // Archive the node and its translation. $this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Archive (this translation)')); - $this->assertText(t('Article Another node has been updated.')); + $this->assertSession()->pageTextContains(t('Article Another node has been updated.')); $this->drupalPostForm('fr/node/' . $english_node->id() . '/edit', [], t('Save and Archive (this translation)')); - $this->assertText(t('Article New draft of translated node has been updated.')); + $this->assertSession()->pageTextContains(t('Article New draft of translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($english_node->moderation_state->value, 'archived'); + $this->assertEquals($english_node->moderation_state->value, 'archived'); $this->assertFalse($english_node->isPublished()); - $this->assertEqual($french_node->moderation_state->value, 'archived'); + $this->assertEquals($french_node->moderation_state->value, 'archived'); $this->assertFalse($french_node->isPublished()); // Create another article with its translation. This time publishing english @@ -180,7 +180,7 @@ public function testTranslateModeratedContent() { 'title[0][value]' => 'An english node', ]; $this->drupalPostForm('node/add/article', $edit, t('Save and Create New Draft')); - $this->assertText(t('Article An english node has been created.')); + $this->assertSession()->pageTextContains(t('Article An english node has been created.')); $english_node = $this->drupalGetNodeByTitle('An english node'); $this->assertFalse($english_node->isPublished()); diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php index 843b6fa..d34acdd 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php @@ -59,11 +59,10 @@ public function testViewShowsCorrectStates() { $node_2->save(); // Now show the View, and confirm that the state labels are showing. - $this->drupalGet('/latest'); - $page = $this->getSession()->getPage(); - $this->assertTrue($page->hasLink('Draft')); - $this->assertTrue($page->hasLink('Archived')); - $this->assertFalse($page->hasLink('Published')); + $this->drupalGet('/all'); + $this->assertSession()->pageTextContains('Draft'); + $this->assertSession()->pageTextContains('Archived'); + $this->assertSession()->pageTextContains('Published'); // Now log in as an admin and test the same thing. $permissions = [ @@ -74,12 +73,11 @@ public function testViewShowsCorrectStates() { $admin1 = $this->drupalCreateUser($permissions); $this->drupalLogin($admin1); - $this->drupalGet('/latest'); - $page = $this->getSession()->getPage(); + $this->drupalGet('/all'); $this->assertEquals(200, $this->getSession()->getStatusCode()); - $this->assertTrue($page->hasLink('Draft')); - $this->assertTrue($page->hasLink('Archived')); - $this->assertFalse($page->hasLink('Published')); + $this->assertSession()->pageTextContains('Draft'); + $this->assertSession()->pageTextContains('Archived'); + $this->assertSession()->pageTextContains('Published'); } /** diff --git a/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateBlockTest.php similarity index 81% rename from core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php rename to core/modules/content_moderation/tests/src/Functional/ModerationStateBlockTest.php index 3a7a68c..4075b7d 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateBlockTest.php @@ -1,6 +1,6 @@ drupalLogin($this->rootUser); $this->drupalGet('admin/structure/block/block-content/types'); - $this->assertLinkByHref('admin/structure/block/block-content/manage/basic/moderation'); + $this->assertSession()->linkByHrefExists('admin/structure/block/block-content/manage/basic/moderation'); $this->drupalGet('admin/structure/block/block-content/manage/basic'); - $this->assertLinkByHref('admin/structure/block/block-content/manage/basic/moderation'); + $this->assertSession()->linkByHrefExists('admin/structure/block/block-content/manage/basic/moderation'); $this->drupalGet('admin/structure/block/block-content/manage/basic/moderation'); // Enable moderation for custom blocks at // admin/structure/block/block-content/manage/basic/moderation. $edit = ['workflow' => 'typical']; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('Your settings have been saved.')); + $this->assertSession()->pageTextContains(t('Your settings have been saved.')); // Create a custom block at block/add and save it as draft. $body = 'Body of moderated block'; @@ -70,7 +70,7 @@ public function testCustomBlockModeration() { 'body[0][value]' => $body, ]; $this->drupalPostForm('block/add', $edit, t('Save and Create New Draft')); - $this->assertText(t('basic Moderated block has been created.')); + $this->assertSession()->pageTextContains(t('basic Moderated block has been created.')); // Place the block in the Sidebar First region. $instance = array( @@ -85,7 +85,7 @@ public function testCustomBlockModeration() { // Navigate to home page and check that the block is visible. It should be // visible because it is the default revision. $this->drupalGet(''); - $this->assertText($body); + $this->assertSession()->pageTextContains($body); // Update the block. $updated_body = 'This is the new body value'; @@ -93,13 +93,13 @@ public function testCustomBlockModeration() { 'body[0][value]' => $updated_body, ]; $this->drupalPostForm('block/' . $block->id(), $edit, t('Save and Create New Draft')); - $this->assertText(t('basic Moderated block has been updated.')); + $this->assertSession()->pageTextContains(t('basic Moderated block has been updated.')); // Navigate to the home page and check that the block shows the updated // content. It should show the updated content because the block's default // revision is not a published moderation state. $this->drupalGet(''); - $this->assertText($updated_body); + $this->assertSession()->pageTextContains($updated_body); // Publish the block so we can create a forward revision. $this->drupalPostForm('block/' . $block->id(), [], t('Save and Publish')); @@ -110,24 +110,24 @@ public function testCustomBlockModeration() { 'body[0][value]' => $forward_revision_body, ]; $this->drupalPostForm('block/' . $block->id(), $edit, t('Save and Create New Draft')); - $this->assertText(t('basic Moderated block has been updated.')); + $this->assertSession()->pageTextContains(t('basic Moderated block has been updated.')); // Navigate to home page and check that the forward revision doesn't show, // since it should not be set as the default revision. $this->drupalGet(''); - $this->assertText($updated_body); + $this->assertSession()->pageTextContains($updated_body); // Open the latest tab and publish the new draft. $edit = [ 'new_state' => 'published', ]; $this->drupalPostForm('block/' . $block->id() . '/latest', $edit, t('Apply')); - $this->assertText(t('The moderation state has been updated.')); + $this->assertSession()->pageTextContains(t('The moderation state has been updated.')); // Navigate to home page and check that the forward revision is now the // default revision and therefore visible. $this->drupalGet(''); - $this->assertText($forward_revision_body); + $this->assertSession()->pageTextContains($forward_revision_body); } } diff --git a/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php similarity index 75% rename from core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php rename to core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php index 62adcc9..79ec4fe 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php @@ -1,6 +1,6 @@ fail('Test node was not saved correctly.'); } - $this->assertEqual('draft', $node->moderation_state->value); + $this->assertEquals('draft', $node->moderation_state->value); $path = 'node/' . $node->id() . '/edit'; // Set up published revision. @@ -42,19 +42,22 @@ public function testCreatingContent() { /* @var \Drupal\node\NodeInterface $node */ $node = \Drupal::entityTypeManager()->getStorage('node')->load($node->id()); $this->assertTrue($node->isPublished()); - $this->assertEqual('published', $node->moderation_state->value); + $this->assertEquals('published', $node->moderation_state->value); // Verify that the state field is not shown. - $this->assertNoText('Published'); + $this->assertSession()->pageTextNotContains('Published'); // Delete the node. $this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete')); - $this->assertText(t('The Moderated content moderated content has been deleted.')); + $this->assertSession()->pageTextContains(t('The Moderated content moderated content has been deleted.')); // Disable content moderation. $this->drupalPostForm('admin/structure/types/manage/moderated_content/moderation', ['workflow' => ''], t('Save')); $this->drupalGet('admin/structure/types/manage/moderated_content/moderation'); - $this->assertOptionSelected('edit-workflow', ''); + + $option_field = $this->assertSession()->optionExists('edit-workflow', ''); + $this->assertTrue($option_field->hasAttribute('selected')); + // Clear bundle cache so workflow gets added or removed from the bundle // information. \Drupal::service('entity_type.bundle.info')->clearCachedBundles(); @@ -70,7 +73,7 @@ public function testCreatingContent() { if (!$node) { $this->fail('Non-moderated test node was not saved correctly.'); } - $this->assertEqual(NULL, $node->moderation_state->value); + $this->assertEquals(NULL, $node->moderation_state->value); } /** @@ -88,32 +91,32 @@ public function testFormSaveDestination() { // After saving, we should be at the canonical URL and viewing the first // revision. - $this->assertUrl(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); - $this->assertText('First version of the content.'); + $this->assertSession()->addressEquals(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); + $this->assertSession()->pageTextContains('First version of the content.'); // Create a new draft; after saving, we should still be on the canonical // URL, but viewing the second revision. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Second version of the content.', ], t('Save and Create New Draft')); - $this->assertUrl(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); - $this->assertText('Second version of the content.'); + $this->assertSession()->addressEquals(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); + $this->assertSession()->pageTextContains('Second version of the content.'); // Make a new published revision; after saving, we should be at the // canonical URL. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Third version of the content.', ], t('Save and Publish')); - $this->assertUrl(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); - $this->assertText('Third version of the content.'); + $this->assertSession()->addressEquals(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); + $this->assertSession()->pageTextContains('Third version of the content.'); // Make a new forward revision; after saving, we should be on the "Latest // version" tab. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Fourth version of the content.', ], t('Save and Create New Draft')); - $this->assertUrl(Url::fromRoute('entity.node.latest_version', ['node' => $node->id()])); - $this->assertText('Fourth version of the content.'); + $this->assertSession()->addressEquals(Url::fromRoute('entity.node.latest_version', ['node' => $node->id()])); + $this->assertSession()->pageTextContains('Fourth version of the content.'); } /** @@ -133,10 +136,10 @@ public function testPagers() { $this->drupalLogin($this->adminUser); $this->drupalGet('admin/content'); $element = $this->cssSelect('nav.pager li.is-active a'); - $url = (string) $element[0]['href']; + $url = $element[0]->getAttribute('href'); $query = []; parse_str(parse_url($url, PHP_URL_QUERY), $query); - $this->assertEqual(0, $query['page']); + $this->assertEquals(0, $query['page']); } } diff --git a/core/modules/content_moderation/src/Tests/ModerationStateNodeTypeTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTypeTest.php similarity index 64% rename from core/modules/content_moderation/src/Tests/ModerationStateNodeTypeTest.php rename to core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTypeTest.php index d23bdfe..aa54ce6 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateNodeTypeTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTypeTest.php @@ -1,7 +1,6 @@ drupalLogin($this->adminUser); $this->createContentTypeFromUi('Not moderated', 'not_moderated'); - $this->assertText('The content type Not moderated has been added.'); + $this->assertSession()->pageTextContains('The content type Not moderated has been added.'); $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'not_moderated'); $this->drupalGet('node/add/not_moderated'); - $this->assertRaw('Save as unpublished'); + $this->assertSession()->responseContains('Save as unpublished'); $this->drupalPostForm(NULL, [ 'title[0][value]' => 'Test', ], t('Save and publish')); - $this->assertText('Not moderated Test has been created.'); + $this->assertSession()->pageTextContains('Not moderated Test has been created.'); } /** @@ -40,16 +39,19 @@ public function testEnablingOnExistingContent() { $this->drupalPostForm(NULL, [ 'title[0][value]' => 'Test', ], t('Save and publish')); - $this->assertText('Not moderated Test has been created.'); + $this->assertSession()->pageTextContains('Not moderated Test has been created.'); // Now enable moderation state, ensuring all the expected links and tabs are // present. $this->drupalGet('admin/structure/types'); - $this->assertLinkByHref('admin/structure/types/manage/not_moderated/moderation'); + $this->assertSession()->linkByHrefExists('admin/structure/types/manage/not_moderated/moderation'); $this->drupalGet('admin/structure/types/manage/not_moderated'); - $this->assertLinkByHref('admin/structure/types/manage/not_moderated/moderation'); + $this->assertSession()->linkByHrefExists('admin/structure/types/manage/not_moderated/moderation'); $this->drupalGet('admin/structure/types/manage/not_moderated/moderation'); - $this->assertOptionSelected('edit-workflow', ''); + + $option_field = $this->assertSession()->optionExists('edit-workflow', ''); + $this->assertTrue($option_field->hasAttribute('selected')); + $edit['workflow'] = 'typical'; $this->drupalPostForm(NULL, $edit, t('Save')); @@ -62,12 +64,12 @@ public function testEnablingOnExistingContent() { } $node = reset($nodes); $this->drupalGet('node/' . $node->id()); - $this->assertResponse(200); - $this->assertLinkByHref('node/' . $node->id() . '/edit'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->linkByHrefExists('node/' . $node->id() . '/edit'); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertResponse(200); - $this->assertRaw('Save and Create New Draft'); - $this->assertNoRaw('Save and publish'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->responseContains('Save and Create New Draft'); + $this->assertSession()->responseNotContains('Save and publish'); } } diff --git a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php similarity index 96% rename from core/modules/content_moderation/src/Tests/ModerationStateTestBase.php rename to core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php index 454dd08..4a7db7c0 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php @@ -1,15 +1,15 @@ drupalLogout(); $this->drupalGet($edit_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet($latest_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet($view_path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Create a forward revision for the 'Latest revision' tab. $this->drupalLogin($this->adminUser); @@ -68,12 +68,12 @@ public function testPageAccess() { $this->drupalLogin($user); $this->drupalGet($edit_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet($latest_path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); $this->drupalGet($view_path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); // Now make another user, who should not be able to see forward revisions. $user = $this->createUser([ @@ -82,12 +82,12 @@ public function testPageAccess() { $this->drupalLogin($user); $this->drupalGet($edit_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet($latest_path); - $this->assertResponse(403); + $this->assertSession()->statusCodeEquals(403); $this->drupalGet($view_path); - $this->assertResponse(200); + $this->assertSession()->statusCodeEquals(200); } } diff --git a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php index 54bd55f..413e814 100644 --- a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php +++ b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php @@ -7,9 +7,9 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\content_moderation\StateTransitionValidation; -use Drupal\state_machine\WorkflowManager; use Drupal\workflow\Entity\Workflow; use Drupal\workflow\WorkflowTypeInterface; +use Drupal\workflow\WorkflowTypeManager; use Prophecy\Argument; /** @@ -63,7 +63,7 @@ protected function setUpModerationInformation(ContentEntityInterface $entity) { $container = new ContainerBuilder(); $workflow_type = $this->prophesize(WorkflowTypeInterface::class); $workflow_type->decorateState(Argument::any())->willReturnArgument(0); - $workflow_manager = $this->prophesize(WorkflowManager::class); + $workflow_manager = $this->prophesize(WorkflowTypeManager::class); $workflow_manager->createInstance('content_moderation', Argument::any())->willReturn($workflow_type->reveal()); $container->set('workflow.plugin.manager.workflow_type', $workflow_manager->reveal()); \Drupal::setContainer($container);