You are here

public function ShareMessageWorkflowTest::testTokenCacheability in Share Message 8

Tests if blocks with tokens are correctly updated when token data changes.

File

tests/src/Functional/ShareMessageWorkflowTest.php, line 94

Class

ShareMessageWorkflowTest
Main Share Message workflow through the admin UI.

Namespace

Drupal\Tests\sharemessage\Functional

Code

public function testTokenCacheability() {

  // Step 1: Create a Share Message in the UI.
  $this
    ->drupalGet('admin/config/services/sharemessage/add');
  $edit = [
    'label' => 'Share Message Test Label',
    'id' => 'sharemessage_test_label',
    'title' => 'Share Message Test Title [current-user:name]',
    'message_long' => 'Share Message Test Long Description',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Add a block that will contain the created Share Message.
  $theme = 'classy';
  $block = [
    'settings[label]' => 'Share Message test block',
    'settings[sharemessage]' => $edit['id'],
    'region' => 'content',
  ];
  $this
    ->drupalPostForm('admin/structure/block/add/sharemessage_block/' . $theme, $block, t('Save block'));
  $this
    ->drupalGet('user');
  $this
    ->assertResponse(200);

  // Check that the username is displayed.
  $this
    ->assertRaw('Share Message Test Title ' . $this->adminUser
    ->getAccountName());

  // Step 2: Edit the username.
  $this->adminUser->name = 'new user';
  $this->adminUser
    ->save();
  $this
    ->drupalGet('user');
  $this
    ->assertResponse(200);

  // Check that the changed username is displayed.
  $this
    ->assertRaw('Share Message Test Title ' . $this->adminUser
    ->getAccountName());
}