@@ -136,4 +136,73 @@ public function testEnsureContainerExistsCreates(): void
136136 $ methods = array_column ($ requests , 0 );
137137 $ this ->assertContains ('PUT ' , $ methods );
138138 }
139+
140+ public function testWalkContainer (): void
141+ {
142+ $ rootJson = json_encode ([
143+ '@id ' => 'http://pod.example/root/ ' ,
144+ '@type ' => ['http://www.w3.org/ns/ldp#BasicContainer ' ],
145+ 'http://www.w3.org/ns/ldp#contains ' => [
146+ ['@id ' => 'http://pod.example/root/file.txt ' ],
147+ ['@id ' => 'http://pod.example/root/sub/ ' , '@type ' => ['http://www.w3.org/ns/ldp#BasicContainer ' ]],
148+ ],
149+ ]);
150+
151+ $ subJson = json_encode ([
152+ '@id ' => 'http://pod.example/root/sub/ ' ,
153+ '@type ' => ['http://www.w3.org/ns/ldp#BasicContainer ' ],
154+ 'http://www.w3.org/ns/ldp#contains ' => [
155+ ['@id ' => 'http://pod.example/root/sub/nested.ttl ' ],
156+ ],
157+ ]);
158+
159+ $ httpClient = new MockHttpClient (static function (string $ method , string $ url ) use ($ rootJson , $ subJson ): MockResponse {
160+ if ('http://pod.example/root/ ' === $ url ) {
161+ return new MockResponse ($ rootJson , [
162+ 'http_code ' => 200 ,
163+ 'response_headers ' => ['Content-Type ' => 'application/ld+json ' ],
164+ ]);
165+ }
166+ if ('http://pod.example/root/sub/ ' === $ url ) {
167+ return new MockResponse ($ subJson , [
168+ 'http_code ' => 200 ,
169+ 'response_headers ' => ['Content-Type ' => 'application/ld+json ' ],
170+ ]);
171+ }
172+
173+ return new MockResponse ('' , ['http_code ' => 404 ]);
174+ });
175+ $ client = new SolidClient ($ httpClient );
176+
177+ $ entries = iterator_to_array ($ client ->walkContainer ('http://pod.example/root/ ' ), false );
178+
179+ $ this ->assertCount (3 , $ entries );
180+ $ this ->assertSame ('http://pod.example/root/file.txt ' , $ entries [0 ]->url );
181+ $ this ->assertSame ('http://pod.example/root/sub/ ' , $ entries [1 ]->url );
182+ $ this ->assertSame ('http://pod.example/root/sub/nested.ttl ' , $ entries [2 ]->url );
183+ }
184+
185+ public function testWalkContainerWithMaxDepth (): void
186+ {
187+ $ rootJson = json_encode ([
188+ '@id ' => 'http://pod.example/root/ ' ,
189+ '@type ' => ['http://www.w3.org/ns/ldp#BasicContainer ' ],
190+ 'http://www.w3.org/ns/ldp#contains ' => [
191+ ['@id ' => 'http://pod.example/root/sub/ ' , '@type ' => ['http://www.w3.org/ns/ldp#BasicContainer ' ]],
192+ ],
193+ ]);
194+
195+ $ httpClient = new MockHttpClient (static function (string $ method , string $ url ) use ($ rootJson ): MockResponse {
196+ return new MockResponse ($ rootJson , [
197+ 'http_code ' => 200 ,
198+ 'response_headers ' => ['Content-Type ' => 'application/ld+json ' ],
199+ ]);
200+ });
201+ $ client = new SolidClient ($ httpClient );
202+
203+ $ entries = iterator_to_array ($ client ->walkContainer ('http://pod.example/root/ ' , 0 ), false );
204+
205+ $ this ->assertCount (1 , $ entries );
206+ $ this ->assertSame ('http://pod.example/root/sub/ ' , $ entries [0 ]->url );
207+ }
139208}
0 commit comments