uuid_services.file_services.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * Test the UUID File Services integration.
  5. */
  6. /**
  7. * Test the UUID File Services integration.
  8. */
  9. class UuidFileServicesTest extends ServicesWebTestCase {
  10. protected $priviledgedUser = NULL;
  11. protected $endpoint = NULL;
  12. /**
  13. * Implementation of getInfo().
  14. */
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'UUID File Services tests',
  18. 'description' => 'Test the file services resource UUID methods and actions.',
  19. 'group' => 'UUID',
  20. );
  21. }
  22. /**
  23. * Implementation of setUp().
  24. */
  25. public function setUp() {
  26. parent::setUp(
  27. 'ctools',
  28. 'services',
  29. 'rest_server',
  30. 'uuid_services',
  31. 'entity',
  32. 'file',
  33. 'field',
  34. 'file_entity'
  35. );
  36. $this->endpoint = $this->saveNewEndpoint();
  37. variable_set('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm');
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function saveNewEndpoint() {
  43. $edit = $this->populateEndpointFAPI();
  44. $endpoint = new stdClass();
  45. $endpoint->disabled = FALSE;
  46. $endpoint->api_version = 3;
  47. $endpoint->name = $edit['name'];
  48. $endpoint->server = $edit['server'];
  49. $endpoint->path = $edit['path'];
  50. $endpoint->authentication = array(
  51. 'services' => 'services',
  52. );
  53. $endpoint->server_settings = array(
  54. 'formatters' => array(
  55. 'json' => TRUE,
  56. 'bencode' => TRUE,
  57. 'rss' => TRUE,
  58. 'plist' => TRUE,
  59. 'xmlplist' => TRUE,
  60. 'php' => TRUE,
  61. 'yaml' => TRUE,
  62. 'jsonp' => FALSE,
  63. 'xml' => FALSE,
  64. ),
  65. 'parsers' => array(
  66. 'application/x-yaml' => TRUE,
  67. 'application/json' => TRUE,
  68. 'application/vnd.php.serialized' => TRUE,
  69. 'application/plist' => TRUE,
  70. 'application/plist+xml' => TRUE,
  71. 'application/x-www-form-urlencoded' => TRUE,
  72. 'multipart/form-data' => TRUE,
  73. ),
  74. );
  75. $endpoint->resources = array(
  76. 'file' => array(
  77. 'operations' => array(
  78. 'retrieve' => array(
  79. 'enabled' => '1',
  80. ),
  81. 'delete' => array(
  82. 'enabled' => '1',
  83. ),
  84. 'index' => array(
  85. 'enabled' => '1',
  86. ),
  87. 'update' => array(
  88. 'enabled' => '1',
  89. ),
  90. ),
  91. 'actions' => array(
  92. 'create_raw' => array(
  93. 'enabled' => '1',
  94. ),
  95. ),
  96. ),
  97. );
  98. $endpoint->debug = 1;
  99. $endpoint->export_type = FALSE;
  100. services_endpoint_save($endpoint);
  101. $endpoint = services_endpoint_load($endpoint->name);
  102. $this->assertTrue($endpoint->name == $edit['name'], 'Endpoint successfully created');
  103. return $endpoint;
  104. }
  105. /**
  106. * Tests file creation.
  107. */
  108. public function testFileUpdate() {
  109. $this->privilegedUser = $this->drupalCreateUser(array('create files'));
  110. $this->drupalLogin($this->privilegedUser);
  111. // Get a test file.
  112. $testfiles = $this->drupalGetTestFiles('php');
  113. $testfile = current($testfiles);
  114. // Setup file to be created.
  115. $filepath = file_default_scheme() . '://' . rand() . '/' . rand() . '/' . $testfile->filename;
  116. $file_data = array(
  117. 'uid' => '0',
  118. 'filesize' => filesize($testfile->uri),
  119. 'filename' => $testfile->filename,
  120. 'filepath' => $filepath,
  121. 'file' => base64_encode(file_get_contents($testfile->uri)),
  122. 'uuid' => 'ee26fe5d-f781-4a38-bfe0-8bb350b90073',
  123. 'type' => 'image',
  124. 'filemime' => 'text/plain',
  125. 'uri' => $testfile->uri,
  126. );
  127. $response = $this->servicesPut($this->endpoint->path . '/file/create', $file_data);
  128. // Get the saved file's extension.
  129. $file = file_load($response['body']->fid);
  130. $name = explode('.', $file->filename);
  131. $last = array_pop($name);
  132. $extension = strtolower($last);
  133. $this->assertNotEqual('php', $extension, 'File was not created with a "php" extension.', 'UUID: File Create');
  134. }
  135. }