diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 87795cc3ee7..a05861473c9 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -49,11 +49,11 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - [$sortField, $sortAscending, $prevNextLinks, $pageSize] = ($this->getPaginationSettings()); + [$sortField, $sortAscending, $pageSize] = ($this->getPaginationSettings()); $canonicalField = $this->getCanonicalField(); - $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $prevNextLinks, $pageSize); + $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); $this->output->writeln("Saving publication data to [{$creator->getOutputPath()}]"); $creator->create(); @@ -188,16 +188,18 @@ protected function addCreatedAtMetaField(): void protected function getPaginationSettings(): array { - if ($this->option('use-defaults') || ! $this->confirm('Do you want to configure pagination settings?')) { - return [null, null, null, null]; + if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { + return [null, null, null]; } - return [$this->getSortField(), $this->getSortDirection(), $this->getPrevNextLinks(), $this->getPageSize()]; + $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); + + return [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; } protected function getSortField(): string { - return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), '__dateCreated'); + return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool @@ -207,11 +209,6 @@ protected function getSortDirection(): bool return $options[$this->choice('Choose the default sort direction', array_keys($options), 'Ascending')]; } - protected function getPrevNextLinks(): bool - { - return $this->confirm('Generate previous/next links in detail view?', true); - } - protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', diff --git a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php index 87c5f7dcfa3..3e1cb0cad4b 100644 --- a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php +++ b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php @@ -67,10 +67,10 @@ public function safeHandle(): int $this->output->write("\n Validating publication [$publication->title]"); $publication->matter->forget('__createdAt'); - foreach ($publication->type->getFieldData() as $field) { + foreach ($publication->type->getFields() as $field) { $countFields++; - $fieldName = $field['name']; - $pubTypeField = new PublicationFieldDefinition($field['type'], $fieldName); + $fieldName = $field->name; + $pubTypeField = new PublicationFieldDefinition($field->type, $fieldName); try { if ($verbose) { diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index b53e36a2d81..5ffcd78fb12 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -26,7 +26,6 @@ public function __construct( protected ?string $canonicalField = null, protected ?string $sortField = null, protected ?bool $sortAscending = null, - protected ?bool $prevNextLinks = null, protected ?int $pageSize = null, ) { $this->directoryName = $this->formatStringForStorage($this->name); @@ -43,7 +42,6 @@ protected function handleCreate(): void [ $this->sortField ?? '__createdAt', $this->sortAscending ?? true, - $this->prevNextLinks ?? true, $this->pageSize ?? 25, ], $this->fields->toArray() diff --git a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php index 81a2f5cee4f..7b73cc8e883 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php @@ -13,8 +13,6 @@ class PaginationSettings implements SerializableContract public string $sortField = '__createdAt'; public bool $sortAscending = true; - /** @deprecated This setting might be deprecated as its unlikely one would enable page size limits without a way to traverse them */ - public bool $prevNextLinks = true; public int $pageSize = 25; public static function fromArray(array $data): static @@ -22,11 +20,10 @@ public static function fromArray(array $data): static return new static(...$data); } - public function __construct(string $sortField = '__createdAt', bool $sortAscending = true, bool $prevNextLinks = true, int $pageSize = 25) + public function __construct(string $sortField = '__createdAt', bool $sortAscending = true, int $pageSize = 25) { $this->sortField = $sortField; $this->sortAscending = $sortAscending; - $this->prevNextLinks = $prevNextLinks; $this->pageSize = $pageSize; } @@ -35,7 +32,6 @@ public function toArray(): array return [ 'sortField' => $this->sortField, 'sortAscending' => $this->sortAscending, - 'prevNextLinks' => $this->prevNextLinks, 'pageSize' => $this->pageSize, ]; } diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index f58c86ae4a4..df05dc5331c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use function array_filter; use function array_merge; use function dirname; use Exception; @@ -31,11 +32,34 @@ class PublicationType implements SerializableContract use Serializable; use InteractsWithDirectories; - public PaginationSettings $pagination; - protected string $directory; + /** The "pretty" name of the publication type */ + public string $name; + + /** + * The field name that is used as the canonical (or identifying) field of publications. + * + * It's used primarily for generating filenames, and the publications must thus be unique by this field. + */ + public string $canonicalField = '__createdAt'; + + /** The Blade filename or view identifier used for rendering a single publication */ + public string $detailTemplate = 'detail.blade.php'; + + /** The Blade filename or view identifier used for rendering the index page (or index pages, when using pagination) */ + public string $listTemplate = 'list.blade.php'; + + /** The pagination settings. Set to null to disable pagination. Make sure your list view supports it when enabled. */ + public null|PaginationSettings $pagination; + + /** + * The front matter fields used for the publications. + * + * @var \Illuminate\Support\Collection + */ + public Collection $fields; - /** @var array> */ - public array $fields = []; + /** The directory of the publication files */ + protected string $directory; public static function get(string $name): static { @@ -55,31 +79,33 @@ public static function fromFile(string $schemaFile): static } public function __construct( - public string $name, - public string $canonicalField = 'identifier', - public string $detailTemplate = 'detail.blade.php', - public string $listTemplate = 'list.blade.php', - array|PaginationSettings $pagination = [], + string $name, + string $canonicalField = '__createdAt', + string $detailTemplate = 'detail.blade.php', + string $listTemplate = 'list.blade.php', + ?array $pagination = [], array $fields = [], ?string $directory = null ) { - $this->fields = $fields; + $this->name = $name; + $this->canonicalField = $canonicalField; + $this->detailTemplate = $detailTemplate; + $this->listTemplate = $listTemplate; + $this->fields = $this->parseFieldData($fields); $this->directory = $directory ?? Str::slug($name); - $this->pagination = $pagination instanceof PaginationSettings - ? $pagination - : PaginationSettings::fromArray($pagination); + $this->pagination = $this->evaluatePaginationSettings($pagination); } public function toArray(): array { - return [ + return $this->withoutNullValues([ 'name' => $this->name, 'canonicalField' => $this->canonicalField, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, - 'pagination' => $this->pagination->toArray(), - 'fields' => $this->fields, - ]; + 'pagination' => $this->pagination?->toArray(), + 'fields' => $this->fields->toArray(), + ]); } public function toJson($options = JSON_PRETTY_PRINT): string @@ -87,6 +113,7 @@ public function toJson($options = JSON_PRETTY_PRINT): string return json_encode($this->toArray(), $options); } + /** Get the publication type's identifier */ public function getIdentifier(): string { return $this->directory ?? Str::slug($this->name); @@ -102,28 +129,14 @@ public function getDirectory(): string return $this->directory; } - /** - * Get the raw field definitions for this publication type. - * - * @see self::getFields() to get the deserialized field definitions. - */ - public function getFieldData(): array - { - return $this->fields; - } - /** * Get the publication fields, deserialized to PublicationFieldDefinition objects. * - * @see self::getFieldData() to get the raw field definitions. - * * @return \Illuminate\Support\Collection */ public function getFields(): Collection { - return Collection::make($this->fields)->mapWithKeys(function (array $data): array { - return [$data['name'] => new PublicationFieldDefinition(...$data)]; - }); + return $this->fields; } public function getFieldDefinition(string $fieldName): PublicationFieldDefinition @@ -188,4 +201,25 @@ protected function getPublicationsSortedByPaginationField(): Collection return $page->matter($this->pagination->sortField); }, descending: ! $this->pagination->sortAscending)->values(); } + + protected function parseFieldData(array $fields): Collection + { + return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { + return new PublicationFieldDefinition(...$data); + }); + } + + protected function evaluatePaginationSettings(array $pagination): ?PaginationSettings + { + if (empty($pagination)) { + return null; + } + + return PaginationSettings::fromArray($pagination); + } + + protected function withoutNullValues(array $array): array + { + return array_filter($array, fn (mixed $value): bool => ! is_null($value)); + } } diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 9e1c191dab2..6e8b8d33403 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -33,7 +33,6 @@ public function test_it_creates_a_new_publication_type() 'canonical', 'sort', false, - false, 10 ); $creator->create(); @@ -48,7 +47,6 @@ public function test_it_creates_a_new_publication_type() "pagination": { "sortField": "sort", "sortAscending": false, - "prevNextLinks": false, "pageSize": 10 }, "fields": [] @@ -75,7 +73,6 @@ public function test_create_with_default_parameters() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [] diff --git a/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php b/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php index b2517f09219..d5e91b8028c 100644 --- a/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php +++ b/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php @@ -133,9 +133,9 @@ public function testWithTagType() { $tags = ['test-publication' => ['foo', 'bar', 'baz']]; $this->file('tags.json', json_encode($tags)); - $this->pubType->fields = [ - (new PublicationFieldDefinition('tag', 'tag', tagGroup: 'test-publication'))->toArray(), - ]; + $this->pubType->fields = collect([ + (new PublicationFieldDefinition('tag', 'tag', tagGroup: 'test-publication')), + ]); $this->pubType->save(); (new SeedsPublicationFiles($this->pubType))->create(); @@ -187,9 +187,9 @@ protected function firstPublication(): MarkdownDocument protected function updateSchema(string $type, string $name): void { - $this->pubType->fields = [ - (new PublicationFieldDefinition($type, $name))->toArray(), - ]; + $this->pubType->fields = collect([ + (new PublicationFieldDefinition($type, $name)), + ]); $this->pubType->save(); } diff --git a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php index 4343de383c9..63c1ee2c185 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php @@ -77,7 +77,6 @@ public function test_command_selects_the_right_publication_using_the_names() 'listTemplate' => 'list', 'pagination' => [ 'pageSize' => 10, - 'prevNextLinks' => true, 'sortField' => '__createdAt', 'sortAscending' => true, ], @@ -584,7 +583,6 @@ protected function makeSchemaFile(array $merge = []): void 'listTemplate' => 'list', 'pagination' => [ 'pageSize' => 10, - 'prevNextLinks' => true, 'sortField' => '__createdAt', 'sortAscending' => true, ], diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 1cffb0585f7..780b3f2cc1c 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -50,7 +50,7 @@ public function test_command_creates_publication_type() 'Tag', ], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?', 'yes') + ->expectsConfirmation('Would you like to enable pagination?', 'yes') ->expectsChoice('Choose the default field you wish to sort by', '__createdAt', [ '__createdAt', 'publication-title', @@ -59,7 +59,6 @@ public function test_command_creates_publication_type() 'Ascending', 'Descending', ]) - ->expectsConfirmation('Generate previous/next links in detail view?', 'yes') ->expectsQuestion('Enter the page size (0 for no limit)', 10) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'publication-title', [ '__createdAt', @@ -81,7 +80,6 @@ public function test_command_creates_publication_type() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 10 }, "fields": [ @@ -129,7 +127,7 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsConfirmation('Field #2 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?') + ->expectsConfirmation('Would you like to enable pagination?') ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'foo', [ '__createdAt', 'bar', @@ -188,7 +186,6 @@ public function testWithTagFieldInput() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [ @@ -242,7 +239,7 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsOutput("Okay, we're back on track!") ->expectsChoice('Enter tag group for field #1', 'foo', ['foo'], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?') + ->expectsConfirmation('Would you like to enable pagination?') ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') ->assertSuccessful(); diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 1371dce9a3c..2740af557b8 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -74,10 +74,12 @@ protected function getTestData(): array 'sortField' => 'sort', 'sortAscending' => true, 'pageSize' => 10, - 'prevNextLinks' => true, ], 'fields' => [ - 'foo' => 'bar', + [ + 'type' => 'string', + 'name' => 'Foo', + ], ], ]; } diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index ad051c6c5e5..bbebb8dda49 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -121,8 +121,7 @@ protected function createRealPublicationFiles(): void "pagination": { "sortField": "__createdAt", "sortAscending": true, - "pageSize": 0, - "prevNextLinks": true + "pageSize": 0 }, "fields": [ { diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index ce9b463fe2c..0f77854c031 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -33,7 +33,11 @@ public function test_can_construct_new_publication_type() if ($key === 'pagination') { $this->assertEquals($property, $publicationType->$key->toArray()); } else { - $this->assertEquals($property, $publicationType->$key); + if ($key === 'fields') { + $this->assertEquals($property, $publicationType->$key->toArray()); + } else { + $this->assertEquals($property, $publicationType->$key); + } } } } @@ -43,30 +47,24 @@ public function test_construct_with_default_values() $publicationType = new PublicationType('Test Publication'); $this->assertEquals('Test Publication', $publicationType->name); - $this->assertEquals('identifier', $publicationType->canonicalField); + $this->assertEquals('__createdAt', $publicationType->canonicalField); $this->assertEquals('detail.blade.php', $publicationType->detailTemplate); $this->assertEquals('list.blade.php', $publicationType->listTemplate); - $this->assertEquals([], $publicationType->fields); - $this->assertEquals(PaginationSettings::fromArray([ - 'sortField' => '__createdAt', - 'sortAscending' => true, - 'pageSize' => 25, - 'prevNextLinks' => true, - ]), $publicationType->pagination); + $this->assertEquals(collect([]), $publicationType->fields); + $this->assertNull($publicationType->pagination); $this->assertEquals('test-publication', $publicationType->getDirectory()); } - public function test_construct_with_pagination_object() + public function test_construct_with_pagination_settings() { - $paginationSettings = PaginationSettings::fromArray([ + $paginationSettings = [ 'sortField' => 'title', 'sortAscending' => false, 'pageSize' => 10, - 'prevNextLinks' => false, - ]); + ]; $publicationType = new PublicationType('Test Publication', pagination: $paginationSettings); - $this->assertSame($paginationSettings, $publicationType->pagination); + $this->assertSame($paginationSettings, $publicationType->pagination->toArray()); } public function test_class_is_arrayable() @@ -136,21 +134,14 @@ public function test_can_load_from_json_file() $this->assertEquals($publicationType, PublicationType::fromFile(('tests/fixtures/test-publication-schema.json'))); } - public function test_it_loads_arbitrary_publication_fields_from_schema_file() + public function test_can_load_fields_with_validation_rules() { $this->directory('test-publication'); $fields = [ [ - 'name' => 'Title', 'type' => 'text', - 'identifier' => 'title', - 'required' => true, - ], - [ - 'name' => 'Body', - 'type' => 'markdown', - 'identifier' => 'body', - 'required' => true, + 'name' => 'title', + 'rules' => ['required'], ], ]; $this->file('test-publication/schema.json', json_encode([ @@ -159,7 +150,7 @@ public function test_it_loads_arbitrary_publication_fields_from_schema_file() ])); $publicationType = PublicationType::fromFile('test-publication/schema.json'); - $this->assertSame($fields, $publicationType->fields); + $this->assertSame($fields, $publicationType->getFields()->toArray()); } public function test_get_fields_method_returns_collection_of_field_objects() @@ -170,7 +161,7 @@ public function test_get_fields_method_returns_collection_of_field_objects() $this->assertInstanceOf(Collection::class, $collection); $this->assertInstanceOf(PublicationFieldDefinition::class, $collection->first()); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title'), + new PublicationFieldDefinition('string', 'title'), ]), $collection); } @@ -187,8 +178,8 @@ public function test_get_field_method_parses_publication_fields_from_schema_file $publicationType = PublicationType::fromFile('test-publication/schema.json'); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title'), - 'number' => new PublicationFieldDefinition('integer', 'number'), + new PublicationFieldDefinition('string', 'title'), + new PublicationFieldDefinition('integer', 'number'), ]), $publicationType->getFields()); } @@ -205,22 +196,11 @@ public function test_get_field_method_parses_publication_fields_with_option_prop $publicationType = PublicationType::fromFile('test-publication/schema.json'); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title', ['foo', 'bar']), - 'tags' => new PublicationFieldDefinition('tag', 'tags', tagGroup: 'myTags'), + new PublicationFieldDefinition('string', 'title', ['foo', 'bar']), + new PublicationFieldDefinition('tag', 'tags', tagGroup: 'myTags'), ]), $publicationType->getFields()); } - public function test_get_field_data_returns_field_data() - { - $publicationType = new PublicationType(...$this->getTestData()); - - $this->assertSame([['name' => 'title', 'type' => 'string']], $publicationType->getFieldData()); - - $publicationType->fields = []; - - $this->assertSame([], $publicationType->getFieldData()); - } - public function test_get_method_can_find_existing_file_on_disk() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); @@ -316,7 +296,7 @@ public function testGetPaginatorSortsCollectionBySpecifiedPaginationSettings() $paginationSettings = new PaginationSettings('myNumber'); $fields = [['name' => 'myNumber', 'type' => 'integer']]; - $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings, fields: $fields); + $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings->toArray(), fields: $fields); $publicationType->save(); $pages[0] = (new PublicationPage('test-publication/page-1', ['myNumber' => 5], type: $publicationType))->save(); @@ -338,7 +318,7 @@ public function testGetPaginatorSortsCollectionBySpecifiedPaginationSettingsWith $paginationSettings = new PaginationSettings('myNumber', false); $fields = [['name' => 'myNumber', 'type' => 'integer']]; - $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings, fields: $fields); + $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings->toArray(), fields: $fields); $publicationType->save(); $pages[0] = (new PublicationPage('test-publication/page-1', ['myNumber' => 5], type: $publicationType))->save(); @@ -407,33 +387,59 @@ public function testArrayRepresentationWithDefaultValues() $this->assertSame([ 'name' => 'test-publication', - 'canonicalField' => 'identifier', + 'canonicalField' => '__createdAt', + 'detailTemplate' => 'detail.blade.php', + 'listTemplate' => 'list.blade.php', + 'fields' => [], + ], $publicationType->toArray()); + } + + public function testJsonRepresentationWithDefaultValues() + { + $publicationType = new PublicationType('test-publication'); + + $this->assertSame(<<<'JSON' + { + "name": "test-publication", + "canonicalField": "__createdAt", + "detailTemplate": "detail.blade.php", + "listTemplate": "list.blade.php", + "fields": [] + } + JSON, $publicationType->toJson()); + } + + public function testArrayRepresentationWithPaginationSettings() + { + $publicationType = new PublicationType('test-publication', pagination: (new PaginationSettings())->toArray()); + + $this->assertSame([ + 'name' => 'test-publication', + 'canonicalField' => '__createdAt', 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', 'pagination' => [ 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, 'pageSize' => 25, ], 'fields' => [], ], $publicationType->toArray()); } - public function testJsonRepresentationWithDefaultValues() + public function testJsonRepresentationWithPaginationSettings() { - $publicationType = new PublicationType('test-publication'); + $publicationType = new PublicationType('test-publication', pagination: (new PaginationSettings())->toArray()); $this->assertSame(<<<'JSON' { "name": "test-publication", - "canonicalField": "identifier", + "canonicalField": "__createdAt", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [] @@ -451,13 +457,12 @@ protected function getTestData(array $mergeData = []): array 'pagination' => [ 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, 'pageSize' => 25, ], 'fields' => [ [ - 'name' => 'title', 'type' => 'string', + 'name' => 'title', ], ], ], $mergeData); diff --git a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php index 3c70f0f3ef9..17cd15cfe3e 100644 --- a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php +++ b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php @@ -244,7 +244,7 @@ protected function pubType(): PublicationType 'canonicalField', 'detail.blade.php', 'list.blade.php', - ['sortField', true, true, 1], + ['sortField', true, 1], [], 'directory' ); diff --git a/packages/framework/tests/Unit/PaginationSettingsTest.php b/packages/framework/tests/Unit/PaginationSettingsTest.php index 79264777f1d..35bdb40b9a8 100644 --- a/packages/framework/tests/Unit/PaginationSettingsTest.php +++ b/packages/framework/tests/Unit/PaginationSettingsTest.php @@ -19,17 +19,15 @@ public function testConstructWithDefaultValues() $this->assertSame('__createdAt', $paginationSettings->sortField); $this->assertSame(true, $paginationSettings->sortAscending); $this->assertSame(25, $paginationSettings->pageSize); - $this->assertSame(true, $paginationSettings->prevNextLinks); } public function testConstruct() { - $paginationSettings = new PaginationSettings('foo', false, false, 10); + $paginationSettings = new PaginationSettings('foo', false, 10); $this->assertSame('foo', $paginationSettings->sortField); $this->assertFalse($paginationSettings->sortAscending); $this->assertSame(10, $paginationSettings->pageSize); - $this->assertFalse($paginationSettings->prevNextLinks); } public function testFromArray() @@ -38,13 +36,11 @@ public function testFromArray() 'sortField' => 'foo', 'sortAscending' => false, 'pageSize' => 10, - 'prevNextLinks' => false, ]); $this->assertSame('foo', $paginationSettings->sortField); $this->assertSame(false, $paginationSettings->sortAscending); $this->assertSame(10, $paginationSettings->pageSize); - $this->assertSame(false, $paginationSettings->prevNextLinks); } public function testToArray() @@ -54,7 +50,6 @@ public function testToArray() $this->assertSame([ 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, 'pageSize' => 25, ], $paginationSettings->toArray()); } @@ -63,7 +58,7 @@ public function testToJson() { $paginationSettings = new PaginationSettings(); - $this->assertSame('{"sortField":"__createdAt","sortAscending":true,"prevNextLinks":true,"pageSize":25}', $paginationSettings->toJson()); + $this->assertSame('{"sortField":"__createdAt","sortAscending":true,"pageSize":25}', $paginationSettings->toJson()); } public function testJsonSerialize() diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 75507907378..0cb042c9f06 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -48,6 +48,7 @@ protected function tearDown(): void parent::tearDown(); } + /** @deprecated as it's probably better to do this via the object constructor */ protected function setupTestPublication(string $directory = 'test-publication') { Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json index 0528d26e352..0617a00d452 100644 --- a/tests/fixtures/test-publication-schema.json +++ b/tests/fixtures/test-publication-schema.json @@ -6,8 +6,7 @@ "pagination": { "sortField": "__createdAt", "sortAscending": true, - "pageSize": 25, - "prevNextLinks": true + "pageSize": 25 }, "fields": [ {