View source
<?php
namespace Drupal\datetime\Tests\Views;
use Drupal\views\Views;
class ArgumentDateTimeTest extends DateTimeHandlerTestBase {
public static $testViews = [
'test_argument_datetime',
];
public function setUp() {
parent::setUp();
$dates = [
'2000-10-10',
'2001-10-10',
'2002-01-01',
];
foreach ($dates as $date) {
$this->nodes[] = $this
->drupalCreateNode([
'field_date' => [
'value' => $date,
],
]);
}
}
public function testDatetimeArgumentYear() {
$view = Views::getView('test_argument_datetime');
$view
->setDisplay('default');
$this
->executeView($view, [
'2000',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[0]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
$view
->setDisplay('default');
$this
->executeView($view, [
'2002',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[2]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
}
public function testDatetimeArgumentMonth() {
$view = Views::getView('test_argument_datetime');
$view
->setDisplay('embed_1');
$this
->executeView($view, [
'10',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[0]
->id(),
];
$expected[] = [
'nid' => $this->nodes[1]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
$view
->setDisplay('embed_1');
$this
->executeView($view, [
'01',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[2]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
}
public function testDatetimeArgumentDay() {
$view = Views::getView('test_argument_datetime');
$view
->setDisplay('embed_2');
$this
->executeView($view, [
'10',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[0]
->id(),
];
$expected[] = [
'nid' => $this->nodes[1]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
$view
->setDisplay('embed_2');
$this
->executeView($view, [
'01',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[2]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
}
public function testDatetimeArgumentAll() {
$view = Views::getView('test_argument_datetime');
$view
->setDisplay('embed_3');
$this
->executeView($view, [
'2000',
'10',
'10',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[0]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
$view
->setDisplay('embed_3');
$this
->executeView($view, [
'2002',
'01',
'01',
]);
$expected = [];
$expected[] = [
'nid' => $this->nodes[2]
->id(),
];
$this
->assertIdenticalResultset($view, $expected, $this->map);
$view
->destroy();
}
}