public function RestfulCreateEntityTestCase::testFileUploadAccess in RESTful 7
Same name and namespace in other branches
- 7.2 tests/RestfulCreateEntityTestCase.test \RestfulCreateEntityTestCase::testFileUploadAccess()
Test access for file upload.
File
- tests/
RestfulCreateEntityTestCase.test, line 184 - Contains RestfulCreateEntityTestCase
Class
- RestfulCreateEntityTestCase
- @file Contains RestfulCreateEntityTestCase
Code
public function testFileUploadAccess() {
variable_set('restful_file_upload', TRUE);
variable_set('restful_file_upload_allow_anonymous_user', TRUE);
// Test access for anonymous user (allowed).
$return = $this
->uploadFile();
$this
->assertEqual($return['code'], 200, 'File upload is allowed to anonymous users.');
variable_set('restful_file_upload_allow_anonymous_user', FALSE);
// Now that we have a successfully uploaded file, make sure it's the same
// file that was uploaded.
$original = hash_file('md5', $this->imagePath);
$return_array = drupal_json_decode($return['body']);
$file = file_load($return_array['data'][0]['id']);
$uploaded = hash_file('md5', file_create_url($file->uri));
$this
->assertEqual($original, $uploaded, 'Original and uploaded file are identical.');
// Test access for anonymous user (denied).
$return = $this
->uploadFile();
$this
->assertEqual($return['code'], 403, 'File upload is denied to anonymous users.');
$this
->drupalLogin($this->account);
// Test access for authenticated users (allowed).
$return = $this
->uploadFile();
$this
->assertEqual($return['code'], 200, 'File upload is allowed to authenticated users.');
// Test access for authenticated users (denied).
variable_set('restful_file_upload', FALSE);
$return = $this
->uploadFile();
$this
->assertEqual($return['code'], 403, 'File upload is denied to authenticated users.');
}