Skip to content

Commit

Permalink
- fixed srcset in blueprint: image => files field
Browse files Browse the repository at this point in the history
- test srcsets
- test multilang route
- ignored coverage: x-language detect since header is too hard to fake

Signed-off-by: Bruno Meilick <[email protected]>
  • Loading branch information
bnomei committed Aug 21, 2019
1 parent 026904d commit 6fcf4be
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/tests/logs
/tests/media
/tests/site/accounts
/tests/site/session
/tests/site/sessions
/tests/site/cache

# files of Composer dependencies that are not needed for the plugin
Expand Down
4 changes: 3 additions & 1 deletion classes/Betterrest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public function contentFromRequest(?\Kirby\Http\Request $request = null): ?array
$request = $request ?? $this->kirby->request();
$path = preg_replace('/rest/', '', (string)$request->path(), 1);

// @codeCoverageIgnoreStart
// auto detect language
if (! \Kirby\Toolkit\A::get($this->options, 'language')) {
$language = $request->header('x-language');
if ($language) {
$this->options['language'] = $language;
}
}
// @codeCoverageIgnoreEnd

// if has language and is multilang setup...
$language = \Kirby\Toolkit\A::get($this->options, 'language');
Expand Down Expand Up @@ -147,7 +149,7 @@ public function applyKirbytags(?string $value): string

/**
* @param $value
* @return string
* @return array
*/
public function applySrcSet($value): array
{
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "robinscholz/better-rest",
"description": "Kirby Plugin for better REST requests",
"type": "kirby-plugin",
"version": "1.0.1",
"version": "1.1.0",
"license": "MIT",
"authors": [
{
Expand Down
10 changes: 8 additions & 2 deletions tests/BetterrestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ public function testContentModification()
$this->assertNull($rest->modifyContent([]));

$data = $rest->modifyContent($rest->content);

$this->assertIsArray($rest->getOptions()['srcset']);
$this->assertRegExp(
'/^\/media\/pages\/test\/.*(375w,).*(667w,).*(1024w,).*(1680w)$/',
$data['data']['content']['testimage'][0]['srcset']
);

$this->assertIsArray($data);
$rest->setData($data);
$this->assertTrue($rest->getData() === $data);

$this->assertIsArray($rest->data);
}

public function testNoDataResponse()
Expand Down
16 changes: 10 additions & 6 deletions tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ public function testFindsTestPage()
$this->assertRegExp('/media\/pages\/test\/.*-.*\/test.jpeg/', $response->body());
}

// public function testFindsRoute()
// {
// $response = kirby()->response('de/path/test');
// $this->assertTrue($response->code() === 200);
// $this->assertTrue('application/json' === $response->type());
// }
public function testFindsRouteFromTestConfig()
{
$response = kirby()->render('en/path/pages/test');
$this->assertTrue($response->code() === 200);
$this->assertTrue('application/json' === $response->type());
$this->assertStringContainsString(
'pages/test',
json_decode($response->body())->path
);
}
}
2 changes: 1 addition & 1 deletion tests/site/blueprints/pages/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sections:
type: fields
fields:
testimage:
type: image
type: files
4 changes: 2 additions & 2 deletions tests/site/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
[
'pattern' => 'path/(:all)',
'method' => 'GET',
'language' => '*',
'action' => function (string $path = null) {
'language' => 'en',
'action' => function ($language, string $path = null) {
return ['path' => $path];
},
],
Expand Down

0 comments on commit 6fcf4be

Please sign in to comment.