You are here

public function ViewStorageTest::testCreateDuplicate in Views (for Drupal 7) 8.3

Tests the createDuplicate() View method.

File

lib/Drupal/views/Tests/ViewStorageTest.php, line 437
Definition of Drupal\views\Tests\ViewStorageTest.

Class

ViewStorageTest
Tests the functionality of ViewStorage and ViewStorageController.

Namespace

Drupal\views\Tests

Code

public function testCreateDuplicate() {
  $view = views_get_view('archive');
  $copy = $view
    ->createDuplicate();
  $this
    ->assertTrue($copy instanceof ViewStorage, '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 ('') as it
  // gets unset.
  $this
    ->assertIdentical($copy
    ->id(), '', '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',
    'api_version',
    'description',
    'tag',
    'base_table',
    'human_name',
    'core',
  );
  foreach ($config_properties as $property) {
    $this
      ->assertIdentical($view->storage->{$property}, $copy->{$property}, format_string('@property property is identical.', array(
      '@property' => $property,
    )));
  }

  // Check the displays are the same.
  foreach ($view->storage->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,
    )));
  }
}