FilterUidRevisionTest.php 2.31 KB
Newer Older
1
2
<?php

3
namespace Drupal\Tests\node\Kernel\Views;
4

5
6
7
8
9
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
10
11
use Drupal\views\Views;

12
13
/**
 * Tests the node_uid_revision handler.
14
15
 *
 * @group node
16
 */
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class FilterUidRevisionTest extends KernelTestBase {

  use NodeCreationTrait;
  use UserCreationTrait;
  use ViewResultAssertionTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'filter',
    'node',
    'node_test_views',
    'system',
    'user',
    'views',
  ];
34

35
36
37
38
39
  /**
   * Views used by this test.
   *
   * @var array
   */
40
  public static $testViews = ['test_filter_node_uid_revision'];
41

42
43
44
45
  /**
   * Tests the node_uid_revision filter.
   */
  public function testFilter() {
46
47
48
49
50
51
52
53
54
55
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installEntitySchema('view');
    $this->installSchema('system', ['sequences']);
    $this->installSchema('node', ['node_access']);
    $this->installConfig(['filter']);
    ViewTestData::createTestViews(static::class, ['node_test_views']);

    $author = $this->createUser();
    $no_author = $this->createUser();
56

57
    $expected_result = [];
58
    // Create one node, with the author as the node author.
59
    $node = $this->createNode(['uid' => $author->id()]);
60
    $expected_result[] = ['nid' => $node->id()];
61
62
    // Create one node of which an additional revision author will be the
    // author.
63
    $node = $this->createNode(['revision_uid' => $no_author->id()]);
64
    $expected_result[] = ['nid' => $node->id()];
65
66
67
68
69
70
71
72
    $revision = clone $node;
    // Force to add a new revision.
    $revision->set('vid', NULL);
    $revision->set('revision_uid', $author->id());
    $revision->save();

    // Create one  node on which the author has neither authorship of revisions
    // or the main node.
73
    $this->createNode(['uid' => $no_author->id()]);
74

75
    $view = Views::getView('test_filter_node_uid_revision');
76
    $view->initHandlers();
77
    $view->filter['uid_revision']->value = [$author->id()];
78

79
    $view->preview();
80
    $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.');
81
82
83
  }

}