Tests the createDuplicate() View method.
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,
)));
}
}