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