function FilterDateTest::setUp

Same name in this branch
  1. 10 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::setUp()
  2. 10 core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::setUp()
  3. 10 core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\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()
  2. 9 core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::setUp()
  3. 9 core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::setUp()
  4. 9 core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp()
  5. 8.9.x core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::setUp()
  6. 8.9.x core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::setUp()
  7. 8.9.x core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::setUp()
  8. 8.9.x core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp()
  9. 11.x core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::setUp()
  10. 11.x core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime_range\Kernel\Views\FilterDateTest::setUp()
  11. 11.x core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTest::setUp()
  12. 11.x core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php \Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp()

Sets up the test.

Parameters

bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

array $modules: The module directories to look in for test views.

Overrides ViewTestBase::setUp

File

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

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, $modules = [
  'views_test_config',
]) : void {
  parent::setUp($import_test_views, $modules);
  $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',
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.