Skip to content

Commit b104f50

Browse files
committed
Merge branch 'release2.20.0'
2 parents de6ac97 + aa2ce5e commit b104f50

16 files changed

+233
-49
lines changed

.github/workflows/tests.yml

+7-22
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Tests
22

33
on:
44
push:
5-
branches: [ dev ]
5+
branches: [ develop ]
66
pull_request:
7-
branches: [ dev ]
7+
branches: [ develop ]
88

99
jobs:
1010
tests:
@@ -14,26 +14,11 @@ jobs:
1414

1515
strategy:
1616
fail-fast: false
17-
matrix:
18-
php-version:
19-
- "8.0"
20-
- "8.1"
21-
- "8.2"
2217

2318
steps:
24-
- uses: actions/checkout@dev
25-
26-
- name: Setup PHP
27-
uses: shivammathur/setup-php@master
19+
- uses: actions/checkout@v3
20+
- uses: php-actions/composer@v6
21+
- uses: php-actions/phpunit@v3
2822
with:
29-
php-version: ${{ matrix.php-version }}
30-
coverage: xdebug
31-
32-
- name: Validate composer.json and composer.lock
33-
run: composer validate
34-
35-
- name: Install dependencies
36-
run: composer install --prefer-dist --no-progress --no-suggest
37-
38-
- name: Run test suite
39-
run: ./vendor/bin/pest --ci
23+
configuration: phpunit.xml.dist
24+
args: --coverage-text

.idea/laravel-storyblok.iml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

