public function ViewsCloneTest::testClone in Views (for Drupal 7) 7.3
Test cloning a view.
File
- tests/
views_clone.test, line 51
Class
- ViewsCloneTest
- Tests cloning a view.
Code
public function testClone() {
// Prepare view to be cloned.
$view = $this
->getTestCloneView();
$view
->set_arguments(array(
0 => $this->node->nid,
));
$view
->set_exposed_input(array(
'field_tags_tid' => $this->term->tid,
));
// Execute view to be cloned.
$result = $view
->execute();
// To make sure that we are properly testing removal of all properties, we
// first need to assert that they are actually present in the original view.
$keys = array(
'current_display',
'display_handler',
'field',
'argument',
'filter',
'sort',
'relationship',
'header',
'footer',
'empty',
'query',
'inited',
'style_plugin',
'plugin_name',
'exposed_data',
'exposed_input',
'exposed_widgets',
'many_to_one_aliases',
'many_to_one_tables',
'feed_icon',
);
foreach ($keys as $key) {
$this
->assertTrue(isset($view->{$key}), $key . 'is set in original view.');
}
$this
->assertTrue($view->built, 'Assert original view built.');
$this
->assertTrue($view->executed, 'Assert original view executed.');
$this
->assertNotEqual($view->build_info, array(), 'Assert original view has build_info.');
$this
->assertNotEqual($view->attachment_before, '', 'Assert original view has attachment_before.');
$this
->assertNotEqual($view->attachment_after, '', 'Assert original view has attachment_after.');
$this
->assertNotEqual($view->result, array(), 'Assert original view has result.');
// Clone view.
$clone = $view
->clone_view();
// Assert that all relevant properties have been removed or reset.
$keys = array(
'current_display',
'display_handler',
'field',
'argument',
'filter',
'sort',
'relationship',
'header',
'footer',
'empty',
'query',
'inited',
'style_plugin',
'plugin_name',
'exposed_data',
'exposed_input',
'exposed_widgets',
'many_to_one_aliases',
'many_to_one_tables',
'feed_icon',
);
foreach ($keys as $key) {
$this
->assertFalse(isset($clone->{$key}), $key . ' has been removed in cloned view.');
}
foreach ($clone->display as $id => $display) {
$this
->assertFalse(isset($clone->display[$id]->handler), 'Make sure all display handlers have been destroyed.');
}
$this
->assertFalse($clone->built, 'Assert cloned view not built.');
$this
->assertFalse($clone->executed, 'Assert cloned view not executed.');
$this
->assertEqual($clone->build_info, array(), 'Assert cloned view has empty build_info.');
$this
->assertEqual($clone->attachment_before, '', 'Assert cloned view has empty attachment_before.');
$this
->assertEqual($clone->attachment_after, '', 'Assert cloned view has empty attachment_after.');
$this
->assertEqual($clone->result, array(), 'Assert cloned view has empty result.');
// Execute cloned view.
$clone
->execute();
// Assert result sets are equal.
$this
->assertEqual($view->result, $clone->result, 'Result sets of cloned view and original view match.');
}