Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Views / RevisionCreateTimestampTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Views;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Tests\ViewTestData;
9 use Drupal\views\Views;
10
11 /**
12  * Ensures that the revision create time can be accessed in views.
13  *
14  * @group views
15  */
16 class RevisionCreateTimestampTest extends ViewsKernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['node_test_views', 'node', 'views', 'user'];
22
23   /**
24    * {@inheritdoc}
25    */
26   public static $testViews = ['test_node_revision_timestamp'];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp($import_test_views = TRUE) {
32     parent::setUp($import_test_views);
33
34     $this->installSchema('node', 'node_access');
35     $this->installEntitySchema('node');
36     $this->installEntitySchema('user');
37
38     if ($import_test_views) {
39       ViewTestData::createTestViews(get_class($this), ['node_test_views']);
40     }
41   }
42
43   public function testRevisionCreateTimestampView() {
44     $node_type = NodeType::create([
45       'type' => 'article',
46       'label' => 'Article',
47     ]);
48     $node_type->save();
49     $node = Node::create([
50       'title' => 'Test node',
51       'type' => 'article',
52       'revision_timestamp' => 1000,
53     ]);
54     $node->save();
55
56     $node->setRevisionCreationTime(1200);
57     $node->setNewRevision(TRUE);
58     $node->save();
59
60     $node->setRevisionCreationTime(1400);
61     $node->setNewRevision(TRUE);
62     $node->save();
63
64     $view = Views::getView('test_node_revision_timestamp');
65     $this->executeView($view);
66
67     $this->assertIdenticalResultset($view, [
68       ['vid' => 3, 'revision_timestamp' => 1400],
69       ['vid' => 2, 'revision_timestamp' => 1200],
70       ['vid' => 1, 'revision_timestamp' => 1000],
71     ], ['vid' => 'vid', 'revision_timestamp' => 'revision_timestamp']);
72   }
73
74 }