db70b2c9da574ece0e03d865369a47b4652962c6
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / NodeRevisionWizardTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional\Views;
4
5 use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the wizard with node_revision as base table.
10  *
11  * @group node
12  * @see \Drupal\node\Plugin\views\wizard\NodeRevision
13  */
14 class NodeRevisionWizardTest extends WizardTestBase {
15
16   /**
17    * Tests creating a node revision view.
18    */
19   public function testViewAdd() {
20     $this->drupalCreateContentType(['type' => 'article']);
21     // Create two nodes with two revision.
22     $node_storage = \Drupal::entityManager()->getStorage('node');
23     /** @var \Drupal\node\NodeInterface $node */
24     $node = $node_storage->create(['title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 40]);
25     $node->save();
26
27     $node = $node->createDuplicate();
28     $node->setNewRevision();
29     $node->created->value = REQUEST_TIME + 20;
30     $node->save();
31
32     $node = $node_storage->create(['title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 30]);
33     $node->save();
34
35     $node = $node->createDuplicate();
36     $node->setNewRevision();
37     $node->created->value = REQUEST_TIME + 10;
38     $node->save();
39
40     $view = [];
41     $view['label'] = $this->randomMachineName(16);
42     $view['id'] = strtolower($this->randomMachineName(16));
43     $view['description'] = $this->randomMachineName(16);
44     $view['page[create]'] = FALSE;
45     $view['show[wizard_key]'] = 'node_revision';
46     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
47
48     $view_storage_controller = \Drupal::entityManager()->getStorage('view');
49     /** @var \Drupal\views\Entity\View $view */
50     $view = $view_storage_controller->load($view['id']);
51
52     $this->assertEqual($view->get('base_table'), 'node_field_revision');
53
54     $executable = Views::executableFactory()->get($view);
55     $this->executeView($executable);
56
57     $this->assertIdenticalResultset($executable, [['vid' => 1], ['vid' => 3], ['vid' => 2], ['vid' => 4]],
58       ['vid' => 'vid']);
59   }
60
61 }