View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\comment\CommentInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\BrowserTestBase;
class NodeAccessPagerTest extends BrowserTestBase {
use CommentTestTrait;
public static $modules = [
'node_access_test',
'comment',
'forum',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
node_access_rebuild();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => t('Basic page'),
]);
$this
->addDefaultCommentField('node', 'page');
$this->webUser = $this
->drupalCreateUser([
'access content',
'access comments',
'node test view',
]);
}
public function testCommentPager() {
$node = $this
->drupalCreateNode();
for ($i = 0; $i < 60; $i++) {
$comment = Comment::create([
'entity_id' => $node
->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => $this
->randomMachineName(),
'comment_body' => [
[
'value' => $this
->randomMachineName(),
],
],
'status' => CommentInterface::PUBLISHED,
]);
$comment
->save();
}
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/' . $node
->id());
$this
->assertText($node
->label());
$this
->assertText(t('Comments'));
$this
->assertRaw('page=1');
$this
->assertNoRaw('page=2');
}
public function testForumPager() {
$vid = $this
->config('forum.settings')
->get('vocabulary');
$this
->assertNotEmpty($vid, 'Forum navigation vocabulary ID is set.');
$tree = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadTree($vid, 0, 1);
$tid = reset($tree)->tid;
$this
->assertNotEmpty($tid, 'General discussion term is found in the forum vocabulary.');
for ($i = 0; $i < 30; $i++) {
$this
->drupalCreateNode([
'nid' => NULL,
'type' => 'forum',
'taxonomy_forums' => [
[
'target_id' => $tid,
],
],
]);
}
$this
->drupalLogin($this->webUser);
$this
->drupalGet('forum/' . $tid);
$this
->assertRaw('page=1');
$this
->assertNoRaw('page=2');
}
}