Issue #3049612 by claudiu.cristea, klausi: Merge ArgumentUserUIDTest & FilterUserUIDTest and convert them into a Kernel test
parent
62d72153ba
commit
43bc928177
|
|
@ -45,6 +45,13 @@ display:
|
||||||
plugin_id: node
|
plugin_id: node
|
||||||
entity_type: node
|
entity_type: node
|
||||||
entity_field: nid
|
entity_field: nid
|
||||||
|
title:
|
||||||
|
field: title
|
||||||
|
id: title
|
||||||
|
table: node_field_data
|
||||||
|
plugin_id: field
|
||||||
|
entity_type: node
|
||||||
|
entity_field: title
|
||||||
pager:
|
pager:
|
||||||
type: full
|
type: full
|
||||||
query:
|
query:
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Drupal\Tests\comment\Functional\Views;
|
|
||||||
|
|
||||||
use Drupal\comment\Entity\Comment;
|
|
||||||
use Drupal\user\Entity\User;
|
|
||||||
use Drupal\views\Views;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the user posted or commented argument handler.
|
|
||||||
*
|
|
||||||
* @group comment
|
|
||||||
*/
|
|
||||||
class ArgumentUserUIDTest extends CommentTestBase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Views used by this test.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $testViews = ['test_comment_user_uid'];
|
|
||||||
|
|
||||||
public function testCommentUserUIDTest() {
|
|
||||||
// Add an additional comment which is not created by the user.
|
|
||||||
$new_user = User::create(['name' => 'new user']);
|
|
||||||
$new_user->save();
|
|
||||||
|
|
||||||
$comment = Comment::create([
|
|
||||||
'uid' => $new_user->uid->value,
|
|
||||||
'entity_id' => $this->nodeUserCommented->id(),
|
|
||||||
'entity_type' => 'node',
|
|
||||||
'field_name' => 'comment',
|
|
||||||
'subject' => 'if a woodchuck could chuck wood.',
|
|
||||||
]);
|
|
||||||
$comment->save();
|
|
||||||
|
|
||||||
$view = Views::getView('test_comment_user_uid');
|
|
||||||
$this->executeView($view, [$this->account->id()]);
|
|
||||||
$result_set = [
|
|
||||||
[
|
|
||||||
'nid' => $this->nodeUserPosted->id(),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'nid' => $this->nodeUserCommented->id(),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
$column_map = ['nid' => 'nid'];
|
|
||||||
$this->assertIdenticalResultset($view, $result_set, $column_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Drupal\Tests\comment\Functional\Views;
|
|
||||||
|
|
||||||
use Drupal\comment\Entity\Comment;
|
|
||||||
use Drupal\user\Entity\User;
|
|
||||||
use Drupal\views\Views;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the user posted or commented filter handler.
|
|
||||||
*
|
|
||||||
* The actual stuff is done in the parent class.
|
|
||||||
*
|
|
||||||
* @group comment
|
|
||||||
*/
|
|
||||||
class FilterUserUIDTest extends CommentTestBase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Views used by this test.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public static $testViews = ['test_comment_user_uid'];
|
|
||||||
|
|
||||||
public function testCommentUserUIDTest() {
|
|
||||||
$view = Views::getView('test_comment_user_uid');
|
|
||||||
$view->setDisplay();
|
|
||||||
$view->removeHandler('default', 'argument', 'uid_touch');
|
|
||||||
|
|
||||||
// Add an additional comment which is not created by the user.
|
|
||||||
$new_user = User::create(['name' => 'new user']);
|
|
||||||
$new_user->save();
|
|
||||||
|
|
||||||
$comment = Comment::create([
|
|
||||||
'uid' => $new_user->uid->value,
|
|
||||||
'entity_id' => $this->nodeUserCommented->id(),
|
|
||||||
'entity_type' => 'node',
|
|
||||||
'field_name' => 'comment',
|
|
||||||
'subject' => 'if a woodchuck could chuck wood.',
|
|
||||||
]);
|
|
||||||
$comment->save();
|
|
||||||
|
|
||||||
$options = [
|
|
||||||
'id' => 'uid_touch',
|
|
||||||
'table' => 'node_field_data',
|
|
||||||
'field' => 'uid_touch',
|
|
||||||
'value' => [$this->loggedInUser->id()],
|
|
||||||
];
|
|
||||||
$view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);
|
|
||||||
$this->executeView($view, [$this->account->id()]);
|
|
||||||
$result_set = [
|
|
||||||
[
|
|
||||||
'nid' => $this->nodeUserPosted->id(),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'nid' => $this->nodeUserCommented->id(),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
$column_map = ['nid' => 'nid'];
|
|
||||||
$this->assertIdenticalResultset($view, $result_set, $column_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\comment\Kernel\Views;
|
||||||
|
|
||||||
|
use Drupal\comment\Entity\Comment;
|
||||||
|
use Drupal\comment\Tests\CommentTestTrait;
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
|
use Drupal\KernelTests\KernelTestBase;
|
||||||
|
use Drupal\node\Entity\NodeType;
|
||||||
|
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||||
|
use Drupal\Tests\user\Traits\UserCreationTrait;
|
||||||
|
use Drupal\views\Tests\ViewResultAssertionTrait;
|
||||||
|
use Drupal\views\Tests\ViewTestData;
|
||||||
|
use Drupal\views\Views;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the user posted or commented filter and argument handlers.
|
||||||
|
*
|
||||||
|
* @group comment
|
||||||
|
*/
|
||||||
|
class FilterAndArgumentUserUidTest extends KernelTestBase {
|
||||||
|
|
||||||
|
use CommentTestTrait;
|
||||||
|
use NodeCreationTrait;
|
||||||
|
use UserCreationTrait;
|
||||||
|
use ViewResultAssertionTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected static $modules = [
|
||||||
|
'comment',
|
||||||
|
'comment_test_views',
|
||||||
|
'field',
|
||||||
|
'filter',
|
||||||
|
'node',
|
||||||
|
'system',
|
||||||
|
'text',
|
||||||
|
'user',
|
||||||
|
'views',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Views used by this test.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $testViews = ['test_comment_user_uid'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the user posted or commented filter and argument handlers.
|
||||||
|
*/
|
||||||
|
public function testHandlers() {
|
||||||
|
$this->installEntitySchema('user');
|
||||||
|
$this->installSchema('system', ['sequences']);
|
||||||
|
$this->installEntitySchema('node');
|
||||||
|
$this->installEntitySchema('comment');
|
||||||
|
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||||
|
$this->installConfig(['filter']);
|
||||||
|
|
||||||
|
NodeType::create(['type' => 'page'])->save();
|
||||||
|
|
||||||
|
FieldStorageConfig::create([
|
||||||
|
'type' => 'text_long',
|
||||||
|
'entity_type' => 'comment',
|
||||||
|
'field_name' => 'comment_body',
|
||||||
|
])->save();
|
||||||
|
$this->addDefaultCommentField('node', 'page', 'comment');
|
||||||
|
|
||||||
|
$account = $this->createUser();
|
||||||
|
$other_account = $this->createUser();
|
||||||
|
|
||||||
|
$node_authored_by_account = $this->createNode([
|
||||||
|
'uid' => $account->id(),
|
||||||
|
'title' => "authored by {$account->id()}",
|
||||||
|
]);
|
||||||
|
$node_commented_by_account = $this->createNode([
|
||||||
|
'title' => "commented by {$account->id()}",
|
||||||
|
]);
|
||||||
|
$arbitrary_node = $this->createNode();
|
||||||
|
|
||||||
|
// Comment added by $account.
|
||||||
|
Comment::create([
|
||||||
|
'uid' => $account->id(),
|
||||||
|
'entity_id' => $node_commented_by_account->id(),
|
||||||
|
'entity_type' => 'node',
|
||||||
|
'field_name' => 'comment',
|
||||||
|
])->save();
|
||||||
|
// Comment added by $other_account on $node_commented_by_account
|
||||||
|
Comment::create([
|
||||||
|
'uid' => $other_account->id(),
|
||||||
|
'entity_id' => $node_commented_by_account->id(),
|
||||||
|
'entity_type' => 'node',
|
||||||
|
'field_name' => 'comment',
|
||||||
|
])->save();
|
||||||
|
// Comment added by $other_account on an arbitrary node.
|
||||||
|
Comment::create([
|
||||||
|
'uid' => $other_account->id(),
|
||||||
|
'entity_id' => $arbitrary_node->id(),
|
||||||
|
'entity_type' => 'node',
|
||||||
|
'field_name' => 'comment',
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
ViewTestData::createTestViews(static::class, ['comment_test_views']);
|
||||||
|
|
||||||
|
$expected_result = [
|
||||||
|
[
|
||||||
|
'nid' => $node_authored_by_account->id(),
|
||||||
|
'title' => "authored by {$account->id()}",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'nid' => $node_commented_by_account->id(),
|
||||||
|
'title' => "commented by {$account->id()}",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$column_map = ['nid' => 'nid', 'title' => 'title'];
|
||||||
|
$view = Views::getView('test_comment_user_uid');
|
||||||
|
|
||||||
|
// Test the argument handler.
|
||||||
|
$view->preview(NULL, [$account->id()]);
|
||||||
|
$this->assertIdenticalResultset($view, $expected_result, $column_map);
|
||||||
|
|
||||||
|
// Test the filter handler. Reuse the same view but replace the argument
|
||||||
|
// handler with a filter handler.
|
||||||
|
$view->removeHandler('default', 'argument', 'uid_touch');
|
||||||
|
$options = [
|
||||||
|
'id' => 'uid_touch',
|
||||||
|
'table' => 'node_field_data',
|
||||||
|
'field' => 'uid_touch',
|
||||||
|
'value' => [$account->id()],
|
||||||
|
];
|
||||||
|
$view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);
|
||||||
|
|
||||||
|
$view->preview();
|
||||||
|
$this->assertIdenticalResultset($view, $expected_result, $column_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue