You are here

function ServicesViewsSecurityUpgradePathTest::testViewsResourceBackwardCompatibility in Services Views 7

Insure path backward compatibility when views resource is enabled.

File

tests/services_views_upgrade_path.test, line 217
Security upgrade tests for the Services Views module.

Class

ServicesViewsSecurityUpgradePathTest
Api call tests for the security upgrade from 1.2 to 1.3.

Code

function testViewsResourceBackwardCompatibility() {
  $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,
    );
  }
  $prefix = "services_views_" . $this->endpoint->name;
  variable_set($prefix . '_white_list', 1);
  variable_set($prefix . "_view_displays", array(
    'services_views_sorted_nodes|default' => '0',
    'services_views_sorted_nodes|page' => 'services_views_sorted_nodes|page',
    'services_views_sorted_nodes|block_1' => '0',
    'services_views_sorted_nodes|services_1' => '0',
  ));
  services_views_convert_white_list_to_clones();

  // Test the old display to make sure it works.
  $responseArray = $this
    ->servicesGet($this->endpoint->path . '/views/services_views_sorted_nodes', array(
    'display_id' => 'services_clone_page',
  ));
  $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);
  $responseArray = $this
    ->servicesGet($this->endpoint->path . '/views/services_views_sorted_nodes', array(
    'display_id' => 'page',
  ));
  $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);
}