BlockFormInBlockTest.php 2.0 KB

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