View source
<?php
namespace Drupal\Tests\node\Functional\Views\Wizard;
use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
use Drupal\views\Views;
class NodeRevisionWizardTest extends WizardTestBase {
protected $defaultTheme = 'stark';
public function testViewAdd() {
$this
->drupalCreateContentType([
'type' => 'article',
]);
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$node = $node_storage
->create([
'title' => $this
->randomString(),
'type' => 'article',
'changed' => REQUEST_TIME + 40,
]);
$node
->save();
$node = $node
->createDuplicate();
$node
->setNewRevision();
$node->changed->value = REQUEST_TIME + 20;
$node
->save();
$node = $node_storage
->create([
'title' => $this
->randomString(),
'type' => 'article',
'changed' => REQUEST_TIME + 30,
]);
$node
->save();
$node = $node
->createDuplicate();
$node
->setNewRevision();
$node->changed->value = REQUEST_TIME + 10;
$node
->save();
$this
->drupalCreateContentType([
'type' => 'not-article',
]);
$node = $node_storage
->create([
'title' => $this
->randomString(),
'type' => 'not-article',
'changed' => REQUEST_TIME + 80,
]);
$node
->save();
$type = [
'show[wizard_key]' => 'node_revision',
];
$this
->drupalGet('admin/structure/views/add');
$this
->submitForm($type, 'Update "Show" choice');
$view = [];
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['description'] = $this
->randomMachineName(16);
$view['page[create]'] = FALSE;
$view['show[type]'] = 'article';
$view['show[sort]'] = 'changed:DESC';
$this
->submitForm($view, 'Save and edit');
$view = Views::getView($view['id']);
$view
->initHandlers();
$this
->assertEquals([
'node_field_revision' => TRUE,
'#global' => TRUE,
'node_field_data' => TRUE,
], $view
->getBaseTables());
$this
->assertEquals('node_field_revision', $view->filter['status']->table);
$this
->assertEquals('status', $view->filter['status']->field);
$this
->assertEquals('1', $view->filter['status']->value);
$this
->assertEquals('node_field_data', $view->filter['type']->table);
$this
->executeView($view);
$this
->assertIdenticalResultset($view, [
[
'vid' => 1,
],
[
'vid' => 3,
],
[
'vid' => 2,
],
[
'vid' => 4,
],
], [
'vid' => 'vid',
]);
$type = [
'show[wizard_key]' => 'node_revision',
];
$this
->drupalGet('admin/structure/views/add');
$this
->submitForm($type, 'Update "Show" choice');
$view = [];
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['description'] = $this
->randomMachineName(16);
$view['page[create]'] = FALSE;
$view['show[type]'] = 'all';
$view['show[sort]'] = 'changed:DESC';
$this
->submitForm($view, 'Save and edit');
$view = Views::getView($view['id']);
$view
->initHandlers();
$this
->assertEquals([
'node_field_revision' => TRUE,
'#global' => TRUE,
], $view
->getBaseTables());
$this
->assertEquals('node_field_revision', $view->filter['status']->table);
$this
->assertEquals('status', $view->filter['status']->field);
$this
->assertEquals('1', $view->filter['status']->value);
$this
->assertArrayNotHasKey('type', $view->filter);
$this
->executeView($view);
$this
->assertIdenticalResultset($view, [
[
'vid' => 5,
],
[
'vid' => 1,
],
[
'vid' => 3,
],
[
'vid' => 2,
],
[
'vid' => 4,
],
], [
'vid' => 'vid',
]);
}
}