View source
<?php
namespace Drupal\Tests\recently_read\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
class RecentlyReadBlockTest extends BrowserTestBase {
use NodeCreationTrait;
protected $defaultTheme = 'bartik';
public static $modules = [
'node',
'block',
'user',
'recently_read',
'views',
'taxonomy',
];
private $user;
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'foo',
]);
$this
->drupalCreateContentType([
'type' => 'bar',
]);
$this
->drupalCreateContentType([
'type' => 'baz',
]);
$this
->config('recently_read.recently_read_type.node')
->set('types', [
'foo',
'baz',
])
->save();
$this
->drupalPlaceBlock('views_block:recently_read_content-block_1', [
'id' => 'recently_read_content',
'items_per_page' => 4,
]);
}
public function testRecentlyReadBlock() {
$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');
$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');
$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');
}
protected function recentlyReadNodeCreate($settings) {
$this
->drupalCreateNode($settings);
if (isset($settings['title'])) {
return $this
->drupalGetNodeByTitle($settings['title']);
}
return NULL;
}
}