public function ServicesResourceWebformTests::testNewEndpointWebformIndex in Webform Service 7.4
testing node_resource Index
File
- tests/
ServicesResourceWebformTests.test, line 165
Class
- ServicesResourceWebformTests
- Run test cases for the endpoint with no authentication turned on.
Code
public function testNewEndpointWebformIndex() {
$types = webform_variable_get('webform_node_types');
// Create and log in our privileged user.
$this->privilegedUser = $this
->drupalCreateUser(array(
'administer services',
'perform unlimited index queries',
));
$this
->drupalLogin($this->privilegedUser);
// Create a set of nodes. The node resource returns 20 returns at a time,
// so we create two pages and a half worth.
$nodes = array();
$count = 50;
for ($i = 0; $i < $count; $i++) {
$node = $this
->drupalCreateNode(array(
'type' => $types[0],
));
$nodes[$node->uuid] = $node;
}
// Get the content.
$page_count = ceil(count($nodes) / 20);
$retrieved_nodes = array();
for ($page = 0; $page < $page_count; $page++) {
$responseArray = $this
->servicesGet($this->endpoint->path . '/' . $types[0], array(
'page' => $page,
));
$this
->assertTrue(count($responseArray['body']) <= 20, t('Correct number of items returned'));
// Store the returned node IDs.
foreach ($responseArray['body'] as $node) {
if (isset($retrieved_nodes[$node->uuid])) {
$this
->fail(t('Duplicate node @uuid returned.', array(
'@uuid' => $node->uuid,
)));
}
$retrieved_nodes[$node->uuid] = TRUE;
$this
->assertTrue($nodes[$node->uuid]->title == $node->title, t('Successfully received Node info'), 'NodeResource: Index');
}
}
// We should have got all the nodes.
$expected_nids = array_keys($nodes);
sort($expected_nids);
$retrieved_nids = array_keys($retrieved_nodes);
sort($retrieved_nids);
$this
->assertEqual($expected_nids, $retrieved_nids, t('Retrieved all nodes'));
// The n+1 page should be empty.
$responseArray = $this
->servicesGet($this->endpoint->path . '/' . $types[0], array(
'page' => $page_count + 1,
));
$this
->assertEqual(count($responseArray['body']), 0, t('The n+1 page is empty'));
// Adjust the pager size.
$responseArray = $this
->servicesGet($this->endpoint->path . '/' . $types[0], array(
'pagesize' => 40,
));
$this
->assertTrue(count($responseArray['body']) == 40, t('Correct number of items returned'));
// Swap to user that can only use the default pager size.
$this->lessPrivilegedUser = $this
->drupalCreateUser(array(
'administer services',
));
$this
->drupalLogin($this->lessPrivilegedUser);
$responseArray = $this
->servicesGet($this->endpoint->path . '/' . $types[0], array(
'pagesize' => 40,
));
$this
->assertTrue(count($responseArray['body']) == 20, t('Correct number of items returned'));
}