1818 * @covers \Pdsinterop\Solid\Resources\Server
1919 * @coversDefaultClass \Pdsinterop\Solid\Resources\Server
2020 *
21- * @uses \Laminas\Diactoros\Response
22- * @uses \Laminas\Diactoros\ServerRequest
23- * @uses \Pdsinterop\Solid\Resources\Exception
24- * @uses \Pdsinterop\Solid\Resources\Server
21+ * @uses \Laminas\Diactoros\Response
22+ * @uses \Laminas\Diactoros\ServerRequest
23+ * @uses \Pdsinterop\Solid\Resources\Exception
24+ * @uses \Pdsinterop\Solid\Resources\Server
2525 */
2626class ServerTest extends TestCase
2727{
2828 ////////////////////////////////// FIXTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2929
30- const MOCK_SLUG = 'Mock Slug ' ;
31-
32- /////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
3330 const MOCK_BODY = 'php://temp ' ;
34- const MOCK_URL = '' ;
31+ const MOCK_PATH = '/path/to/resource/ ' ;
3532 const MOCK_SERVER_PARAMS = [];
3633 const MOCK_UPLOADED_FILES = [];
34+ const MOCK_URL = 'https://example.com ' . self ::MOCK_PATH ;
35+
36+ /////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
3737
3838 /** @testdox Server should complain when instantiated without File System */
3939 public function testInstatiationWithoutFileSystem ()
@@ -133,60 +133,34 @@ public function testRespondToRequestWithUnsupportedHttpMethod($httpMethod)
133133 *
134134 * @covers ::respondToRequest
135135 *
136- * @dataProvider provideMimeTypes
136+ * @dataProvider provideSlugs
137137 */
138- public function testRespondToPOSTCreateRequest ($ mimetype )
138+ public function testRespondToPOSTCreateRequest ($ slug , $ mimetype, $ expected )
139139 {
140- $ expected = self ::MOCK_SLUG . self ::MOCK_SLUG ;
141- $ extensions = [
142- 'application/json ' => '.json ' ,
143- 'application/ld+json ' => '.json ' ,
144- 'text/html ' => '.html ' ,
145- 'text/plain ' => '.txt ' ,
146- 'text/turtle ' => '.ttl ' ,
147- ];
148-
149- if (
150- $ mimetype === 'application/ld+json '
151- || $ mimetype === 'text/turtle '
152- || $ mimetype === 'text/html '
153- || $ mimetype === 'text/plain '
154- || $ mimetype === 'application/json '
155- ) {
156- /*/ If the filename suggestion in the Slug contains a file extension, another file extension is appended for known/supported MIME types. This leads to a filename with two file extensions, like 'example.ttl.ttl'.
157-
158- If the MIME type is not known or does not match the provided file extension, there are still two file extensions. They are merely not the same.
159-
160- For instance 'example.json.ttl' or 'example.ttl.json'.
161- /*/
162- $ expected .= $ extensions [$ mimetype ];
163- }
164-
165140 // Arrange
166141 $ mockFileSystem = $ this ->getMockBuilder (FilesystemInterface::class)->getMock ();
167142 $ mockGraph = $ this ->getMockBuilder (Graph::class)->getMock ();
168143 $ request = $ this ->createRequest ('POST ' , [
169144 'Content-Type ' => $ mimetype ,
170145 'Link ' => '' ,
171- 'Slug ' => self :: MOCK_SLUG ,
146+ 'Slug ' => $ slug ,
172147 ]);
173148
174149 $ mockFileSystem
175150 ->method ('has ' )
176151 ->withAnyParameters ()
177152 ->willReturnMap ([
178- [self ::MOCK_SLUG , true ],
179- [$ expected , false ],
153+ [self ::MOCK_PATH , true ],
180154 ]);
181155
182156 $ mockFileSystem
183157 ->method ('getMimetype ' )
184- ->with (self ::MOCK_SLUG )
158+ ->with (self ::MOCK_PATH )
185159 ->willReturn (Server::MIME_TYPE_DIRECTORY );
186160
187161 $ mockFileSystem
188162 ->method ('write ' )
189- ->with ( $ expected , '' , [] )
163+ ->withAnyParameters ( )
190164 ->willReturn (true );
191165
192166 // Act
@@ -196,21 +170,23 @@ public function testRespondToPOSTCreateRequest($mimetype)
196170 // Assert
197171 $ actual = $ response ->getHeaderLine ('Location ' );
198172
199- $ this ->assertEquals ($ expected , $ actual );
173+ $ this ->assertEquals (self :: MOCK_PATH . $ expected , $ actual );
200174 }
201175
202176 /////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
203177
204- public static function provideMimeTypes ()
178+ public static function provideSlugs ()
205179 {
206180 return [
207- 'mime: (empty) ' => ['' ],
208- 'mime: application/json ' => ['application/json ' ],
209- 'mime: application/ld+json ' => ['application/ld+json ' ],
210- 'mime: some/other ' => ['some/other ' ],
211- 'mime: text/html ' => ['text/html ' ],
212- 'mime: text/plain ' => ['text/plain ' ],
213- 'mime: text/turtle ' => ['text/turtle ' ],
181+ // '' => [$slug, $mimetype, $expectedFilename],
182+ 'Slug with json extension, with ld+json MIME ' => ['Mock Slug.json ' , 'application/ld+json ' , 'Mock Slug.json.json ' ],
183+ 'Slug with jsonld extension, with ld+json MIME) ' => ['Mock Slug.jsonld ' , 'application/ld+json ' , 'Mock Slug.jsonld.json ' ],
184+ 'Slug with PNG extension, with PNG MIME ' => ['Mock Slug.png ' , 'image/png ' , 'Mock Slug.png.png ' ],
185+ 'Slug with some other, extension) with Turtle MIME ' => ['Mock Slug.other ' , 'text/turtle ' , 'Mock Slug.other.ttl ' ],
186+ 'Slug with Turtle extension, with other MIME ' => ['Mock Slug.ttl ' , 'some/other ' , 'Mock Slug.ttl ' ],
187+ 'Slug with Turtle extension, with Turtle MIME ' => ['Mock Slug.ttl ' , 'text/turtle ' , 'Mock Slug.ttl.ttl ' ],
188+ 'Slug without extension), with some other MIME ' => ['Mock Slug ' , 'some/other ' , 'Mock Slug ' ],
189+ 'Slug without extension), with turtle MIME ' => ['Mock Slug ' , 'text/turtle ' , 'Mock Slug.ttl ' ],
214190 ];
215191 }
216192
0 commit comments