Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / block / tests / src / Functional / BlockFormInBlockTest.php
1 <?php
2
3 namespace Drupal\Tests\block\Functional;
4
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests form in block caching.
10  *
11  * @group block
12  */
13 class BlockFormInBlockTest extends BrowserTestBase {
14
15   /**
16    * Modules to install.
17    *
18    * @var array
19    */
20   public static $modules = ['block', 'block_test', 'test_page_test'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     // Enable our test block.
29     $this->drupalPlaceBlock('test_form_in_block');
30   }
31
32   /**
33    * Test to see if form in block's redirect isn't cached.
34    */
35   public function testCachePerPage() {
36     $form_values = ['email' => 'test@example.com'];
37
38     // Go to "test-page" and test if the block is enabled.
39     $this->drupalGet('test-page');
40     $this->assertResponse(200);
41     $this->assertText('Your .com email address.', 'form found');
42
43     // Make sure that we're currently still on /test-page after submitting the
44     // form.
45     $this->drupalPostForm(NULL, $form_values, t('Submit'));
46     $this->assertUrl('test-page');
47     $this->assertText(t('Your email address is @email', ['@email' => 'test@example.com']));
48
49     // Go to a different page and see if the block is enabled there as well.
50     $this->drupalGet('test-render-title');
51     $this->assertResponse(200);
52     $this->assertText('Your .com email address.', 'form found');
53
54     // Make sure that submitting the form didn't redirect us to the first page
55     // we submitted the form from after submitting the form from
56     // /test-render-title.
57     $this->drupalPostForm(NULL, $form_values, t('Submit'));
58     $this->assertUrl('test-render-title');
59     $this->assertText(t('Your email address is @email', ['@email' => 'test@example.com']));
60   }
61
62   /**
63    * Test the actual placeholders
64    */
65   public function testPlaceholders() {
66     $this->drupalGet('test-multiple-forms');
67
68     $placeholder = 'form_action_' . Crypt::hashBase64('Drupal\Core\Form\FormBuilder::prepareForm');
69     $this->assertText('Form action: ' . $placeholder, 'placeholder found.');
70   }
71
72 }