diff --git a/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php index f2653b7..ac2a588 100644 --- a/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Field\BaseFieldDefinition; use Drupal\FunctionalTests\Update\UpdatePathTestBase; +use Drupal\views\Entity\View; /** * Tests update functions for the Block Content module. @@ -66,4 +67,75 @@ public function testStatusFieldAddition() { $this->assertFalse($schema->fieldExists('block_content_field_data', 'content_translation_status')); } + /** + * Tests updating the block_content view for publishable block_content blocks. + * + * @see block_content_update_8600() + */ + public function testBlockContentPublishableUIUpdate() { + $this->runUpdates(); + + // Load and initialize the block_content view. + $view = View::load('block_content'); + $data = $view->toArray(); + // Check that new fields exist and that they are in the correct order. + $view_fields = $data['display']['default']['display_options']['fields']; + $this->assertArrayHasKey('block_content_bulk_form', $view_fields); + $this->assertArrayHasKey('status', $view_fields); + $block_content_bulk_form_position = array_search('block_content_bulk_form', array_keys($view_fields)); + $this->assertEqual($block_content_bulk_form_position, 0, "The block_content_bulk_form field is in the correct position"); + $expected_status_position = array_search('operations', array_keys($view_fields)) - 1; + $status_position = array_search('status', array_keys($view_fields)); + $this->assertEqual($status_position, $expected_status_position, "The status field is in the correct position"); + // Check that the new filter exists and is exposed. + $this->assertArrayHasKey('status', $data['display']['default']['display_options']['filters']); + $this->assertTrue($data['display']['default']['display_options']['filters']['status']['exposed'], "The status filter is exposed"); + + // Check the new actions were created and work as expected. + $user = $this->drupalCreateUser(['administer blocks', 'administer block_content display']); + $this->drupalLogin($user); + // Create a block. + $block_title = 'Test Block'; + $edit = []; + $edit['info[0][value]'] = $block_title; + $edit['body[0][value]'] = $this->randomMachineName(16); + $this->drupalPostForm('block/add/basic', $edit, t('Save')); + + // Check that the new block is displayed and showing its published status. + $this->drupalGet('admin/structure/block/block-content'); + $this->assertText($block_title); + $this->assertText('Yes', "Block displayed as published"); + + // Unpublish the block using the new unpublish action. + $edit =[]; + $edit['action'] = 'block_content_unpublish_action'; + $edit['block_content_bulk_form[0]'] = TRUE; + $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply to selected items')); + $this->assertText('Unpublish block content was applied to 1 item.'); + $this->assertText($block_title); + $this->assertText('No', "Block displayed as unpublished"); + + // Filter by unpublished to show only unpublished blocks. + $edit =[]; + $edit['status'] = 0; + $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply')); + $this->assertText($block_title); + $this->assertText('No', "Block displayed as unpublished"); + + // Publish the block using the new publish action. + $edit =[]; + $edit['action'] = 'block_content_publish_action'; + $edit['block_content_bulk_form[0]'] = TRUE; + $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply to selected items')); + $this->assertText('Publish block content was applied to 1 item.'); + $this->assertText('Yes', "Block displayed as unpublished"); + + // Filter by published to show only published blocks. + $edit =[]; + $edit['status'] = 1; + $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply')); + $this->assertText($block_title); + $this->assertText('Yes', "Block displayed as unpublished"); + } + }