3 namespace Drupal\Tests\block\Functional;
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests form in block caching.
13 class BlockFormInBlockTest extends BrowserTestBase {
20 public static $modules = ['block', 'block_test', 'test_page_test'];
25 protected function setUp() {
28 // Enable our test block.
29 $this->drupalPlaceBlock('test_form_in_block');
33 * Test to see if form in block's redirect isn't cached.
35 public function testCachePerPage() {
36 $form_values = ['email' => 'test@example.com'];
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');
43 // Make sure that we're currently still on /test-page after submitting the
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']));
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');
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']));
63 * Test the actual placeholders
65 public function testPlaceholders() {
66 $this->drupalGet('test-multiple-forms');
68 $placeholder = 'form_action_' . Crypt::hashBase64('Drupal\Core\Form\FormBuilder::prepareForm');
69 $this->assertText('Form action: ' . $placeholder, 'placeholder found.');