Commit 61c3d57c authored by catch's avatar catch

Issue #2865992 by tar_inet, Lendude, mpdonadio, Wim Leers: Convert Datetime...

Issue #2865992 by tar_inet, Lendude, mpdonadio, Wim Leers: Convert Datetime module Views tests to Kerneltest
parent 78adae8b
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\datetime\Tests\Views; namespace Drupal\datetime\Tests\Views;
@trigger_error('\Drupal\datetime\Tests\Views\DateTimeHandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\BrowserTestBase', E_USER_DEPRECATED);
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
...@@ -11,6 +13,9 @@ ...@@ -11,6 +13,9 @@
/** /**
* Base class for testing datetime handlers. * Base class for testing datetime handlers.
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\BrowserTestBase.
*/ */
abstract class DateTimeHandlerTestBase extends HandlerTestBase { abstract class DateTimeHandlerTestBase extends HandlerTestBase {
......
<?php <?php
namespace Drupal\datetime\Tests\Views; namespace Drupal\Tests\datetime\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -19,8 +20,8 @@ class ArgumentDateTimeTest extends DateTimeHandlerTestBase { ...@@ -19,8 +20,8 @@ class ArgumentDateTimeTest extends DateTimeHandlerTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
// Add some basic test nodes. // Add some basic test nodes.
$dates = [ $dates = [
...@@ -29,11 +30,15 @@ protected function setUp() { ...@@ -29,11 +30,15 @@ protected function setUp() {
'2002-01-01', '2002-01-01',
]; ];
foreach ($dates as $date) { foreach ($dates as $date) {
$this->nodes[] = $this->drupalCreateNode([ $node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [ 'field_date' => [
'value' => $date, 'value' => $date,
] ]
]); ]);
$node->save();
$this->nodes[] = $node;
} }
} }
......
<?php
namespace Drupal\Tests\datetime\Kernel\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Base class for testing datetime handlers.
*/
abstract class DateTimeHandlerTestBase extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['datetime_test', 'node', 'datetime', 'field'];
/**
* Name of the field.
*
* Note, this is used in the default test view.
*
* @var string
*/
protected static $field_name = 'field_date';
/**
* Nodes to test.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $nodes = [];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
$this->installEntitySchema('user');
// Add a date field to page nodes.
$node_type = NodeType::create([
'type' => 'page',
'name' => 'page'
]);
$node_type->save();
$fieldStorage = FieldStorageConfig::create([
'field_name' => static::$field_name,
'entity_type' => 'node',
'type' => 'datetime',
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
]);
$fieldStorage->save();
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => 'page',
'required' => TRUE,
]);
$field->save();
// Views needs to be aware of the new field.
$this->container->get('views.views_data')->clear();
// Set column map.
$this->map = [
'nid' => 'nid',
];
// Load test views.
ViewTestData::createTestViews(get_class($this), ['datetime_test']);
}
}
<?php <?php
namespace Drupal\datetime\Tests\Views; namespace Drupal\Tests\datetime\Kernel\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -27,8 +29,8 @@ class FilterDateTest extends DateTimeHandlerTestBase { ...@@ -27,8 +29,8 @@ class FilterDateTest extends DateTimeHandlerTestBase {
* *
* Create nodes with relative dates of yesterday, today, and tomorrow. * Create nodes with relative dates of yesterday, today, and tomorrow.
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
// Set to 'today'. // Set to 'today'.
static::$date = REQUEST_TIME; static::$date = REQUEST_TIME;
...@@ -48,11 +50,15 @@ protected function setUp() { ...@@ -48,11 +50,15 @@ protected function setUp() {
]; ];
foreach ($dates as $date) { foreach ($dates as $date) {
$this->nodes[] = $this->drupalCreateNode([ $node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [ 'field_date' => [
'value' => $date, 'value' => $date,
] ]
]); ]);
$node->save();
$this->nodes[] = $node;
} }
} }
......
<?php <?php
namespace Drupal\datetime\Tests\Views; namespace Drupal\Tests\datetime\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -29,8 +30,8 @@ class FilterDateTimeTest extends DateTimeHandlerTestBase { ...@@ -29,8 +30,8 @@ class FilterDateTimeTest extends DateTimeHandlerTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
static::$date = REQUEST_TIME + 86400; static::$date = REQUEST_TIME + 86400;
...@@ -47,11 +48,15 @@ protected function setUp() { ...@@ -47,11 +48,15 @@ protected function setUp() {
\Drupal::service('date.formatter')->format(static::$date, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE), \Drupal::service('date.formatter')->format(static::$date, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE),
]; ];
foreach ($dates as $date) { foreach ($dates as $date) {
$this->nodes[] = $this->drupalCreateNode([ $node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [ 'field_date' => [
'value' => $date, 'value' => $date,
] ]
]); ]);
$node->save();
$this->nodes[] = $node;
} }
} }
......
<?php <?php
namespace Drupal\datetime\Tests\Views; namespace Drupal\Tests\datetime\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -19,8 +20,8 @@ class SortDateTimeTest extends DateTimeHandlerTestBase { ...@@ -19,8 +20,8 @@ class SortDateTimeTest extends DateTimeHandlerTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp($import_test_views = TRUE) {
parent::setUp(); parent::setUp($import_test_views);
// Add some basic test nodes. // Add some basic test nodes.
$dates = [ $dates = [
...@@ -33,11 +34,15 @@ protected function setUp() { ...@@ -33,11 +34,15 @@ protected function setUp() {
'2000-10-10T00:03:03', '2000-10-10T00:03:03',
]; ];
foreach ($dates as $date) { foreach ($dates as $date) {
$this->nodes[] = $this->drupalCreateNode([ $node = Node::create([
'title' => $this->randomMachineName(8),
'type' => 'page',
'field_date' => [ 'field_date' => [
'value' => $date, 'value' => $date,
] ]
]); ]);
$node->save();
$this->nodes[] = $node;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment