public function ServicesViewsSecurityUpgradePathTest::testClone in Services Views 7
Test the upgraded clone to see if it produces the same output.
File
- tests/
services_views_upgrade_path.test, line 54 - Security upgrade tests for the Services Views module.
Class
- ServicesViewsSecurityUpgradePathTest
- Api call tests for the security upgrade from 1.2 to 1.3.
Code
public function testClone() {
$alphabet = range('A', 'Z');
$nodes = array();
$count = 5;
$results = array();
// TODO: set view as whitelisted.
for ($i = 0; $i < $count; $i++) {
$node = $this
->drupalCreateNode(array(
'title' => $alphabet[$i],
));
$nodes[$node->nid] = $node;
$results[] = array(
'title' => $node->title,
'nid' => $node->nid,
);
}
$view = views_get_view('services_views_sorted_nodes');
$this
->executeView($view, 'page');
$this
->assertIdenticalResultset($view, $results, array(
'node_title' => 'title',
'nid' => 'nid',
));
$new_display_name = services_views_clone_display($view, 'page');
$new_display = $view->display[$new_display_name];
$this
->verbose('<pre>' . print_r($new_display, TRUE) . '</pre>');
$this
->assertTrue($new_display->display_options['path'] == 'services_views_sorted_nodes/page');
$this
->assertTrue($new_display->display_options['access']['type'] == 'perm' && $new_display->display_options['access']['perm'] == 'view own unpublished content');
$this
->executeView($view, $new_display_name);
$this
->assertIdenticalResultset($view, $results, array(
'node_title' => 'title',
'nid' => 'nid',
));
// Test the new display to make sure it works.
$responseArray = $this
->servicesGet($this->endpoint->path . '/views/services_views_sorted_nodes', array(
'display_id' => $new_display_name,
));
$api_results = json_decode(json_encode($responseArray['body']), TRUE);
$results = array(
array(
'node_title' => 'A',
'nid' => '1',
),
array(
'node_title' => 'B',
'nid' => '2',
),
array(
'node_title' => 'C',
'nid' => '3',
),
array(
'node_title' => 'D',
'nid' => '4',
),
array(
'node_title' => 'E',
'nid' => '5',
),
);
$this
->assertEqual($results, $api_results);
// Test the old display name to make sure backward compatibility works.
$responseArray = $this
->servicesGet($this->endpoint->path . '/views/services_views_sorted_nodes', array(
'display_id' => $new_display_name,
));
$api_results = json_decode(json_encode($responseArray['body']), TRUE);
$this
->assertEqual($results, $api_results);
// TODO: Test that the custom resource and views resource output the same
// thing. Currently this isn't the case on 9-3-17. @see #1647360.
}