3 namespace Drupal\block\Tests;
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\simpletest\WebTestBase;
10 * Tests form in block caching.
14 class BlockFormInBlockTest extends WebTestBase {
21 public static $modules = ['block', 'block_test', 'test_page_test'];
26 protected function setUp() {
29 // Enable our test block.
30 $this->drupalPlaceBlock('test_form_in_block');
34 * Test to see if form in block's redirect isn't cached.
36 public function testCachePerPage() {
37 $form_values = ['email' => 'test@example.com'];
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');
44 // Make sure that we're currently still on /test-page after submitting the
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']));
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');
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']));
64 * Test the actual placeholders
66 public function testPlaceholders() {
67 $this->drupalGet('test-multiple-forms');
69 $placeholder = 'form_action_' . Crypt::hashBase64('Drupal\Core\Form\FormBuilder::prepareForm');
70 $this->assertText('Form action: ' . $placeholder, 'placeholder found.');