public function ViewStorageTest::testCreateDuplicate

Tests the createDuplicate() View method.

File

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

Class

ViewStorageTest
Tests the functionality of View and ViewStorageController.

Namespace

Drupal\views\Tests

Code

public function testCreateDuplicate() {
  $view = views_get_view('test_view_storage');
  $copy = $view->storage
    ->createDuplicate();
  $this
    ->assertTrue($copy instanceof View, 'The copied object is a View.');

  // Check that the original view and the copy have different UUIDs.
  $this
    ->assertNotIdentical($view->storage
    ->uuid(), $copy
    ->uuid(), 'The copied view has a new UUID.');

  // Check the 'name' (ID) is using the View objects default value (NULL) as it
  // gets unset.
  $this
    ->assertIdentical($copy
    ->id(), NULL, 'The ID has been reset.');

  // Check the other properties.
  // @todo Create a reusable property on the base test class for these?
  $config_properties = array(
    'disabled',
    'description',
    'tag',
    'base_table',
    'label',
    'core',
  );
  foreach ($config_properties as $property) {
    $this
      ->assertIdentical($view->storage
      ->get($property), $copy
      ->get($property), format_string('@property property is identical.', array(
      '@property' => $property,
    )));
  }

  // Check the displays are the same.
  $copy_display = $copy
    ->get('display');
  foreach ($view->storage
    ->get('display') as $id => $display) {

    // assertIdentical will not work here.
    $this
      ->assertEqual($display, $copy_display[$id], format_string('The @display display has been copied correctly.', array(
      '@display' => $id,
    )));
  }
}