You are here

public function ServicesResourceFileTests::testResourceFileCreate in Services 7.3

Same name and namespace in other branches
  1. 6.3 tests/functional/ServicesResourceFileTests.test \ServicesResourceFileTests::testResourceFileCreate()

Test create method.

File

tests/functional/ServicesResourceFileTests.test, line 98
Test for file resource.

Class

ServicesResourceFileTests
Test class.

Code

public function testResourceFileCreate() {

  // Create file argument with data.
  $filepath = file_default_scheme() . '://' . rand() . '/' . rand() . '/' . $this->testfile->filename;
  $file = array(
    'filesize' => filesize($this->testfile->uri),
    'filename' => $this->testfile->filename,
    'filepath' => $filepath,
    'file' => base64_encode(file_get_contents($this->testfile->uri)),
    'uid' => $this->privileged_user->uid,
  );

  // Create file with call.
  $result = $this
    ->servicesPost($this->endpoint->path . '/file', $file);
  $this
    ->assertEqual($result['code'], 200, 'File created.', 'FileResource: Create');

  // Load file and assert that it exists.
  $file_load = file_load($result['body']['fid']);
  $this
    ->assertTrue(is_file($file_load->uri), 'New file saved to disk.', 'FileResource: Create');
  $this
    ->assertEqual($file_load->uri, $filepath, 'The path of newly created file placed into directory with random name.', 'FileResource: Create');
}