Skip to content

Commit

Permalink
Merge pull request #20 from pdsinterop/add-solid-crud-tests
Browse files Browse the repository at this point in the history
Add solid-crud tests
  • Loading branch information
michielbdejong authored Nov 13, 2020
2 parents 273e209 + ed9d972 commit ee9d5fa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ ADD . /app
WORKDIR /app
RUN php /install/composer.phar install --no-dev --prefer-dist
COPY site.conf /etc/apache2/sites-enabled/site.conf
RUN chown www-data /app/config
RUN chown -R www-data:www-data /app
EXPOSE 443
2 changes: 1 addition & 1 deletion run-solid-test-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export COOKIE="`docker run --rm --cap-add=SYS_ADMIN --network=testnet -e SERVER_

echo "Running webid-provider tests with cookie $COOKIE"
docker run --rm --network=testnet --env COOKIE="$COOKIE" --env-file /tmp/env-vars-for-test-image.list webid-provider
# docker run --rm --network=testnet --env-file /tmp/env-vars-for-test-image.list solid-crud
docker run --rm --network=testnet --env-file /tmp/env-vars-for-test-image.list solid-crud
rm /tmp/env-vars-for-test-image.list
docker stop server
docker rm server
Expand Down
32 changes: 32 additions & 0 deletions src/Controller/StorageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Pdsinterop\Solid\Controller;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class StorageController extends ServerController
{
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
{
$body = <<< EOF
@prefix : <#>.
@prefix inbox: <>.
@prefix ldp: <http://www.w3.org/ns/ldp#>.
@prefix terms: <http://purl.org/dc/terms/>.
@prefix XML: <http://www.w3.org/2001/XMLSchema#>.
@prefix st: <http://www.w3.org/ns/posix/stat#>.
inbox:
a ldp:BasicContainer, ldp:Container, ldp:Resource;
terms:modified "2019-12-20T14:52:54Z"^^XML:dateTime;
st:mtime 1576853574.389;
st:size 4096.
EOF;
$response = $this->getResponse();

$response->getBody()->write($body);
return $response
->withHeader("Content-type", "text/turtle");
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/foaf.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
>
<foaf:Person rdf:ID="me">
<ldp:inbox rdf:resource="/inbox/"/>
<solid:account rdf:resource="/"/>
<space:storage rdf:resource="/"/>
<solid:account rdf:resource="/account/"/>
<space:storage rdf:resource="/storage/"/>
<solid:privateTypeIndex rdf:resource="/settings/privateTypeIndex.ttl"/>
<solid:publicTypeIndex rdf:resource="/settings/publicTypeIndex.ttl"/>
<space:preferencesFile rdf:resource="/settings/preferencesFile.ttl"/>
Expand Down
38 changes: 28 additions & 10 deletions web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use League\Route\Http\Exception\NotFoundException;
use League\Route\Router;
use League\Route\Strategy\ApplicationStrategy;

use Pdsinterop\Solid\Controller\AddSlashToPathController;
use Pdsinterop\Solid\Controller\ApprovalController;
use Pdsinterop\Solid\Controller\AuthorizeController;
Expand All @@ -32,6 +31,7 @@
use Pdsinterop\Solid\Controller\Profile\ProfileController;
use Pdsinterop\Solid\Controller\RegisterController;
use Pdsinterop\Solid\Controller\ResourceController;
use Pdsinterop\Solid\Controller\StorageController;
use Pdsinterop\Solid\Controller\TokenController;
use Pdsinterop\Solid\Resources\Server as ResourceServer;

Expand All @@ -55,21 +55,40 @@
$container->add(ServerRequestInterface::class, Request::class);
$container->add(ResponseInterface::class, Response::class);

/*
$adapter = new \League\Flysystem\Adapter\Local(__DIR__ . '/../tests/fixtures');
$filesystem = new \League\Flysystem\Filesystem($adapter);
$graph = new \EasyRdf_Graph();
$plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph);
$filesystem->addPlugin($plugin);
*/

$container->share(FilesystemInterface::class, function () {
$container->share(FilesystemInterface::class, function () use ($request) {
// @FIXME: Filesystem root and the $adapter should be configurable.
// Implement this with `$filesystem = \MJRider\FlysystemFactory\create(getenv('STORAGE_ENDPOINT'));`
$filesystemRoot = __DIR__ . '/../tests/fixtures';

$adapter = new \League\Flysystem\Adapter\Local($filesystemRoot);

$filesystem = new \League\Flysystem\Filesystem($adapter);
$graph = new \EasyRdf_Graph();

// Create Formats objects
$formats = new \Pdsinterop\Rdf\Formats();

$serverUri = "https://" . $request->getServerParams()["SERVER_NAME"] . $request->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url;

// Create the RDF Adapter
$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
$adapter,
$graph,
$formats,
$serverUri
);

$filesystem = new \League\Flysystem\Filesystem($rdfAdapter);

$filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats));

$plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph);
$filesystem->addPlugin($plugin);

Expand All @@ -85,20 +104,18 @@
$container->add(ResourceController::class, function () use ($container) {
$filesystem = $container-> get(FilesystemInterface::class);

require_once __DIR__ . '/../lib/solid-crud/src/Server.php';

$server = new ResourceServer($filesystem, new Response());

return new ResourceController($server);
});

$controllers = [
AddSlashToPathController::class,
ApprovalController::class,
ApprovalController::class,
AuthorizeController::class,
CardController::class,
CorsController::class,
HandleApprovalController::class,
HandleApprovalController::class,
HelloWorldController::class,
HttpToHttpsController::class,
JwksController::class,
Expand All @@ -107,7 +124,8 @@
OpenidController::class,
ProfileController::class,
RegisterController::class,
TokenController::class,
StorageController::class,
TokenController::class,
];

$traits = [
Expand Down Expand Up @@ -160,8 +178,7 @@
$router->map('POST', '/sharing/{clientId}/', HandleApprovalController::class)->setScheme($scheme);
$router->map('POST', '/token', TokenController::class)->setScheme($scheme);
$router->map('POST', '/token/', TokenController::class)->setScheme($scheme);

$router->group('/data', static function (\League\Route\RouteGroup $group) {
$router->group('/storage', static function (\League\Route\RouteGroup $group) {
$methods = [
'DELETE',
'GET',
Expand All @@ -174,6 +191,7 @@

array_walk($methods, static function ($method) use (&$group) {
$group->map($method, '/', AddSlashToPathController::class);
// $group->map($method, '//', StorageController::class);
$group->map($method, '{path:.*}', ResourceController::class);
});
})->setScheme($scheme);
Expand Down

0 comments on commit ee9d5fa

Please sign in to comment.