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,35 @@ 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 {
180+ /*/ 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'.
181+
182+ 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.
183+
184+ For instance 'example.json.ttl' or 'example.ttl.json'.
185+
186+ Known/Supported MIME types and file extensions:
187+ 'application/json' => '.json',
188+ 'application/ld+json' => '.json',
189+ 'text/html' => '.html',
190+ 'text/plain' => '.txt',
191+ 'text/turtle' => '.ttl',
192+ /*/
193+
206194 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 ' ],
195+ // '' => [$slug, $mimetype, $expectedFilename ],
196+ 'Slug (with extension) matching supported MIME extension ' => ['Mock Slug.ttl ' , ' text/turtle ' , ' Mock Slug.ttl.ttl ' ],
197+ 'Slug (with extension) matching unsupported MIME extension ' => ['Mock Slug.png ' , ' image/png ' , ' Mock Slug.png ' ],
198+ 'Slug (with extension) not matching supported MIME extension ' => ['Mock Slug.foo ' , ' text/turtle ' , ' Mock Slug.foo.ttl ' ],
199+ 'Slug (with extension) not matching unsupported MIME extension ' => ['Mock Slug.ttl ' , ' some/other ' , ' Mock Slug.ttl ' ],
200+ 'Slug (without extension) supported MIME ' => ['Mock Slug ' , ' text/turtle ' , ' Mock Slug ' . ' .ttl ' ],
201+ 'Slug (without extension) unsupported MIME ' => ['Mock Slug ' , ' some/other ' , ' Mock Slug ' ],
214202 ];
215203 }
216204
0 commit comments