Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / block_content / tests / src / Functional / PageEditTest.php
1 <?php
2
3 namespace Drupal\Tests\block_content\Functional;
4
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\Component\Utility\Unicode;
7
8 /**
9  * Create a block and test block edit functionality.
10  *
11  * @group block_content
12  */
13 class PageEditTest extends BlockContentTestBase {
14
15   protected function setUp() {
16     parent::setUp();
17
18     $this->drupalPlaceBlock('page_title_block');
19   }
20
21   /**
22    * Checks block edit functionality.
23    */
24   public function testPageEdit() {
25     $this->drupalLogin($this->adminUser);
26
27     $title_key = 'info[0][value]';
28     $body_key = 'body[0][value]';
29     // Create block to edit.
30     $edit = [];
31     $edit['info[0][value]'] = Unicode::strtolower($this->randomMachineName(8));
32     $edit[$body_key] = $this->randomMachineName(16);
33     $this->drupalPostForm('block/add/basic', $edit, t('Save'));
34
35     // Check that the block exists in the database.
36     $blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute();
37     $block = BlockContent::load(reset($blocks));
38     $this->assertTrue($block, 'Custom block found in database.');
39
40     // Load the edit page.
41     $this->drupalGet('block/' . $block->id());
42     $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
43     $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
44
45     // Edit the content of the block.
46     $edit = [];
47     $edit[$title_key] = $this->randomMachineName(8);
48     $edit[$body_key] = $this->randomMachineName(16);
49     // Stay on the current page, without reloading.
50     $this->drupalPostForm(NULL, $edit, t('Save'));
51
52     // Edit the same block, creating a new revision.
53     $this->drupalGet("block/" . $block->id());
54     $edit = [];
55     $edit['info[0][value]'] = $this->randomMachineName(8);
56     $edit[$body_key] = $this->randomMachineName(16);
57     $edit['revision'] = TRUE;
58     $this->drupalPostForm(NULL, $edit, t('Save'));
59
60     // Ensure that the block revision has been created.
61     \Drupal::entityManager()->getStorage('block_content')->resetCache([$block->id()]);
62     $revised_block = BlockContent::load($block->id());
63     $this->assertNotIdentical($block->getRevisionId(), $revised_block->getRevisionId(), 'A new revision has been created.');
64
65     // Test deleting the block.
66     $this->drupalGet("block/" . $revised_block->id());
67     $this->clickLink(t('Delete'));
68     $this->assertText(format_string('Are you sure you want to delete the custom block @label?', ['@label' => $revised_block->label()]));
69   }
70
71 }