You are here

class DateTimeSchemaTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/datetime/tests/src/Kernel/Views/DateTimeSchemaTest.php \Drupal\Tests\datetime\Kernel\Views\DateTimeSchemaTest
  2. 9 core/modules/datetime/tests/src/Kernel/Views/DateTimeSchemaTest.php \Drupal\Tests\datetime\Kernel\Views\DateTimeSchemaTest

Tests the Drupal\datetime\Plugin\views schemas.

@group datetime

Hierarchy

Expanded class hierarchy of DateTimeSchemaTest

File

core/modules/datetime/tests/src/Kernel/Views/DateTimeSchemaTest.php, line 13

Namespace

Drupal\Tests\datetime\Kernel\Views
View source
class DateTimeSchemaTest extends DateTimeHandlerTestBase {
  use SchemaCheckTestTrait;

  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'test_argument_datetime',
    'test_filter_datetime',
    'test_sort_datetime',
  ];

  /**
   * Tests argument plugin schema.
   */
  public function testDateTimeSchema() {

    // Test argument schema.
    $view = Views::getView('test_argument_datetime');
    $view
      ->initHandlers();
    $view
      ->setDisplay('default');
    $arguments = $view->displayHandlers
      ->get('default')
      ->getOption('arguments');
    $arguments['field_date_value_year']['date'] = 'Date';
    $view->displayHandlers
      ->get('default')
      ->overrideOption('arguments', $arguments);
    $view
      ->save();
    $this
      ->assertConfigSchemaByName('views.view.test_argument_datetime');

    // Test filter schema.
    $view = Views::getView('test_filter_datetime');
    $view
      ->initHandlers();
    $filters = $view->displayHandlers
      ->get('default')
      ->getOption('filters');
    $filters['field_date_value']['type'] = 'date';
    $view->displayHandlers
      ->get('default')
      ->overrideOption('filters', $filters);
    $view
      ->save();
    $this
      ->assertConfigSchemaByName('views.view.test_filter_datetime');

    // Test sort schema.
    $view = Views::getView('test_sort_datetime');
    $view
      ->initHandlers();
    $sorts = $view->displayHandlers
      ->get('default')
      ->getOption('sorts');
    $this
      ->assertNotEmpty($sorts['field_date_value']['granularity']);
    $this
      ->assertConfigSchemaByName('views.view.test_sort_datetime');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateTimeSchemaTest::$testViews public static property
DateTimeSchemaTest::testDateTimeSchema public function Tests argument plugin schema.
SchemaCheckTestTrait::assertConfigSchema public function Asserts the TypedConfigManager has a valid schema for the configuration.
SchemaCheckTestTrait::assertConfigSchemaByName public function Asserts configuration, specified by name, has a valid schema.
SchemaCheckTrait::$configName protected property The configuration object name under test.
SchemaCheckTrait::$schema protected property The config schema wrapper object for the configuration object under test.
SchemaCheckTrait::checkConfigSchema public function Checks the TypedConfigManager has a valid schema for the configuration.
SchemaCheckTrait::checkValue protected function Helper method to check data type.