function ViewStorageTest::createTests

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::createTests()
  2. 8.9.x core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::createTests()
  3. 11.x core/modules/views/tests/src/Kernel/ViewStorageTest.php \Drupal\Tests\views\Kernel\ViewStorageTest::createTests()

Tests creating configuration entities.

1 call to ViewStorageTest::createTests()
ViewStorageTest::testConfigurationEntityCRUD in core/modules/views/tests/src/Kernel/ViewStorageTest.php
Tests CRUD operations.

File

core/modules/views/tests/src/Kernel/ViewStorageTest.php, line 117

Class

ViewStorageTest
Tests the CRUD functionality for a view.

Namespace

Drupal\Tests\views\Kernel

Code

protected function createTests() {
  // Create a new View instance with empty values.
  $created = $this->controller
    ->create([]);
  $this->assertInstanceOf(View::class, $created);
  // Check that the View contains all of the properties.
  foreach ($this->configProperties as $property) {
    $this->assertTrue(property_exists($created, $property), "Property: {$property} created on View.");
  }
  // Create a new View instance with config values.
  $values = $this->config('views.view.test_view_storage')
    ->get();
  $values['id'] = 'test_view_storage_new';
  unset($values['uuid']);
  $created = $this->controller
    ->create($values);
  $this->assertInstanceOf(View::class, $created);
  // Check that the View contains all of the properties.
  $properties = $this->configProperties;
  // Remove display from list.
  array_pop($properties);
  // Test all properties except displays.
  foreach ($properties as $property) {
    $this->assertNotNull($created->get($property), "Property: {$property} created on View.");
    $this->assertSame($values[$property], $created->get($property), "Property value: {$property} matches configuration value.");
  }
  // Check the UUID of the loaded View.
  $created->save();
  $created_loaded = View::load('test_view_storage_new');
  $this->assertSame($created->uuid(), $created_loaded->uuid(), 'The created UUID has been saved correctly.');
}

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