-19
This file was deleted.

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Use Storyblok’s amazing headless CMS in way that feels familiar to Laravel developers
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/riclep/laravel-storyblok.svg?style=flat-square)](https://packagist.org/packages/riclep/laravel-storyblok)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/riclep/laravel-storyblok.svg?style=flat-square)](https://packagist.org/packages/riclep/laravel-storyblok)
5+
6+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/riclep/laravel-storyblok/Tests)
7+
![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/riclep/laravel-storyblok/php)
8+
49
[![Build](https://img.shields.io/scrutinizer/build/g/riclep/laravel-storyblok?style=flat-square)](https://scrutinizer-ci.com/g/riclep/laravel-storyblok)
510
[![Quality Score](https://img.shields.io/scrutinizer/g/riclep/laravel-storyblok.svg?style=flat-square)](https://scrutinizer-ci.com/g/riclep/laravel-storyblok)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/riclep/laravel-storyblok.svg?style=flat-square)](https://packagist.org/packages/riclep/laravel-storyblok)
11+
712
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/M4M2C42W6)
813
[![Twitter](https://img.shields.io/twitter/follow/riclep.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=riclep)
914

@@ -44,7 +49,7 @@ Improve your content’s typography. [Package](https://github.com/RicLeP/laravel
4449

4550
Helpers for layout, block positioning and CSS class name generation. [Package](https://github.com/RicLeP/laravel-storyblok-css) [Docs](https://ls.sirric.co.uk/docs/2.19/css-classes)
4651

47-
### Laravel Storyblok Form builder
52+
### Laravel Storyblok Form builder (BETA)
4853

4954
Build forms with Storyblok complete with Laravel’s validation. [Package](https://github.com/RicLeP/laravel-storyblok-forms) [Docs](https://ls.sirric.co.uk/docs/2.19/laravel-storyblok-forms)
5055

@@ -70,9 +75,10 @@ If you discover any security related issues, please email [email protected] inste
7075

7176
## Credits
7277

73-
- Richard Le Poidevin [GitHub](https://github.com/riclep) / [Twitter](https://twitter.com/riclep)
74-
- [Storyblok](https://www.storyblok.com/)
75-
- [Laravel](https://laravel.com/)
78+
- Richard Le Poidevin [GitHub](https://github.com/riclep) / [Twitter](https://twitter.com/riclep) ![img](https://ls.sirric.co.uk/img/storyblok-ambassador-asset-vert-color.svg)
79+
- [The contributors](https://github.com/RicLeP/laravel-storyblok/graphs/contributors) 😍
80+
- [Storyblok](https://www.storyblok.com/) 😻
81+
- [Laravel](https://laravel.com/) 🥰
7682

7783
## License
7884

config/storyblok.php

+10
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,14 @@
218218
|
219219
*/
220220
'settings_field' => 'settings',
221+
222+
/*
223+
|--------------------------------------------------------------------------
224+
| Default date format
225+
|--------------------------------------------------------------------------
226+
|
227+
| Use any valid PHP date format, applied when casting DateTimes to string
228+
|
229+
*/
230+
'date_format' => 'H:i:s j F Y',
221231
];

src/Console/PageMakeCommand.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Riclep\Storyblok\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
use Illuminate\Support\Str;
7+
8+
class PageMakeCommand extends GeneratorCommand
9+
{
10+
protected $name = 'ls:page';
11+
12+
protected $description = 'Create a new page class';
13+
14+
protected $type = 'Page';
15+
16+
protected function getStub(): string
17+
{
18+
return file_exists(resource_path('stubs/storyblok/page.stub')) ? resource_path('stubs/storyblok/page.stub') : __DIR__ . '/stubs/page.stub';
19+
}
20+
21+
protected function getDefaultNamespace($rootNamespace): string
22+
{
23+
return $rootNamespace . '\Storyblok\Page';
24+
}
25+
26+
public function handle(): void
27+
{
28+
parent::handle();
29+
30+
$this->doOtherOperations();
31+
}
32+
33+
protected function doOtherOperations(): void
34+
{
35+
$class = $this->qualifyClass($this->getNameInput());
36+
$path = $this->getPath($class);
37+
$content = file_get_contents($path);
38+
39+
$content = str_replace('DummySlug', Str::kebab($this->getNameInput()), $content);
40+
41+
file_put_contents($path, $content);
42+
}
43+
}

src/Console/stubs/page.stub

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Riclep\Storyblok\Page as BasePage;
6+
7+
/**
8+
*/
9+
class DummyClass extends BasePage
10+
{
11+
//
12+
}

src/Fields/DateTime.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ class DateTime extends Field
1111
{
1212
public function __toString(): string
1313
{
14-
return $this->content->toDatetimeString();
14+
if (!$this->content) {
15+
return '';
16+
}
17+
18+
if (property_exists($this, 'format')) {
19+
return $this->content->format($this->format);
20+
}
21+
22+
return config('storyblok.date_format') ? $this->content->format(config('storyblok.date_format')) : $this->content->toDatetimeString();
1523
}
1624

1725
/**

src/StoryblokServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function boot(): void
3434
BlockMakeCommand::class,
3535
BlockSyncCommand::class,
3636
FolderMakeCommand::class,
37+
PageMakeCommand::class,
3738
StubViewsCommand::class
3839
]);
3940
}

tests/BlockTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,17 @@ public function block_settings_can_process_comma_separated_list()
443443

444444
$this->assertEquals(['quarter', 'half', 'full'], $block->settings('lsf_style')['commas']);
445445
}
446+
447+
/** @test */
448+
public function will_return_mutli_self_fields()
449+
{
450+
$page = $this->makePage('multi-option-self.json');
451+
$block = $page->block();
452+
453+
$this->assertEquals([
454+
0 => '20',
455+
1 => '10',
456+
2 => '30',
457+
], $block->body[0]->test_field);
458+
}
446459
}

tests/FieldTest.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Riclep\Storyblok\Support\ImageTransformers\Storyblok;
1919
use Riclep\Storyblok\Tests\Fixtures\Blocks\NullBlock;
2020
use Riclep\Storyblok\Tests\Fixtures\Fields\AssetWithAccessor;
21+
use Riclep\Storyblok\Tests\Fixtures\Fields\CustomDate;
2122
use Riclep\Storyblok\Tests\Fixtures\Fields\HeroImage;
2223
use Riclep\Storyblok\Tests\Fixtures\Fields\Imgix;
2324
use Riclep\Storyblok\Tests\Fixtures\Fields\WithImage;
@@ -97,10 +98,28 @@ public function can_convert_date_to_carbon()
9798
}
9899

99100
/** @test */
100-
public function can_convert_date_to_string()
101+
public function can_set_default_date_format()
101102
{
102103
$field = new DateTime($this->getFieldContents('datetime'), null);
103-
$this->assertEquals('2020-07-01 20:57:00', (string) $field);
104+
105+
$this->assertEquals('20:57:00 1 July 2020', (string) $field);
106+
}
107+
108+
/** @test */
109+
public function can_set_date_format_with_property()
110+
{
111+
$field = new CustomDate($this->getFieldContents('datetime'), null);
112+
113+
$this->assertEquals('01/07/2020', (string) $field);
114+
}
115+
116+
/** @test */
117+
public function empty_dates_return_null()
118+
{
119+
$field = new DateTime('', null);
120+
121+
$this->assertNull($field->content());
122+
$this->assertEquals('', (string) $field);
104123
}
105124

106125
/** @test */

tests/Fixtures/Fields/CustomDate.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
4+
namespace Riclep\Storyblok\Tests\Fixtures\Fields;
5+
6+
7+
use Riclep\Storyblok\Fields\DateTime;
8+
9+
class CustomDate extends DateTime
10+
{
11+
protected string $format = 'd/m/Y';
12+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
4+
namespace Riclep\Storyblok\Tests\Fixtures\Folders;
5+
6+
7+
use Illuminate\Support\Collection;
8+
9+
class SortedFolder extends \Riclep\Storyblok\Folder
10+
{
11+
public function __construct()
12+
{
13+
// these are lost when $folder->settings() is called
14+
$this->settings([
15+
'sort_by' => 'content.date:desc',
16+
'per_page' => 17
17+
]);
18+
}
19+
}

tests/Fixtures/multi-option-self.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"story": {
3+
"name": "test",
4+
"created_at": "2022-07-15T10:32:54.701Z",
5+
"published_at": "2022-06-16T12:51:40.423Z",
6+
"id": 163795103,
7+
"uuid": "847ef2f7-c110-40bf-b2e2-e6ea8f684ca7",
8+
"content": {
9+
"_uid": "1515771c-3ec4-4922-8921-9607eda522e6",
10+
"body": [
11+
{
12+
"_uid": "29914472-2a98-428d-868c-56c30207d608",
13+
"component": "test-component",
14+
"test_field": [
15+
"20",
16+
"10",
17+
"30"
18+
]
19+
}
20+
],
21+
"component": "relation"
22+
},
23+
"tag_list": [],
24+
"slug": "test",
25+
"full_slug": "test/test",
26+
"first_published_at": "2022-06-16T12:51:40.423Z"
27+
}
28+
}

tests/FolderTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Riclep\Storyblok\Page;
88
use Riclep\Storyblok\Tests\Fixtures\Folders\Folder;
99
use Riclep\Storyblok\Tests\Fixtures\Folders\EmptyFolder;
10+
use Riclep\Storyblok\Tests\Fixtures\Folders\SortedFolder;
1011

1112
class FolderTest extends TestCase
1213
{
@@ -102,5 +103,37 @@ public function can_set_settings() {
102103
'per_page' => 7,
103104
], $settings);
104105
}
106+
107+
/** @test */
108+
public function can_add_settings_in_folder_constructor() {
109+
$folder = new SortedFolder();
110+
$settings = $this::callMethod($folder, 'getSettings');
111+
112+
$this->assertEquals([
113+
'is_startpage' => false,
114+
'sort_by' => 'content.date:desc',
115+
'starts_with' => '',
116+
'page' => 0,
117+
'per_page' => 17,
118+
], $settings);
119+
120+
121+
$folder2 = new SortedFolder();
122+
123+
// calling settings overrides the settings in the constructor if the constructor uses
124+
// a settings array
125+
$folder2->settings([
126+
'per_page' => 8,
127+
]);
128+
$settings2 = $this::callMethod($folder2, 'getSettings');
129+
130+
$this->assertEquals([
131+
'is_startpage' => false,
132+
'sort_by' => 'published_at:desc',
133+
'starts_with' => '',
134+
'page' => 0,
135+
'per_page' => 8,
136+
], $settings2);
137+
}
105138
}
106139

0 commit comments

Comments
 (0)