You are here

protected function FilterDateTest::setUp in Drupal 8

Same name in this branch
  1. 8 core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::setUp()
  2. 8 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::setUp()
  3. 8 core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp()
  4. 8 core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::setUp()
Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::setUp()

Overrides ViewTestBase::setUp

File

core/modules/views/tests/src/Functional/Handler/FilterDateTest.php, line 46

Class

FilterDateTest
Tests the core Drupal\views\Plugin\views\filter\Date handler.

Namespace

Drupal\Tests\views\Functional\Handler

Code

protected function setUp($import_test_views = TRUE) {
  parent::setUp($import_test_views);
  $this->dateFormatter = $this->container
    ->get('date.formatter');

  // Add a date field so we can test datetime handling.
  NodeType::create([
    'type' => 'page',
    'name' => 'Page',
  ])
    ->save();

  // Setup a field storage and field, but also change the views data for the
  // entity_test entity type.
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'field_date',
    'type' => 'datetime',
    'entity_type' => 'node',
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_name' => 'field_date',
    'entity_type' => 'node',
    'bundle' => 'page',
  ]);
  $field
    ->save();

  // Add some basic test nodes.
  $this->nodes = [];
  $this->nodes[] = $this
    ->drupalCreateNode([
    'created' => 100000,
    'field_date' => 10000,
  ]);
  $this->nodes[] = $this
    ->drupalCreateNode([
    'created' => 200000,
    'field_date' => 20000,
  ]);
  $this->nodes[] = $this
    ->drupalCreateNode([
    'created' => 300000,
    'field_date' => 30000,
  ]);
  $this->nodes[] = $this
    ->drupalCreateNode([
    'created' => time() + 86400,
    'field_date' => time() + 86400,
  ]);
  $this->map = [
    'nid' => 'nid',
  ];
}