protected function ViewStorageTest::createTests

Tests creating configuration entities.

1 call to ViewStorageTest::createTests()
ViewStorageTest::testConfigurationEntityCRUD in drupal/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php
Tests CRUD operations.

File

drupal/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php, line 132
Definition of Drupal\views\Tests\ViewStorageTest.

Class

ViewStorageTest
Tests the functionality of View and ViewStorageController.

Namespace

Drupal\views\Tests

Code

protected function createTests() {

  // Create a new View instance with empty values.
  $created = $this->controller
    ->create(array());
  $this
    ->assertTrue($created instanceof View, 'Created object is a View.');

  // Check that the View contains all of the properties.
  foreach ($this->config_properties as $property) {
    $this
      ->assertTrue(property_exists($created, $property), format_string('Property: @property created on View.', array(
      '@property' => $property,
    )));
  }

  // Create a new View instance with config values.
  $values = config('views.view.test_view_storage')
    ->get();
  $created = $this->controller
    ->create($values);
  $this
    ->assertTrue($created instanceof View, 'Created object is a View.');

  // Check that the View contains all of the properties.
  $properties = $this->config_properties;

  // Remove display from list.
  array_pop($properties);

  // Test all properties except displays.
  foreach ($properties as $property) {
    $this
      ->assertTrue($created
      ->get($property) !== NULL, format_string('Property: @property created on View.', array(
      '@property' => $property,
    )));
    $this
      ->assertIdentical($values[$property], $created
      ->get($property), format_string('Property value: @property matches configuration value.', array(
      '@property' => $property,
    )));
  }

  // Check the UUID of the loaded View.
  $created
    ->set('id', 'test_view_storage_new');
  $created
    ->save();
  $created_loaded = entity_load('view', 'test_view_storage_new');
  $this
    ->assertIdentical($created
    ->uuid(), $created_loaded
    ->uuid(), 'The created UUID has been saved correctly.');
}