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