public function RecentlyReadBlockTest::testRecentlyReadBlock in Recently Read 8
Tests Recently read block for authenticated and anonymous user.
Throws
\Behat\Mink\Exception\ExpectationException
\Behat\Mink\Exception\ResponseTextException
\Drupal\Core\Entity\EntityMalformedException
File
- tests/
src/ Functional/ RecentlyReadBlockTest.php, line 66
Class
- RecentlyReadBlockTest
- Testing Recently Read Block.
Namespace
Drupal\Tests\recently_read\FunctionalCode
public function testRecentlyReadBlock() {
// 0. create user & login
// 1. visit few nodes.
// 2. check recently read content block.
// $this->fail('Recently read has failed you.');.
$this->user = $this
->DrupalCreateUser([
'access content',
]);
$this
->drupalLogin($this->user);
$node1 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode1'),
'type' => 'foo',
]);
$node2 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode2'),
'type' => 'foo',
]);
$node3 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode3'),
'type' => 'bar',
]);
$node4 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode4'),
'type' => 'bar',
]);
$node5 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode5'),
'type' => 'baz',
]);
$node6 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode6'),
'type' => 'baz',
]);
$this
->drupalGet($node1
->toUrl());
$this
->drupalGet($node2
->toUrl());
$this
->drupalGet($node3
->toUrl());
$this
->drupalGet($node4
->toUrl());
$this
->drupalGet($node5
->toUrl());
$this
->drupalGet($node6
->toUrl());
$this
->drupalGet('/user');
$session = $this
->assertSession();
$session
->pageTextContains('Recently read content');
$session
->pageTextNotContains('TestNode3');
$session
->linkExists('TestNode6');
// Check if recently read content gets replaced by new content.
$node7 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode7'),
'type' => 'foo',
]);
$node8 = $this
->recentlyReadNodeCreate([
'title' => t('TestNode8'),
'type' => 'foo',
]);
$this
->drupalGet($node7
->toUrl());
$this
->drupalGet($node8
->toUrl());
$session
->linkExists('TestNode8');
$this
->drupalLogout();
$session
->pageTextNotContains('TestNode5');
// Anonymous user.
$this
->drupalGet($node1
->toUrl());
$this
->drupalGet($node2
->toUrl());
$this
->drupalGet($node3
->toUrl());
$this
->drupalGet($node4
->toUrl());
$this
->drupalGet($node5
->toUrl());
$this
->drupalGet($node6
->toUrl());
$this
->drupalGet('/user');
$session
->pageTextContains('Recently read content');
$session
->pageTextNotContains('TestNode3');
$session
->linkExists('TestNode6');
$this
->drupalGet($node7
->toUrl());
$this
->drupalGet($node8
->toUrl());
$session
->linkExists('TestNode8');
}