Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
robinscholz committed Aug 21, 2019
2 parents e0bb3c1 + d7f9c4c commit 976b3f6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 11 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ composer require robinscholz/better-rest
git submodule add https://github.com/robinscholz/better-rest.git site/plugins/better-rest
```

### Credits
## Credits
A big thanks to [@bnomei](https://github.com/bnomei) who refactored the initial source code into something extendable and future proof. If you are using this plugin please consider buying a Kirby license through his [affiliate link](https://a.paddle.com/v2/click/1129/35731?link=1170)!

## License
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 @@ -146,7 +148,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.1",
"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
8 changes: 6 additions & 2 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()
// public function testFindsRouteFromTestConfig()
// {
// $response = kirby()->response('de/path/test');
// $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 976b3f6

Please sign in to comment.