public function ServicesResourceFileTests::testIndexFiles in Services 7.3
File
- tests/
functional/ ServicesResourceFileTests.test, line 57 - Test for file resource.
Class
- ServicesResourceFileTests
- Test class.
Code
public function testIndexFiles() {
// Create a set of files to test with
$files = array();
foreach ($this->testfiles as $file) {
file_save($file);
$files[$file->fid] = $file;
}
// Get the content.
$page_count = ceil(count($files) / 20);
$retrieved_files = array();
for ($page = 0; $page < $page_count; $page++) {
$responseArray = $this
->servicesGet($this->endpoint->path . '/file', array(
'page' => $page,
'fields' => 'fid,filename',
));
$this
->assertTrue(count($responseArray['body']) <= 20, 'Correct number of items returned');
// Store the returned file IDs.
foreach ($responseArray['body'] as $file) {
if (isset($retrieved_files[$file->fid])) {
$this
->fail(format_string('Duplicate files @fid returned.', array(
'@fid' => $file->fid,
)));
}
$retrieved_files[$file->fid] = TRUE;
$this
->assertTrue($files[$file->fid]->filename == $file->filename, 'Successfully received File info', 'FileResource: Index');
}
}
// We should have got all the files.
$expected_fids = array_keys($files);
sort($expected_fids);
$retrieved_fids = array_keys($retrieved_files);
sort($retrieved_fids);
$this
->assertEqual($expected_fids, $retrieved_fids, 'Retrieved all files');
// The n+1 page should be empty.
$responseArray = $this
->servicesGet($this->endpoint->path . '/file', array(
'page' => $page_count + 1,
));
$this
->assertEqual(count($responseArray['body']), 0, 'The n+1 page is empty');
}