Merge "Add CollationFa"
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / SwiftFileBackendTest.php
1 <?php
2
3 /**
4 * @group FileRepo
5 * @group FileBackend
6 * @group medium
7 */
8 class SwiftFileBackendTest extends MediaWikiTestCase {
9 /** @var TestingAccessWrapper Proxy to SwiftFileBackend */
10 private $backend;
11
12 protected function setUp() {
13 parent::setUp();
14
15 $this->backend = TestingAccessWrapper::newFromObject(
16 new SwiftFileBackend( [
17 'name' => 'local-swift-testing',
18 'class' => 'SwiftFileBackend',
19 'wikiId' => 'unit-testing',
20 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ),
21 'swiftAuthUrl' => 'http://127.0.0.1:8080/auth', // unused
22 'swiftUser' => 'test:tester',
23 'swiftKey' => 'testing',
24 'swiftTempUrlKey' => 'b3968d0207b54ece87cccc06515a89d4' // unused
25 ] )
26 );
27 }
28
29 /**
30 * @dataProvider provider_testSanitizeHdrs
31 * @covers SwiftFileBackend::sanitizeHdrs
32 * @covers SwiftFileBackend::getCustomHeaders
33 */
34 public function testSanitizeHdrs( $raw, $sanitized ) {
35 $hdrs = $this->backend->sanitizeHdrs( [ 'headers' => $raw ] );
36
37 $this->assertEquals( $hdrs, $sanitized, 'sanitizeHdrs() has expected result' );
38 }
39
40 public static function provider_testSanitizeHdrs() {
41 return [
42 [
43 [
44 'content-length' => 345,
45 'content-type' => 'image+bitmap/jpeg',
46 'content-disposition' => 'inline',
47 'content-duration' => 35.6363,
48 'content-Custom' => 'hello',
49 'x-content-custom' => 'hello'
50 ],
51 [
52 'content-disposition' => 'inline',
53 'content-duration' => 35.6363,
54 'content-custom' => 'hello',
55 'x-content-custom' => 'hello'
56 ]
57 ],
58 [
59 [
60 'content-length' => 345,
61 'content-type' => 'image+bitmap/jpeg',
62 'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
63 'content-duration' => 35.6363,
64 'content-custom' => 'hello',
65 'x-content-custom' => 'hello'
66 ],
67 [
68 'content-disposition' => 'inline;filename=xxx',
69 'content-duration' => 35.6363,
70 'content-custom' => 'hello',
71 'x-content-custom' => 'hello'
72 ]
73 ],
74 [
75 [
76 'content-length' => 345,
77 'content-type' => 'image+bitmap/jpeg',
78 'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
79 'content-duration' => 35.6363,
80 'content-custom' => 'hello',
81 'x-content-custom' => 'hello'
82 ],
83 [
84 'content-disposition' => '',
85 'content-duration' => 35.6363,
86 'content-custom' => 'hello',
87 'x-content-custom' => 'hello'
88 ]
89 ]
90 ];
91 }
92
93 /**
94 * @dataProvider provider_testGetMetadataHeaders
95 * @covers SwiftFileBackend::getMetadataHeaders
96 */
97 public function testGetMetadataHeaders( $raw, $sanitized ) {
98 $hdrs = $this->backend->getMetadataHeaders( $raw );
99
100 $this->assertEquals( $hdrs, $sanitized, 'getMetadataHeaders() has expected result' );
101 }
102
103 public static function provider_testGetMetadataHeaders() {
104 return [
105 [
106 [
107 'content-length' => 345,
108 'content-custom' => 'hello',
109 'x-content-custom' => 'hello',
110 'x-object-meta-custom' => 5,
111 'x-object-meta-sha1Base36' => 'a3deadfg...',
112 ],
113 [
114 'x-object-meta-custom' => 5,
115 'x-object-meta-sha1base36' => 'a3deadfg...',
116 ]
117 ]
118 ];
119 }
120
121 /**
122 * @dataProvider provider_testGetMetadata
123 * @covers SwiftFileBackend::getMetadata
124 */
125 public function testGetMetadata( $raw, $sanitized ) {
126 $hdrs = $this->backend->getMetadata( $raw );
127
128 $this->assertEquals( $hdrs, $sanitized, 'getMetadata() has expected result' );
129 }
130
131 public static function provider_testGetMetadata() {
132 return [
133 [
134 [
135 'content-length' => 345,
136 'content-custom' => 'hello',
137 'x-content-custom' => 'hello',
138 'x-object-meta-custom' => 5,
139 'x-object-meta-sha1Base36' => 'a3deadfg...',
140 ],
141 [
142 'custom' => 5,
143 'sha1base36' => 'a3deadfg...',
144 ]
145 ]
146 ];
147 }
148 }