diff --git a/packages/framework/src/Console/Commands/MakePublicationCommand.php b/packages/framework/src/Console/Commands/MakePublicationCommand.php index 37f9de75db4..1115b3d92cc 100644 --- a/packages/framework/src/Console/Commands/MakePublicationCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationCommand.php @@ -189,19 +189,6 @@ protected function generateFieldRules(PublicationField $field): Collection $fieldRules = Collection::make($field->type->rules()); if ($fieldRules->contains('between')) { $fieldRules->forget($fieldRules->search('between')); - if ($field->min && $field->max) { - switch ($field->type) { - case 'string': - case 'integer': - case 'float': - $fieldRules->add("between:$field->min,$field->max"); - break; - case 'datetime': - $fieldRules->add("after:$field->min"); - $fieldRules->add("before:$field->max"); - break; - } - } } return $fieldRules; diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 604575c08aa..cdc0e3013ca 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -87,11 +87,6 @@ protected function captureFieldsDefinitions(): Collection $type = $this->getFieldType(); if ($type < 10) { - do { - $fieldData['min'] = trim($this->askWithValidation('min', 'Min value (see Documentation)', ['required', 'string'], 0)); - $fieldData['max'] = trim($this->askWithValidation('max', 'Max value (see Documentation)', ['required', 'string'], 0)); - $lengthsValid = $this->validateLengths($fieldData['min'], $fieldData['max']); - } while (! $lengthsValid); } else { $fieldData = $this->getFieldDataForTag($fieldData); } diff --git a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php index 1aaa84eb0fb..11bddbe8d00 100644 --- a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php +++ b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php @@ -68,7 +68,7 @@ public function safeHandle(): int foreach ($publication->type->fields as $field) { $countFields++; $fieldName = $field['name']; - $pubTypeField = new PublicationField($field['type'], $fieldName, $field['min'], $field['max'], $field['tagGroup'] ?? null, $pubType); + $pubTypeField = new PublicationField($field['type'], $fieldName, $field['tagGroup'] ?? null, $pubType); try { if ($verbose) { diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php index 2bb204095d0..4b32e5a14ad 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php @@ -9,10 +9,7 @@ use Hyde\Framework\Features\Publications\PublicationService; use Hyde\Support\Concerns\Serializable; use Hyde\Support\Contracts\SerializableContract; -use Illuminate\Support\Carbon; use Illuminate\Support\Str; -use InvalidArgumentException; -use JetBrains\PhpStorm\Deprecated; use Rgasch\Collection\Collection; use function strtolower; @@ -27,10 +24,6 @@ class PublicationField implements SerializableContract use Serializable; public readonly PublicationFieldTypes $type; - /** @deprecated https://github.com/hydephp/develop/pull/685#issuecomment-1361565809 */ - public readonly string $max; - /** @deprecated https://github.com/hydephp/develop/pull/685#issuecomment-1361565809 */ - public readonly string $min; public readonly string $name; public readonly ?string $tagGroup; public readonly ?PublicationType $publicationType; // Only used for validation command, interactive command doesn't need this @@ -40,18 +33,12 @@ public static function fromArray(array $array): static return new static(...$array); } - public function __construct(PublicationFieldTypes|string $type, string $name, #[Deprecated] int | string | null $min = '0', #[Deprecated] int | string | null $max = '0', ?string $tagGroup = null, PublicationType $publicationType = null) + public function __construct(PublicationFieldTypes|string $type, string $name, ?string $tagGroup = null, PublicationType $publicationType = null) { $this->type = $type instanceof PublicationFieldTypes ? $type : PublicationFieldTypes::from(strtolower($type)); $this->name = Str::kebab($name); - $this->min = (string) $min; - $this->max = (string) $max; $this->tagGroup = $tagGroup; $this->publicationType = $publicationType; - - if ($max < $min && $max !== '0') { - throw new InvalidArgumentException("The 'max' value cannot be less than the 'min' value."); - } } public function toArray(): array @@ -59,8 +46,6 @@ public function toArray(): array return [ 'type' => $this->type->value, 'name' => $this->name, - 'min' => $this->min, - 'max' => $this->max, 'tagGroup' => $this->tagGroup, ]; } @@ -74,41 +59,20 @@ public function getValidationRules(bool $reload = true): Collection $defaultRules = Collection::create(PublicationFieldTypes::values()); $fieldRules = Collection::create($defaultRules->get($this->type->value)); - $useRange = true; - // The trim command used to process the min/max input results in a string, so - // we need to test both int and string values to determine required status. - if (($this->min && ! $this->max) || ($this->min == '0' && $this->max == '0')) { - $fieldRules->forget($fieldRules->search('required')); - $useRange = false; - } - switch ($this->type->value) { case 'array': $fieldRules->add('array'); break; case 'datetime': $fieldRules->add('date'); - if ($this->min) { - $dateMin = Carbon::parse($this->min); - $fieldRules->add("after:$dateMin"); - } - if ($this->max) { - $dateMax = Carbon::parse($this->max); - $fieldRules->add("before:$dateMax"); - } + break; case 'float': $fieldRules->add('numeric'); - if ($useRange) { - $fieldRules->add("between:$this->min,$this->max"); - } break; case 'integer': case 'string': case 'text': - if ($useRange) { - $fieldRules->add("between:$this->min,$this->max"); - } break; case 'image': $mediaFiles = PublicationService::getMediaForPubType($this->publicationType, $reload); diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index f1920aef16f..c209aaeeb6e 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -121,7 +121,7 @@ public function getFieldRules(bool $reload = false): Collection public function getCanonicalFieldDefinition(): PublicationField { if (str_starts_with($this->canonicalField, '__')) { - return new PublicationField('string', $this->canonicalField, 0, 0); + return new PublicationField('string', $this->canonicalField); } return $this->getFields()->filter(fn (PublicationField $field): bool => $field->name === $this->canonicalField)->first(); diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationPageTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationPageTest.php index ff39d5be183..06525dc3fbf 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationPageTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationPageTest.php @@ -62,13 +62,9 @@ public function testWithTextType() $pubType = $this->makePublicationType([[ 'type' => 'string', 'name' => 'title', - 'min' => 0, - 'max' => 128, ], [ 'type' => 'text', 'name' => 'description', - 'min' => 0, - 'max' => 128, ]]); $fieldData = Collection::make([ @@ -99,13 +95,9 @@ public function testWithArrayType() $pubType = $this->makePublicationType([[ 'type' => 'string', 'name' => 'title', - 'min' => 0, - 'max' => 128, ], [ 'type' => 'array', 'name' => 'tags', - 'min' => 0, - 'max' => 128, ]]); $fieldData = Collection::make([ @@ -146,13 +138,9 @@ public function testCreateWithoutSupplyingRequiredField() $pubType = $this->makePublicationType([[ 'type' => 'string', 'name' => 'title', - 'min' => 0, - 'max' => 128, ], [ 'type' => 'string', 'name' => 'slug', - 'min' => 0, - 'max' => 128, ]]); $fieldData = Collection::make([ @@ -181,19 +169,13 @@ public function testItCreatesValidYaml() $pubType = $this->makePublicationType([[ 'type' => 'string', 'name' => 'title', - 'min' => 0, - 'max' => 128, ], [ 'type' => 'text', 'name' => 'description', - 'min' => 0, - 'max' => 128, ], [ 'type' => 'array', 'name' => 'tags', - 'min' => 0, - 'max' => 128, ]]); $fieldData = Collection::make([ @@ -242,8 +224,6 @@ protected function makePublicationType(array $fields = [ [ 'type' => 'string', 'name' => 'title', - 'min' => 0, - 'max' => 128, ], ]): PublicationType { diff --git a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php index 8d4b4e86c1e..521432ded42 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php @@ -166,8 +166,6 @@ public function test_command_with_text_input() 'fields' => [[ 'type' => 'text', 'name' => 'description', - 'min' => '0', - 'max' => '0', ], ], ]); @@ -196,8 +194,6 @@ public function test_command_with_array_input() 'fields' => [[ 'type' => 'array', 'name' => 'tags', - 'min' => '0', - 'max' => '0', ], ], ]); @@ -237,8 +233,6 @@ protected function makeSchemaFile(array $merge = []): void 'fields' => [ [ 'name' => 'title', - 'min' => '0', - 'max' => '0', 'type' => 'string', ], ], diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 6609bfef224..0ae5e406164 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -39,8 +39,6 @@ public function test_command_creates_publication_type() 9 => 'Local Image', 10 => 'Tag (select value from list)', ]) - ->expectsQuestion('Min value (see Documentation)', '0') - ->expectsQuestion('Max value (see Documentation)', '0') ->expectsQuestion('Add another field (y/n)', 'n') ->expectsChoice('Choose the default field you wish to sort by', 'dateCreated (meta field)', [ 'dateCreated (meta field)', @@ -78,8 +76,6 @@ public function test_command_creates_publication_type() { "type": "string", "name": "publication-title", - "min": "0", - "max": "0", "tagGroup": null } ] @@ -92,26 +88,4 @@ public function test_command_creates_publication_type() Filesystem::deleteDirectory('test-publication'); } - - public function test_cannot_create_field_with_lower_max_than_min_value() - { - $this->artisan('make:publicationType test-publication') - ->expectsQuestion('Field name', 'foo') - ->expectsQuestion('Field type', 'foo') - ->expectsQuestion('Min value (see Documentation)', 10) - ->expectsQuestion('Max value (see Documentation)', 5) - ->expectsQuestion('Min value (see Documentation)', 5) - ->expectsQuestion('Max value (see Documentation)', 10) - - ->expectsQuestion('Add another field (y/n)', 'n') - ->expectsQuestion('Choose the default field you wish to sort by', 'foo') - ->expectsQuestion('Choose the default sort direction', 'Ascending (oldest items first if sorting by dateCreated)') - ->expectsQuestion('Enter the pageSize (0 for no limit)', 10) - ->expectsQuestion('Generate previous/next links in detail view (y/n)', 'n') - ->expectsQuestion('Choose a canonical name field (the values of this field have to be unique!)', 'foo') - ->expectsOutputToContain('Creating a new Publication Type!') - ->assertSuccessful(); - - Filesystem::deleteDirectory('test-publication'); - } } diff --git a/packages/framework/tests/Feature/PublicationFieldTest.php b/packages/framework/tests/Feature/PublicationFieldTest.php index fa4254405f3..cff7ebc566b 100644 --- a/packages/framework/tests/Feature/PublicationFieldTest.php +++ b/packages/framework/tests/Feature/PublicationFieldTest.php @@ -7,7 +7,6 @@ use Hyde\Framework\Features\Publications\Models\PublicationField; use Hyde\Framework\Features\Publications\PublicationFieldTypes; use Hyde\Testing\TestCase; -use InvalidArgumentException; use ValueError; /** @@ -22,8 +21,6 @@ public function test_can_instantiate_class() $this->assertSame(PublicationFieldTypes::String, $field->type); $this->assertSame('test', $field->name); - $this->assertSame('1', $field->min); - $this->assertSame('10', $field->max); } public function test_from_array_method() @@ -31,16 +28,12 @@ public function test_from_array_method() $field = PublicationField::fromArray([ 'type' => 'string', 'name' => 'test', - 'min' => '1', - 'max' => '10', ]); $this->assertInstanceOf(PublicationField::class, $field); $this->assertSame(PublicationFieldTypes::String, $field->type); $this->assertSame('test', $field->name); - $this->assertSame('1', $field->min); - $this->assertSame('10', $field->max); } public function test_can_get_field_as_array() @@ -48,86 +41,43 @@ public function test_can_get_field_as_array() $this->assertSame([ 'type' => 'string', 'name' => 'test', - 'min' => '1', - 'max' => '10', 'tagGroup' => null, ], $this->makeField()->toArray()); } public function test_can_encode_field_as_json() { - $this->assertSame('{"type":"string","name":"test","min":"1","max":"10","tagGroup":null}', json_encode($this->makeField())); + $this->assertSame('{"type":"string","name":"test","tagGroup":null}', json_encode($this->makeField())); } public function test_can_construct_type_using_enum_case() { - $field1 = new PublicationField(PublicationFieldTypes::String, 'test', 1, 10); + $field1 = new PublicationField(PublicationFieldTypes::String, 'test'); $this->assertSame(PublicationFieldTypes::String, $field1->type); - $field2 = new PublicationField('string', 'test', 1, 10); + $field2 = new PublicationField('string', 'test'); $this->assertSame(PublicationFieldTypes::String, $field2->type); $this->assertEquals($field1, $field2); } - public function test_default_range_values() - { - $field = new PublicationField('string', 'test'); - $this->assertSame('0', $field->min); - $this->assertSame('0', $field->max); - } - - public function test_null_range_values_are_cast_to_empty_string() - { - $field = new PublicationField('string', 'test', null, null); - $this->assertSame('', $field->min); - $this->assertSame('', $field->max); - } - - public function test_max_value_cannot_be_less_than_min_value() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The 'max' value cannot be less than the 'min' value."); - - new PublicationField('string', 'test', '10', '1'); - } - - public function test_only_min_value_can_be_set() - { - new PublicationField('string', 'test', '1'); - $this->assertTrue(true); - } - - public function test_only_max_value_can_be_set() - { - new PublicationField('string', 'test', null, '10'); - $this->assertTrue(true); - } - - public function test_integers_can_be_added_as_strings() - { - $field = new PublicationField('string', 'test', '1', '10'); - $this->assertSame('1', $field->min); - $this->assertSame('10', $field->max); - } - public function test_type_must_be_valid() { $this->expectException(ValueError::class); $this->expectExceptionMessage('"invalid" is not a valid backing value for enum "'.PublicationFieldTypes::class.'"'); - new PublicationField('invalid', 'test', '1', '10'); + new PublicationField('invalid', 'test'); } public function test_type_input_is_case_insensitive() { - $field = new PublicationField('STRING', 'test', '1', '10'); + $field = new PublicationField('STRING', 'test'); $this->assertSame(PublicationFieldTypes::String, $field->type); } public function test_name_gets_stored_as_kebab_case() { - $field = new PublicationField('string', 'Test Field', '1', '10'); + $field = new PublicationField('string', 'Test Field'); $this->assertSame('test-field', $field->name); } @@ -138,6 +88,6 @@ public function test_validate_input_against_rules() protected function makeField(): PublicationField { - return new PublicationField('string', 'test', 1, '10'); + return new PublicationField('string', 'test'); } } diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index c0bc298e558..bff8605712e 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -127,8 +127,6 @@ protected function createRealPublicationFiles(): void "fields": [ { "name": "slug", - "min": "4", - "max": "32", "type": "string" } ] diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index eb63cfeae50..c40a25be672 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -139,7 +139,7 @@ public function test_get_fields_method_returns_collection_of_field_objects() $this->assertInstanceOf(Collection::class, $collection); $this->assertInstanceOf(PublicationField::class, $collection->first()); $this->assertEquals(new \Rgasch\Collection\Collection([ - 'title' => new PublicationField('string', 'title', 0, 128), + 'title' => new PublicationField('string', 'title'), ]), $collection); } @@ -169,7 +169,7 @@ public function test_get_field_rules() { $publicationType = new PublicationType(...$this->getTestData()); $this->assertEquals([ - 'title' => ['between:0,128'], + 'title' => [], ], $publicationType->getFieldRules()->toArray()); } @@ -189,8 +189,6 @@ protected function getTestData(): array 'fields' => [ [ 'name' => 'title', - 'min' => '0', - 'max' => '128', 'type' => 'string', ], ], diff --git a/packages/framework/tests/Unit/PublicationFieldValidationRulesTest.php b/packages/framework/tests/Unit/PublicationFieldValidationRulesTest.php index a66712ea01b..b51ed0381c5 100644 --- a/packages/framework/tests/Unit/PublicationFieldValidationRulesTest.php +++ b/packages/framework/tests/Unit/PublicationFieldValidationRulesTest.php @@ -79,7 +79,7 @@ public function testGetRulesForImage() $this->directory('_media/foo'); $this->file('_media/foo/bar.jpg'); $this->file('_media/foo/baz.png'); - $rules = (new PublicationField('image', 'myImage', publicationType: new PublicationType('foo')))->getValidationRules(); + $rules = (new PublicationField('image', 'myImage', null, publicationType: new PublicationType('foo')))->getValidationRules(); $this->assertSame(['in:_media/foo/bar.jpg,_media/foo/baz.png'], $rules->toArray()); } diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json index 490762392f0..08d24f68970 100644 --- a/tests/fixtures/test-publication-schema.json +++ b/tests/fixtures/test-publication-schema.json @@ -12,8 +12,6 @@ "fields": [ { "name": "title", - "min": "0", - "max": "128", "type": "string" } ]