1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Tests for the remote_stream_wrapper module.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
class RemoteStreamWrapperTestCase extends DrupalWebTestCase {
|
8 |
|
|
public static function getInfo() {
|
9 |
|
|
return array(
|
10 |
|
|
'name' => 'Remote stream wrapper',
|
11 |
|
|
'description' => 'Tests functionality for remote stream wrappers.',
|
12 |
6331c987
|
Assos Assos
|
'group' => 'Remote stream wrapper',
|
13 |
85ad3d82
|
Assos Assos
|
);
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
function setUp() {
|
17 |
|
|
parent::setUp(array('remote_stream_wrapper', 'image'));
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Override DrupalWebTestCase::drupalGetTestFiles to return 'external' files.
|
22 |
|
|
*/
|
23 |
|
|
protected function drupalGetTestFiles($type, $size = NULL) {
|
24 |
|
|
$files = parent::drupalGetTestFiles($type, $size);
|
25 |
|
|
foreach ($files as $file) {
|
26 |
|
|
$file->original_uri = $file->uri;
|
27 |
|
|
$file->uri = file_create_url($file->uri);
|
28 |
|
|
}
|
29 |
|
|
return $files;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
* Test STREAM_WRAPPERS_REMOTE bitmask and file_get_remote_stream_wrappers().
|
34 |
|
|
*/
|
35 |
|
|
function testBitMasks() {
|
36 |
|
|
$cases = array(
|
37 |
|
|
array('filter' => STREAM_WRAPPERS_ALL, 'result' => TRUE),
|
38 |
|
|
array('filter' => STREAM_WRAPPERS_LOCAL, 'result' => TRUE),
|
39 |
|
|
array('filter' => STREAM_WRAPPERS_READ, 'result' => TRUE),
|
40 |
|
|
array('filter' => STREAM_WRAPPERS_WRITE, 'result' => FALSE),
|
41 |
|
|
array('filter' => STREAM_WRAPPERS_VISIBLE, 'result' => TRUE),
|
42 |
|
|
array('filter' => STREAM_WRAPPERS_HIDDEN, 'result' => FALSE),
|
43 |
|
|
array('filter' => STREAM_WRAPPERS_LOCAL_HIDDEN, 'result' => FALSE),
|
44 |
|
|
array('filter' => STREAM_WRAPPERS_WRITE_VISIBLE, 'result' => FALSE),
|
45 |
|
|
array('filter' => STREAM_WRAPPERS_READ_VISIBLE, 'result' => TRUE),
|
46 |
|
|
array('filter' => STREAM_WRAPPERS_NORMAL, 'result' => FALSE),
|
47 |
|
|
array('filter' => STREAM_WRAPPERS_LOCAL_NORMAL, 'result' => FALSE),
|
48 |
|
|
);
|
49 |
|
|
|
50 |
|
|
foreach ($cases as $case) {
|
51 |
|
|
$wrappers = file_get_stream_wrappers($case['filter']);
|
52 |
|
|
$this->assertEqual(isset($wrappers['http']), $case['result']);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
$wrappers = file_get_remote_stream_wrappers();
|
56 |
|
|
$this->assertEqual(count($wrappers), 3, 'Correct number of remote stream wrappers returned.');
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Check that basic-level file functions return expected values.
|
61 |
|
|
*/
|
62 |
|
|
function testFileStat() {
|
63 |
|
|
$files = $this->drupalGetTestFiles('image');
|
64 |
|
|
$file = $files[0];
|
65 |
|
|
|
66 |
|
|
$this->assertTrue(is_file($file->uri));
|
67 |
|
|
$this->assertFalse(is_dir($file->uri));
|
68 |
|
|
$this->assertEqual(filesize($file->uri), 125);
|
69 |
|
|
$this->assertEqual(image_get_info($file->uri), array(
|
70 |
|
|
'width' => 40,
|
71 |
|
|
'height' => 20,
|
72 |
|
|
'extension' => 'png',
|
73 |
|
|
'mime_type' => 'image/png',
|
74 |
|
|
'file_size' => 125,
|
75 |
|
|
));
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Test file CRUD functions with remote files.
|
80 |
|
|
*/
|
81 |
|
|
function testFileCrud() {
|
82 |
|
|
$files = $this->drupalGetTestFiles('image');
|
83 |
|
|
|
84 |
|
|
$file = remote_stream_wrapper_file_load_by_uri($files[0]->uri);
|
85 |
|
|
$this->assertFalse($file, 'Remote file not yet saved as a managed file.');
|
86 |
|
|
$file = remote_stream_wrapper_file_create_by_uri($files[0]->uri);
|
87 |
|
|
file_save($file);
|
88 |
|
|
$this->assertTrue(!empty($file->fid), 'Remote file saved successfully.');
|
89 |
|
|
$this->assertEqual($file->filesize, filesize($files[0]->original_uri));
|
90 |
|
|
$this->assertEqual($file->filemime, file_get_mimetype($files[0]->original_uri));
|
91 |
|
|
|
92 |
|
|
$loaded_file = remote_stream_wrapper_file_load_by_uri($files[0]->uri);
|
93 |
|
|
$this->assertEqual($loaded_file->fid, $file->fid, 'Remote file managed record loaded by URI.');
|
94 |
|
|
|
95 |
|
|
// Delete the managed file record.
|
96 |
|
|
$result = file_delete($file);
|
97 |
|
|
$this->assertIdentical($result, TRUE, 'Remote file record deleted successfully.');
|
98 |
|
|
$this->assertFalse(remote_stream_wrapper_file_load_by_uri($files[0]->uri), 'Remote file managed record no longer exists.');
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Test that remote images can be used with image styles.
|
103 |
|
|
*/
|
104 |
|
|
function testRemoteImageStyles() {
|
105 |
|
|
$files = $this->drupalGetTestFiles('image');
|
106 |
|
|
$file = remote_stream_wrapper_file_create_by_uri($files[0]->uri);
|
107 |
|
|
file_save($file);
|
108 |
|
|
$generated_uri = remote_stream_wrapper_image_style_path('thumbnail', $file->uri);
|
109 |
|
|
|
110 |
|
|
$output = theme('image_style', array('style_name' => 'thumbnail', 'path' => $file->uri));
|
111 |
|
|
$this->drupalSetContent($output);
|
112 |
|
|
$elements = $this->xpath('//img');
|
113 |
|
|
$this->drupalGet($elements[0]['src']);
|
114 |
|
|
$this->assertResponse(200);
|
115 |
|
|
|
116 |
|
|
$this->assertTrue(is_file($generated_uri), t('Generated file does exist after we accessed it.'));
|
117 |
|
|
$this->assertRaw(file_get_contents($generated_uri), t('URL returns expected file.'));
|
118 |
|
|
$generated_image_info = image_get_info($generated_uri);
|
119 |
|
|
$this->assertEqual($this->drupalGetHeader('Content-Type'), $generated_image_info['mime_type'], t('Expected Content-Type was reported.'));
|
120 |
|
|
$this->assertEqual($this->drupalGetHeader('Content-Length'), $generated_image_info['file_size'], t('Expected Content-Length was reported.'));
|
121 |
|
|
}
|
122 |
|
|
} |