diff --git a/tests/Fields/AccordionTest.php b/tests/Fields/AccordionTest.php index b06ff5c2..510dda62 100644 --- a/tests/Fields/AccordionTest.php +++ b/tests/Fields/AccordionTest.php @@ -14,31 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Accordion; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Endpoint; +use Extended\ACF\Tests\Fields\Settings\Instructions; -class AccordionTest extends TestCase +class AccordionTest extends FieldTestCase { - public function testType() - { - $field = Accordion::make('Accordion')->get(); - $this->assertSame('accordion', $field['type']); - } + use Endpoint; + use Instructions; - public function testEndpoint() - { - $field = Accordion::make('Accordion Endpoint')->endpoint()->get(); - $this->assertTrue($field['endpoint']); - } + public string $field = Accordion::class; + public string $type = 'accordion'; public function testMultiExpand() { - $field = Accordion::make('Accordion Multi Expand')->multiExpand()->get(); + $field = Accordion::make('Multi Expand')->multiExpand()->get(); $this->assertTrue($field['multi_expand']); } public function testOpen() { - $field = Accordion::make('Accordion Open')->open()->get(); + $field = Accordion::make('Open')->open()->get(); $this->assertTrue($field['open']); } } diff --git a/tests/Fields/ButtonGroupTest.php b/tests/Fields/ButtonGroupTest.php index 9020eb2b..5f0068da 100644 --- a/tests/Fields/ButtonGroupTest.php +++ b/tests/Fields/ButtonGroupTest.php @@ -14,24 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\ButtonGroup; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Choices; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\DirectionLayout; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class ButtonGroupTest extends TestCase +class ButtonGroupTest extends FieldTestCase { - public function testType() - { - $field = ButtonGroup::make('Button Group')->get(); - $this->assertSame('button_group', $field['type']); - } + use Choices; + use ConditionalLogic; + use DefaultValue; + use DirectionLayout; + use Instructions; + use Required; + use ReturnFormat; + use Wrapper; - public function testChoices() - { - $choices = ['blue' => 'Blue Pill', 'red' => 'Red Pill']; - $field = ButtonGroup::make('Choices')->choices($choices)->get(); - $this->assertSame($choices, $field['choices']); - - $choices = ['Forest Green', 'Sky Blue']; - $field = ButtonGroup::make('Choices List')->choices($choices)->get(); - $this->assertSame(['forest_green' => 'Forest Green', 'sky_blue' => 'Sky Blue'], $field['choices']); - } + public string $field = ButtonGroup::class; + public string $type = 'button_group'; } diff --git a/tests/Fields/CheckboxTest.php b/tests/Fields/CheckboxTest.php index 274ada2a..df3f5e2e 100644 --- a/tests/Fields/CheckboxTest.php +++ b/tests/Fields/CheckboxTest.php @@ -14,25 +14,29 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Checkbox; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -class CheckboxTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\Choices; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\DirectionLayout; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class CheckboxTest extends FieldTestCase { - public function testType() - { - $field = Checkbox::make('Checkbox')->get(); - $this->assertSame('checkbox', $field['type']); - } - - public function testLayout() - { - $field = Checkbox::make('Checkbox Layout')->layout('horizontal')->get(); - $this->assertSame('horizontal', $field['layout']); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid argument layout [test].'); - - Checkbox::make('Invalid Checkbox Layout')->layout('test'); - } + use Choices; + use ConditionalLogic; + use DefaultValue; + use DirectionLayout; + use Disabled; + use Instructions; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Checkbox::class; + public string $type = 'checkbox'; } diff --git a/tests/Fields/ColorPickerTest.php b/tests/Fields/ColorPickerTest.php index d39a7b6f..3affe48a 100644 --- a/tests/Fields/ColorPickerTest.php +++ b/tests/Fields/ColorPickerTest.php @@ -14,19 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\ColorPicker; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class ColorPickerTest extends TestCase +class ColorPickerTest extends FieldTestCase { - public function testType() - { - $field = ColorPicker::make('Color Picker')->get(); - $this->assertSame('color_picker', $field['type']); - } + use ConditionalLogic; + use DefaultValue; + use Instructions; + use Required; + use Wrapper; + + public string $field = ColorPicker::class; + public string $type = 'color_picker'; public function testEnableOpacity() { - $field = ColorPicker::make('Color Picker Enable Opacity')->enableOpacity()->get(); + $field = ColorPicker::make('Enable Opacity')->enableOpacity()->get(); $this->assertTrue($field['enable_opacity']); } } diff --git a/tests/Fields/DatePickerTest.php b/tests/Fields/DatePickerTest.php index e2db600c..0b222be1 100644 --- a/tests/Fields/DatePickerTest.php +++ b/tests/Fields/DatePickerTest.php @@ -14,31 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\DatePicker; -use PHPUnit\Framework\TestCase; - -class DatePickerTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DateTimeFormat; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\WeekDay; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class DatePickerTest extends FieldTestCase { - public function testType() - { - $field = DatePicker::make('Date Picker')->get(); - $this->assertSame('date_picker', $field['type']); - } - - public function testDisplayFormat() - { - $field = DatePicker::make('Date Display Format')->displayFormat('d/m/Y')->get(); - $this->assertSame('d/m/Y', $field['display_format']); - } - - public function testReturnFormat() - { - $field = DatePicker::make('Date Return Format')->returnFormat('d/m/Y')->get(); - $this->assertSame('d/m/Y', $field['return_format']); - } - - public function testFirstDayOfWeek() - { - $field = DatePicker::make('Date Week Day')->firstDayOfWeek(1)->get(); - $this->assertSame(1, $field['first_day']); - } + use ConditionalLogic; + use DateTimeFormat; + use Disabled; + use Immutable; + use Instructions; + use Required; + use WeekDay; + use Wrapper; + + public string $field = DatePicker::class; + public string $type = 'date_picker'; } diff --git a/tests/Fields/DateTimePickerTest.php b/tests/Fields/DateTimePickerTest.php index c60af60c..b60e6622 100644 --- a/tests/Fields/DateTimePickerTest.php +++ b/tests/Fields/DateTimePickerTest.php @@ -14,13 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\DateTimePicker; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DateTimeFormat; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\WeekDay; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class DateTimePickerTest extends TestCase +class DateTimePickerTest extends FieldTestCase { - public function testType() - { - $field = DateTimePicker::make('Date Time Picker')->get(); - $this->assertSame('date_time_picker', $field['type']); - } + use ConditionalLogic; + use DateTimeFormat; + use Disabled; + use Immutable; + use Instructions; + use Required; + use WeekDay; + use Wrapper; + + public string $field = DateTimePicker::class; + public string $type = 'date_time_picker'; } diff --git a/tests/Fields/EmailTest.php b/tests/Fields/EmailTest.php index e78a6306..c6ed08d4 100644 --- a/tests/Fields/EmailTest.php +++ b/tests/Fields/EmailTest.php @@ -14,13 +14,28 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Email; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Affixable; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Placeholder; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class EmailTest extends TestCase +class EmailTest extends FieldTestCase { - public function testType() - { - $field = Email::make('Email Address')->get(); - $this->assertSame('email', $field['type']); - } + use Affixable; + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use Placeholder; + use Required; + use Wrapper; + + public string $field = Email::class; + public string $type = 'email'; } diff --git a/tests/Fields/FieldTest.php b/tests/Fields/FieldTest.php new file mode 100644 index 00000000..075a45d5 --- /dev/null +++ b/tests/Fields/FieldTest.php @@ -0,0 +1,86 @@ +get(); + $this->assertSame('Label', $field['label']); + } + + public function testName() + { + $field = Text::make('Label Name')->get(); + $this->assertSame('label_name', $field['name']); + + $field = Text::make('Custom Name', 'custom_name')->get(); + $this->assertSame('custom_name', $field['name']); + } + + public function testKey() + { + $field = Text::make('Key')->get(); + $this->assertSame('field_722bfe15', $field['key']); + } + + public function testCustomKey() + { + $field = Text::make('Custom Key')->key('field_123456')->get(); + $this->assertSame('field_123456', $field['key']); + } + + public function testKeyUniqueness() + { + $this->expectExceptionMessage('The key [field_16217cde] is not unique.'); + Text::make('Key Uniqueness 1')->key('field_16217cde'); + Text::make('Key Uniqueness 2')->key('field_16217cde'); + } + + public function testKeyPrefix() + { + $this->expectExceptionMessage('The key should have the prefix [field_].'); + Text::make('Key refix')->key('phone')->get(); + } + + public function testWithSettings() + { + $field = Text::make('With Settings')->withSettings(['custom' => 'setting'])->get(); + $this->assertSame('setting', $field['custom']); + + $this->expectException(InvalidArgumentException::class); + Text::make('With Settings Label')->withSettings(['label' => 'invalid'])->get(); + } + + public function testDump() + { + $log = []; + + VarDumper::setHandler(function ($value) use (&$log) { + $log[] = $value; + }); + + Text::make('Dump')->dump(1, 2); + + $this->assertSame([['label' => 'Dump', 'name' => 'dump', 'type' => 'text', 'key' => 'field_076f7d8c'], 1, 2], $log); + + VarDumper::setHandler(null); + } +} diff --git a/tests/Fields/FieldTestCase.php b/tests/Fields/FieldTestCase.php index bf5c4404..c767ccde 100644 --- a/tests/Fields/FieldTestCase.php +++ b/tests/Fields/FieldTestCase.php @@ -13,8 +13,7 @@ namespace Extended\ACF\Tests\Fields; -use Extended\ACF\Key; -use InvalidArgumentException; +use Extended\ACF\Fields\Field; use PHPUnit\Framework\TestCase; class FieldTestCase extends TestCase @@ -22,73 +21,17 @@ class FieldTestCase extends TestCase public string $field; public string $type; - protected function label(string $label): string + protected function make(string $label): Field { $exploded = explode('\\', $this->field); $className = end($exploded); - return $className . ' ' . $label; + return $this->field::make($className . ' ' . $label); } public function testType() { - $settings = $this->field::make($this->type)->get(); + $settings = $this->make($this->type)->get(); $this->assertSame($this->type, $settings['type']); } - - public function testLabel() - { - $field = $this->field::make($this->label('Name'))->get(); - $this->assertSame($this->label('Name'), $field['label']); - } - - public function testName() - { - $name = Key::sanitize($this->label('Name 1')); - $field = $this->field::make($this->label('Name 1'))->get(); - $this->assertSame($name, $field['name']); - - $name = Key::sanitize($this->label('Name 2')); - $field = $this->field::make($this->label('Name 2'), $name)->get(); - $this->assertSame($name, $field['name']); - } - - public function testKey() - { - $label = $this->label('Key'); - $name = Key::sanitize($label); - $key = 'field_' . Key::hash('_' . $name); // prefix with an underscore by default when there is no parent key - - $field = $this->field::make($label)->get(); - $this->assertSame($key, $field['key']); - } - - public function testCustomKey() - { - $key = Key::sanitize($this->label('Custom Key')); - $field = $this->field::make($this->label('Custom Key'))->key('field_' . $key)->get(); - $this->assertSame('field_' . $key, $field['key']); - } - - public function testKeyUniqueness() - { - $this->expectExceptionMessage('The key [field_16217cde] is not unique.'); - $this->field::make($this->label('Key Uniqueness 1'))->key('field_16217cde'); - $this->field::make($this->label('Key Uniqueness 2'))->key('field_16217cde'); - } - - public function testKeyPrefix() - { - $this->expectExceptionMessage('The key should have the prefix [field_].'); - $this->field::make($this->label('Key Prefix'))->key('phone')->get(); - } - - public function testWithSettings() - { - $field = $this->field::make($this->label('With Settings'))->withSettings(['custom' => 'setting'])->get(); - $this->assertSame('setting', $field['custom']); - - $this->expectException(InvalidArgumentException::class); - $this->field::make($this->label('With Settings Label'))->withSettings(['label' => 'invalid'])->get(); - } } diff --git a/tests/Fields/FileTest.php b/tests/Fields/FileTest.php index aa1d3743..3f9ddc7d 100644 --- a/tests/Fields/FileTest.php +++ b/tests/Fields/FileTest.php @@ -14,43 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\File; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; - -class FileTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\FileSize; +use Extended\ACF\Tests\Fields\Settings\FileTypes; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Library; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class FileTest extends FieldTestCase { - public function testType() - { - $field = File::make('File')->get(); - $this->assertSame('file', $field['type']); - } - - public function testAcceptedFileTypes() - { - $field = File::make('File Accepted File Types')->acceptedFileTypes(['image/jpg', 'application/pdf'])->get(); - $this->assertSame('image/jpg,application/pdf', $field['mime_types']); - } - - public function testReturnFormat() - { - $field = File::make('Return Format')->returnFormat('array')->get(); - $this->assertSame('array', $field['return_format']); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid argument return format [test].'); - - File::make('Invalid Return Format')->returnFormat('test')->get(); - } - - public function testMinSize() - { - $field = File::make('File Min Size')->minSize('400 KB')->get(); - $this->assertSame('400 KB', $field['min_size']); - } - - public function testMaxSize() - { - $field = File::make('File Max Size')->maxSize(5)->get(); - $this->assertSame(5, $field['max_size']); - } + use ConditionalLogic; + use FileSize; + use FileTypes; + use Instructions; + use Library; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = File::class; + public string $type = 'file'; } diff --git a/tests/Fields/FlexibleContentTest.php b/tests/Fields/FlexibleContentTest.php index 8eb33e3e..4f6f4d7f 100644 --- a/tests/Fields/FlexibleContentTest.php +++ b/tests/Fields/FlexibleContentTest.php @@ -16,25 +16,28 @@ use Extended\ACF\Fields\FlexibleContent; use Extended\ACF\Fields\Layout; use Extended\ACF\Fields\Text; -use PHPUnit\Framework\TestCase; - -class FlexibleContentTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ButtonLabel; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class FlexibleContentTest extends FieldTestCase { - public function testType() - { - $field = FlexibleContent::make('Flexible Content')->get(); - $this->assertSame('flexible_content', $field['type']); - } + use ButtonLabel; + use ConditionalLogic; + use Instructions; + use MinMax; + use Required; + use Wrapper; - public function testLabels() - { - $field = FlexibleContent::make('Flexible Content Labels')->layouts([])->get(); - $this->assertSame([], $field['layouts']); - } + public string $field = FlexibleContent::class; + public string $type = 'flexible_content'; public function testLayouts() { - $field = FlexibleContent::make('Flexible Content Layouts') + $field = FlexibleContent::make('Layouts') ->layouts([ Layout::make('Image') ->fields([ diff --git a/tests/Fields/GalleryTest.php b/tests/Fields/GalleryTest.php index 693a33c2..a20f679c 100644 --- a/tests/Fields/GalleryTest.php +++ b/tests/Fields/GalleryTest.php @@ -14,16 +14,35 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Gallery; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Dimensions; +use Extended\ACF\Tests\Fields\Settings\FileSize; +use Extended\ACF\Tests\Fields\Settings\FileTypes; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Library; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\PreviewSize; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -class GalleryTest extends TestCase +class GalleryTest extends FieldTestCase { - public function testType() - { - $field = Gallery::make('Gallery')->get(); - $this->assertSame('gallery', $field['type']); - } + use ConditionalLogic; + use Dimensions; + use FileSize; + use FileTypes; + use Instructions; + use Library; + use MinMax; + use PreviewSize; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Gallery::class; + public string $type = 'gallery'; public function testInsert() { @@ -35,28 +54,4 @@ public function testInsert() Gallery::make('Invalid Insert')->insert('test')->get(); } - - public function testMaxHeight() - { - $field = Gallery::make('Gallery Max Height')->maxHeight(20)->get(); - $this->assertSame(20, $field['max_height']); - } - - public function testMinHeight() - { - $field = Gallery::make('Gallery Min Height')->minHeight(10)->get(); - $this->assertSame(10, $field['min_height']); - } - - public function testMaxWidth() - { - $field = Gallery::make('Gallery Max Width')->maxWidth(40)->get(); - $this->assertSame(40, $field['max_width']); - } - - public function testMinWidth() - { - $field = Gallery::make('Gallery Min Width')->minWidth(30)->get(); - $this->assertSame(30, $field['min_width']); - } } diff --git a/tests/Fields/GoogleMapTest.php b/tests/Fields/GoogleMapTest.php index 39a00a20..ef92afe7 100644 --- a/tests/Fields/GoogleMapTest.php +++ b/tests/Fields/GoogleMapTest.php @@ -14,15 +14,22 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\GoogleMap; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Height; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class GoogleMapTest extends TestCase +class GoogleMapTest extends FieldTestCase { - public function testType() - { - $field = GoogleMap::make('Google Map')->get(); - $this->assertSame('google_map', $field['type']); - } + use ConditionalLogic; + use Height; + use Instructions; + use Required; + use Wrapper; + + public string $field = GoogleMap::class; + public string $type = 'google_map'; public function testCenter() { diff --git a/tests/Fields/GroupTest.php b/tests/Fields/GroupTest.php index 0bc2cd33..e65fb014 100644 --- a/tests/Fields/GroupTest.php +++ b/tests/Fields/GroupTest.php @@ -14,37 +14,22 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Group; -use Extended\ACF\Fields\Text; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; - -class GroupTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Fields; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Layout; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class GroupTest extends FieldTestCase { - public function testType() - { - $field = Group::make('Group')->get(); - $this->assertSame('group', $field['type']); - } - - public function testFields() - { - $field = Group::make('Group Fields') - ->fields([ - Text::make('Title'), - ]) - ->get(); - - $this->assertSame('Title', $field['sub_fields'][0]['label']); - } - - public function testLayout() - { - $field = Group::make('Group Layout')->layout('block')->get(); - $this->assertSame('block', $field['layout']); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid argument layout [test].'); - - Group::make('Invalid Group Layout')->layout('test')->get(); - } + use ConditionalLogic; + use Fields; + use Instructions; + use Layout; + use Required; + use Wrapper; + + public string $field = Group::class; + public string $type = 'group'; } diff --git a/tests/Fields/ImageTest.php b/tests/Fields/ImageTest.php index e2b9226d..1d8e22dd 100644 --- a/tests/Fields/ImageTest.php +++ b/tests/Fields/ImageTest.php @@ -14,31 +14,30 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Image; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; - -class ImageTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Dimensions; +use Extended\ACF\Tests\Fields\Settings\FileSize; +use Extended\ACF\Tests\Fields\Settings\FileTypes; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Library; +use Extended\ACF\Tests\Fields\Settings\PreviewSize; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class ImageTest extends FieldTestCase { - public function testType() - { - $field = Image::make('Image')->get(); - $this->assertSame('image', $field['type']); - } - - public function testPreviewSize() - { - $field = Image::make('Preview Size')->previewSize('large')->get(); - $this->assertSame('large', $field['preview_size']); - } - - public function testLibrary() - { - $field = Image::make('Library')->library('all')->get(); - $this->assertSame('all', $field['library']); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid argument library [test].'); - - Image::make('Invalid Library')->library('test')->get(); - } + use ConditionalLogic; + use Dimensions; + use FileSize; + use FileTypes; + use Instructions; + use Library; + use PreviewSize; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Image::class; + public string $type = 'image'; } diff --git a/tests/Fields/LayoutTest.php b/tests/Fields/LayoutTest.php index 7cef1e2b..7a36123a 100644 --- a/tests/Fields/LayoutTest.php +++ b/tests/Fields/LayoutTest.php @@ -14,13 +14,32 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Layout; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Fields; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use InvalidArgumentException; -class LayoutTest extends TestCase +class LayoutTest extends FieldTestCase { - public function testDisplay() + use Fields; + use MinMax; + + public string $field = Layout::class; + public string $type = 'layout'; + + public function testType() { - $layout = Layout::make('Layout')->layout('block')->get(); - $this->assertSame('block', $layout['display']); + $field = Layout::make('Layout Key')->get(); + $this->assertStringStartsWith('layout_', $field['key']); + } + + public function testLayout() + { + $field = Layout::make('Layout')->layout('table')->get(); + $this->assertSame('table', $field['display']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument layout [test].'); + + Layout::make('Invalid Layout')->layout('test')->get(); } } diff --git a/tests/Fields/LinkTest.php b/tests/Fields/LinkTest.php index 1e1c803b..2d20c5cf 100644 --- a/tests/Fields/LinkTest.php +++ b/tests/Fields/LinkTest.php @@ -14,13 +14,20 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Link; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class LinkTest extends TestCase +class LinkTest extends FieldTestCase { - public function testType() - { - $field = Link::make('Link')->get(); - $this->assertSame('link', $field['type']); - } + use ConditionalLogic; + use Instructions; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Link::class; + public string $type = 'link'; } diff --git a/tests/Fields/MessageTest.php b/tests/Fields/MessageTest.php index 10718504..185c7662 100644 --- a/tests/Fields/MessageTest.php +++ b/tests/Fields/MessageTest.php @@ -14,25 +14,22 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Message; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Message as MessageAttribute; +use Extended\ACF\Tests\Fields\Settings\NewLines; -class MessageTest extends TestCase +class MessageTest extends FieldTestCase { - public function testType() - { - $field = Message::make('Message')->get(); - $this->assertSame('message', $field['type']); - } + use ConditionalLogic; + use MessageAttribute; + use NewLines; + + public string $field = Message::class; + public string $type = 'message'; public function testEscapeHtml() { - $field = Message::make('Message Escape HTML')->escapeHtml()->get(); + $field = Message::make('Escape HTML')->escapeHtml()->get(); $this->assertTrue($field['esc_html']); } - - public function testMessage() - { - $field = Message::make('Message Content')->message('The Content')->get(); - $this->assertSame('The Content', $field['message']); - } } diff --git a/tests/Fields/NumberTest.php b/tests/Fields/NumberTest.php index 85ba5054..693e9301 100644 --- a/tests/Fields/NumberTest.php +++ b/tests/Fields/NumberTest.php @@ -14,25 +14,32 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Number; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Affixable; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\Placeholder; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Step; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class NumberTest extends TestCase +class NumberTest extends FieldTestCase { - public function testType() - { - $field = Number::make('Number')->get(); - $this->assertSame('number', $field['type']); - } + use Affixable; + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use MinMax; + use Placeholder; + use Required; + use Step; + use Wrapper; - public function testMax() - { - $field = Number::make('Max')->max(10.5)->get(); - $this->assertSame(10.5, $field['max']); - } - - public function testMin() - { - $field = Number::make('Min')->min(5.5)->get(); - $this->assertSame(5.5, $field['min']); - } + public string $field = Number::class; + public string $type = 'number'; } diff --git a/tests/Fields/OembedTest.php b/tests/Fields/OembedTest.php index a170579f..335dc8df 100644 --- a/tests/Fields/OembedTest.php +++ b/tests/Fields/OembedTest.php @@ -14,25 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Oembed; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Height; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class OembedTest extends TestCase +class OembedTest extends FieldTestCase { - public function testType() - { - $field = Oembed::make('Oembed')->get(); - $this->assertSame('oembed', $field['type']); - } + use ConditionalLogic; + use Height; + use Instructions; + use Required; + use Wrapper; - public function testHeight() - { - $field = Oembed::make('Oembed Height')->height(100)->get(); - $this->assertSame(100, $field['height']); - } + public string $field = Oembed::class; + public string $type = 'oembed'; public function testWidth() { - $field = Oembed::make('Oembed Width')->width(200)->get(); + $field = Oembed::make('Width')->width(200)->get(); $this->assertSame(200, $field['width']); } } diff --git a/tests/Fields/PageLinkTest.php b/tests/Fields/PageLinkTest.php index ebbf571e..da150ce8 100644 --- a/tests/Fields/PageLinkTest.php +++ b/tests/Fields/PageLinkTest.php @@ -14,25 +14,36 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\PageLink; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\FilterBy; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Multiple; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class PageLinkTest extends TestCase +class PageLinkTest extends FieldTestCase { - public function testType() - { - $field = PageLink::make('Page Link')->get(); - $this->assertSame('page_link', $field['type']); - } + use ConditionalLogic; + use FilterBy; + use Instructions; + use Multiple; + use Nullable; + use Required; + use Wrapper; + + public string $field = PageLink::class; + public string $type = 'page_link'; public function testAllowArchives() { - $field = PageLink::make('Page Link Archives')->allowArchives()->get(); + $field = PageLink::make('Archives')->allowArchives()->get(); $this->assertTrue($field['allow_archives']); } public function testDisallowArchives() { - $field = PageLink::make('Page Link Non-archives')->allowArchives(false)->get(); + $field = PageLink::make('Non-archives')->allowArchives(false)->get(); $this->assertFalse($field['allow_archives']); } } diff --git a/tests/Fields/PostObjectTest.php b/tests/Fields/PostObjectTest.php index 9fac016c..1bf63912 100644 --- a/tests/Fields/PostObjectTest.php +++ b/tests/Fields/PostObjectTest.php @@ -14,37 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\PostObject; -use PHPUnit\Framework\TestCase; - -class PostObjectTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\FilterBy; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Multiple; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class PostObjectTest extends FieldTestCase { - public function testType() - { - $field = PostObject::make('Post Object')->get(); - $this->assertSame('post_object', $field['type']); - } - - public function testMultiple() - { - $field = PostObject::make('Post Object Multiple')->multiple()->get(); - $this->assertTrue($field['multiple']); - } - - public function testNullable() - { - $field = PostObject::make('Post Object Nullable')->nullable()->get(); - $this->assertTrue($field['allow_null']); - } - - public function testPostTypes() - { - $field = PostObject::make('Post Object Filter Post Type')->postTypes(['page'])->get(); - $this->assertSame(['page'], $field['post_type']); - } - - public function testTaxonomies() - { - $field = PostObject::make('Post Object Filter Taxonomy')->taxonomies(['category:untitled'])->get(); - $this->assertSame(['category:untitled'], $field['taxonomy']); - } + use ConditionalLogic; + use FilterBy; + use Instructions; + use Multiple; + use Nullable; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = PostObject::class; + public string $type = 'post_object'; } diff --git a/tests/Fields/RadioButtonTest.php b/tests/Fields/RadioButtonTest.php index 410daf7a..1a19bec7 100644 --- a/tests/Fields/RadioButtonTest.php +++ b/tests/Fields/RadioButtonTest.php @@ -14,13 +14,30 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\RadioButton; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Choices; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\DirectionLayout; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class RadioButtonTest extends TestCase +class RadioButtonTest extends FieldTestCase { - public function testType() - { - $field = RadioButton::make('Radio Button')->get(); - $this->assertSame('radio', $field['type']); - } + use Choices; + use ConditionalLogic; + use DefaultValue; + use DirectionLayout; + use Disabled; + use Instructions; + use Nullable; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = RadioButton::class; + public string $type = 'radio'; } diff --git a/tests/Fields/RangeTest.php b/tests/Fields/RangeTest.php index f451d0f9..6c6cca83 100644 --- a/tests/Fields/RangeTest.php +++ b/tests/Fields/RangeTest.php @@ -14,19 +14,30 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Range; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Affixable; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Step; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class RangeTest extends TestCase +class RangeTest extends FieldTestCase { - public function testType() - { - $field = Range::make('Range')->get(); - $this->assertSame('range', $field['type']); - } + use Affixable; + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use MinMax; + use Required; + use Step; + use Wrapper; - public function testStep() - { - $field = Range::make('Range Step')->step(5.2)->get(); - $this->assertSame(5.2, $field['step']); - } + public string $field = Range::class; + public string $type = 'range'; } diff --git a/tests/Fields/RelationshipTest.php b/tests/Fields/RelationshipTest.php index e5994082..9ac1231e 100644 --- a/tests/Fields/RelationshipTest.php +++ b/tests/Fields/RelationshipTest.php @@ -14,35 +14,36 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Relationship; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; - -class RelationshipTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\FilterBy; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class RelationshipTest extends FieldTestCase { - public function testType() - { - $field = Relationship::make('Relationship')->get(); - $this->assertSame('relationship', $field['type']); - } + use ConditionalLogic; + use FilterBy; + use Instructions; + use MinMax; + use Required; + use ReturnFormat; + use Wrapper; - public function testPostStatus() - { - $field = Relationship::make('Relationship Post Status')->postStatus(['publish'])->get(); - $this->assertSame(['publish'], $field['post_status']); - - $this->expectException(InvalidArgumentException::class); - Relationship::make('Relationship Invalid Post Status')->postStatus(['invalid'])->get(); - } + public string $field = Relationship::class; + public string $type = 'relationship'; public function testElements() { - $field = Relationship::make('Relationship Elements')->elements(['featured_image'])->get(); + $field = Relationship::make('Elements')->elements(['featured_image'])->get(); $this->assertSame(['featured_image'], $field['elements']); } public function testFilters() { - $field = Relationship::make('Relationship Filters')->filters(['search'])->get(); + $field = Relationship::make('Filters')->filters(['search'])->get(); $this->assertSame(['search'], $field['filters']); } } diff --git a/tests/Fields/RepeaterTest.php b/tests/Fields/RepeaterTest.php index 0f87a562..27979fac 100644 --- a/tests/Fields/RepeaterTest.php +++ b/tests/Fields/RepeaterTest.php @@ -15,37 +15,44 @@ use Extended\ACF\Fields\Repeater; use Extended\ACF\Fields\Text; -use PHPUnit\Framework\TestCase; - -class RepeaterTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ButtonLabel; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Fields; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Layout; +use Extended\ACF\Tests\Fields\Settings\MinMax; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class RepeaterTest extends FieldTestCase { - public function testType() - { - $field = Repeater::make('Repeater')->get(); - $this->assertSame('repeater', $field['type']); - } - - public function testButtonLabel() - { - $field = Repeater::make('Repeater Button label')->buttonLabel('Add Item')->get(); - $this->assertSame('Add Item', $field['button_label']); - } + use ButtonLabel; + use ConditionalLogic; + use Fields; + use Instructions; + use Layout; + use MinMax; + use Required; + use Wrapper; + + public string $field = Repeater::class; + public string $type = 'repeater'; public function testCollapsed() { - $field = Repeater::make('Repeater Collapsed') + $field = Repeater::make('Collapsed') ->fields([ Text::make('Title'), ]) ->collapsed('title') ->get(); - $this->assertSame('field_15a7e5e1', $field['collapsed']); + $this->assertSame('field_eedb3216', $field['collapsed']); } public function testPagination() { - $field = Repeater::make('Repeater Pagination')->pagination(10)->get(); + $field = Repeater::make('Pagination')->pagination(10)->get(); $this->assertTrue($field['pagination']); $this->assertSame(10, $field['rows_per_page']); diff --git a/tests/Fields/SelectTest.php b/tests/Fields/SelectTest.php index a1f0f3bb..53d5f6c8 100644 --- a/tests/Fields/SelectTest.php +++ b/tests/Fields/SelectTest.php @@ -14,15 +14,34 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Select; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\Choices; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Multiple; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class SelectTest extends TestCase +class SelectTest extends FieldTestCase { - public function testType() - { - $field = Select::make('Select Type')->get(); - $this->assertSame('select', $field['type']); - } + use Choices; + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use Multiple; + use Nullable; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Select::class; + public string $type = 'select'; public function testStylized() { diff --git a/tests/Fields/Settings/Affixable.php b/tests/Fields/Settings/Affixable.php index e6307ade..118570c5 100644 --- a/tests/Fields/Settings/Affixable.php +++ b/tests/Fields/Settings/Affixable.php @@ -17,13 +17,13 @@ trait Affixable { public function testSuffix() { - $settings = $this->field::make($this->label('Suffix'))->suffix('%')->get(); + $settings = $this->make('Suffix')->suffix('%')->get(); $this->assertSame('%', $settings['append']); } public function testPrefix() { - $settings = $this->field::make($this->label('Prefix'))->prefix('$')->get(); + $settings = $this->make('Prefix')->prefix('$')->get(); $this->assertSame('$', $settings['prepend']); } } diff --git a/tests/Fields/Settings/ButtonLabel.php b/tests/Fields/Settings/ButtonLabel.php new file mode 100644 index 00000000..4545bde3 --- /dev/null +++ b/tests/Fields/Settings/ButtonLabel.php @@ -0,0 +1,23 @@ +make('Button label')->buttonLabel('Add Item')->get(); + $this->assertSame('Add Item', $field['button_label']); + } +} diff --git a/tests/Fields/Settings/Choices.php b/tests/Fields/Settings/Choices.php new file mode 100644 index 00000000..eb6c89fa --- /dev/null +++ b/tests/Fields/Settings/Choices.php @@ -0,0 +1,28 @@ + 'Blue Pill']; + $field = $this->make('Choices')->choices($choices)->get(); + $this->assertSame($choices, $field['choices']); + + $choices = ['Forest Green']; + $field = $this->make('Choices List')->choices($choices)->get(); + $this->assertSame(['forest_green' => 'Forest Green'], $field['choices']); + } +} diff --git a/tests/Fields/Settings/ConditionalLogic.php b/tests/Fields/Settings/ConditionalLogic.php index 7261b298..0f50e43e 100644 --- a/tests/Fields/Settings/ConditionalLogic.php +++ b/tests/Fields/Settings/ConditionalLogic.php @@ -17,7 +17,7 @@ trait ConditionalLogic { public function testConditionalLogicExternalGroup() { - $field = $this->field::make($this->label('Conditional Logic External Group')) + $field = $this->make('Conditional Logic External Group') ->conditionalLogic([ \Extended\ACF\ConditionalLogic::where( group: 'external', @@ -30,7 +30,7 @@ public function testConditionalLogicExternalGroup() public function testConditionalLogicAnd() { - $field = $this->field::make($this->label('Conditional Logic And')) + $field = $this->make('Conditional Logic And') ->conditionalLogic([ \Extended\ACF\ConditionalLogic::where('type', '==', 'video')->and('highlight', '!=', 'true') ])->get('group'); @@ -41,7 +41,7 @@ public function testConditionalLogicAnd() public function testConditionalLogic() { - $field = $this->field::make($this->label('Conditional Logic')) + $field = $this->make('Conditional Logic') ->conditionalLogic([ \Extended\ACF\ConditionalLogic::where('type', '==empty'), ]) diff --git a/tests/Fields/Settings/DateTimeFormat.php b/tests/Fields/Settings/DateTimeFormat.php new file mode 100644 index 00000000..241ea9b4 --- /dev/null +++ b/tests/Fields/Settings/DateTimeFormat.php @@ -0,0 +1,29 @@ +make('Display Format')->displayFormat('ymd')->get(); + $this->assertSame('ymd', $field['display_format']); + } + + public function testReturnFormat() + { + $field = $this->make('Return Format')->returnFormat('ymd')->get(); + $this->assertSame('ymd', $field['return_format']); + } +} diff --git a/tests/Fields/Settings/DefaultValue.php b/tests/Fields/Settings/DefaultValue.php new file mode 100644 index 00000000..8b3d892e --- /dev/null +++ b/tests/Fields/Settings/DefaultValue.php @@ -0,0 +1,23 @@ +make('Default')->default('Chris Coyier')->get(); + $this->assertSame('Chris Coyier', $field['default_value']); + } +} diff --git a/tests/Fields/Settings/Dimensions.php b/tests/Fields/Settings/Dimensions.php new file mode 100644 index 00000000..acded2f3 --- /dev/null +++ b/tests/Fields/Settings/Dimensions.php @@ -0,0 +1,41 @@ +make('Max Height')->maxHeight(20)->get(); + $this->assertSame(20, $field['max_height']); + } + + public function testMinHeight() + { + $field = $this->make('Min Height')->minHeight(10)->get(); + $this->assertSame(10, $field['min_height']); + } + + public function testMaxWidth() + { + $field = $this->make('Max Width')->maxWidth(40)->get(); + $this->assertSame(40, $field['max_width']); + } + + public function testMinWidth() + { + $field = $this->make('Min Width')->minWidth(30)->get(); + $this->assertSame(30, $field['min_width']); + } +} diff --git a/tests/Fields/Settings/DirectionLayout.php b/tests/Fields/Settings/DirectionLayout.php new file mode 100644 index 00000000..9a92f455 --- /dev/null +++ b/tests/Fields/Settings/DirectionLayout.php @@ -0,0 +1,30 @@ +make('Layout')->layout('horizontal')->get(); + $this->assertSame('horizontal', $field['layout']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument layout [test].'); + + $this->make('Invalid Layout')->layout('test'); + } +} diff --git a/tests/Fields/Settings/Disabled.php b/tests/Fields/Settings/Disabled.php new file mode 100644 index 00000000..2d1f8516 --- /dev/null +++ b/tests/Fields/Settings/Disabled.php @@ -0,0 +1,23 @@ +make('Disabled')->disabled()->get(); + $this->assertTrue($field['disabled']); + } +} diff --git a/tests/Fields/Settings/Endpoint.php b/tests/Fields/Settings/Endpoint.php new file mode 100644 index 00000000..4518ae05 --- /dev/null +++ b/tests/Fields/Settings/Endpoint.php @@ -0,0 +1,23 @@ +make('Endpoint')->endpoint()->get(); + $this->assertTrue($field['endpoint']); + } +} diff --git a/tests/Fields/Settings/Fields.php b/tests/Fields/Settings/Fields.php new file mode 100644 index 00000000..6236aaf7 --- /dev/null +++ b/tests/Fields/Settings/Fields.php @@ -0,0 +1,30 @@ +make('Fields') + ->fields([ + Text::make('Title'), + ]) + ->get(); + + $this->assertSame('Title', $field['sub_fields'][0]['label']); + } +} diff --git a/tests/Fields/Settings/FileSize.php b/tests/Fields/Settings/FileSize.php new file mode 100644 index 00000000..85fa9394 --- /dev/null +++ b/tests/Fields/Settings/FileSize.php @@ -0,0 +1,29 @@ +make('Min Size')->minSize('400 KB')->get(); + $this->assertSame('400 KB', $field['min_size']); + } + + public function testMaxSize() + { + $field = $this->make('Max Size')->maxSize(5)->get(); + $this->assertSame(5, $field['max_size']); + } +} diff --git a/tests/Fields/Settings/FileTypes.php b/tests/Fields/Settings/FileTypes.php new file mode 100644 index 00000000..1b921e64 --- /dev/null +++ b/tests/Fields/Settings/FileTypes.php @@ -0,0 +1,23 @@ +make('Accepted File Types')->acceptedFileTypes(['jpg', 'pdf'])->get(); + $this->assertSame('jpg,pdf', $field['mime_types']); + } +} diff --git a/tests/Fields/Settings/FilterBy.php b/tests/Fields/Settings/FilterBy.php new file mode 100644 index 00000000..08c376c9 --- /dev/null +++ b/tests/Fields/Settings/FilterBy.php @@ -0,0 +1,40 @@ +make('Post Status')->postStatus(['publish'])->get(); + $this->assertSame(['publish'], $field['post_status']); + + $this->expectException(InvalidArgumentException::class); + $this->make('Invalid Post Status')->postStatus(['invalid'])->get(); + } + + public function testPostTypes() + { + $field = $this->make('Filter Post Type')->postTypes(['page'])->get(); + $this->assertSame(['page'], $field['post_type']); + } + + public function testTaxonomies() + { + $field = $this->make('Filter Taxonomy')->taxonomies(['category:untitled'])->get(); + $this->assertSame(['category:untitled'], $field['taxonomy']); + } +} diff --git a/tests/Fields/Settings/Height.php b/tests/Fields/Settings/Height.php new file mode 100644 index 00000000..3d7dd089 --- /dev/null +++ b/tests/Fields/Settings/Height.php @@ -0,0 +1,23 @@ +make('Height')->height(100)->get(); + $this->assertSame(100, $field['height']); + } +} diff --git a/tests/Fields/Settings/Immutable.php b/tests/Fields/Settings/Immutable.php index 51e89ae7..f408ac01 100644 --- a/tests/Fields/Settings/Immutable.php +++ b/tests/Fields/Settings/Immutable.php @@ -17,7 +17,7 @@ trait Immutable { public function testReadOnly() { - $field = $this->field::make($this->label('Read Only'))->readOnly()->get(); + $field = $this->make('Read Only')->readOnly()->get(); $this->assertTrue($field['readonly']); } } diff --git a/tests/Fields/Settings/Instructions.php b/tests/Fields/Settings/Instructions.php index cae57b5e..a80367e2 100644 --- a/tests/Fields/Settings/Instructions.php +++ b/tests/Fields/Settings/Instructions.php @@ -17,7 +17,7 @@ trait Instructions { public function testInstructions() { - $field = $this->field::make($this->label('Instructions'))->instructions('text **strong** *italic* __strong__ _italic_ `code` [link](https://advancedcustomfields.com/)')->get(); + $field = $this->make('Instructions')->instructions('text **strong** *italic* __strong__ _italic_ `code` [link](https://advancedcustomfields.com/)')->get(); $this->assertSame('text strong italic strong italic code link', $field['instructions']); } } diff --git a/tests/Fields/Settings/Layout.php b/tests/Fields/Settings/Layout.php new file mode 100644 index 00000000..8fb6e247 --- /dev/null +++ b/tests/Fields/Settings/Layout.php @@ -0,0 +1,30 @@ +make('Layout')->layout('block')->get(); + $this->assertSame('block', $field['layout']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument layout [test].'); + + $this->make('Invalid Layout')->layout('test')->get(); + } +} diff --git a/tests/Fields/Settings/Library.php b/tests/Fields/Settings/Library.php new file mode 100644 index 00000000..b6cfbeff --- /dev/null +++ b/tests/Fields/Settings/Library.php @@ -0,0 +1,30 @@ +make('Library')->library('all')->get(); + $this->assertSame('all', $field['library']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument library [test].'); + + $this->make('Invalid Library')->library('test')->get(); + } +} diff --git a/tests/Fields/Settings/MaxLength.php b/tests/Fields/Settings/MaxLength.php new file mode 100644 index 00000000..ef341f22 --- /dev/null +++ b/tests/Fields/Settings/MaxLength.php @@ -0,0 +1,23 @@ +make('Max Length')->maxLength(100)->get(); + $this->assertSame(100, $field['maxlength']); + } +} diff --git a/tests/Fields/Settings/Message.php b/tests/Fields/Settings/Message.php new file mode 100644 index 00000000..c0ae3b79 --- /dev/null +++ b/tests/Fields/Settings/Message.php @@ -0,0 +1,23 @@ +make('Content')->message('Adam Whatan')->get(); + $this->assertSame('Adam Whatan', $field['message']); + } +} diff --git a/tests/Fields/Settings/MinMax.php b/tests/Fields/Settings/MinMax.php new file mode 100644 index 00000000..e69cf033 --- /dev/null +++ b/tests/Fields/Settings/MinMax.php @@ -0,0 +1,29 @@ +make('Max')->max(10.5)->get(); + $this->assertSame(10.5, $field['max']); + } + + public function testMin() + { + $field = $this->make('Min')->min(5.5)->get(); + $this->assertSame(5.5, $field['min']); + } +} diff --git a/tests/Fields/Settings/Multiple.php b/tests/Fields/Settings/Multiple.php new file mode 100644 index 00000000..c33b9d32 --- /dev/null +++ b/tests/Fields/Settings/Multiple.php @@ -0,0 +1,23 @@ +make('Multiple')->multiple()->get(); + $this->assertTrue($field['multiple']); + } +} diff --git a/tests/Fields/Settings/NewLines.php b/tests/Fields/Settings/NewLines.php new file mode 100644 index 00000000..b41bf03e --- /dev/null +++ b/tests/Fields/Settings/NewLines.php @@ -0,0 +1,30 @@ +make('Description')->newLines('br')->get(); + $this->assertSame('br', $field['new_lines']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument new lines [test].'); + + $this->make('Message')->newLines('test')->get(); + } +} diff --git a/tests/Fields/Settings/Nullable.php b/tests/Fields/Settings/Nullable.php new file mode 100644 index 00000000..c8329539 --- /dev/null +++ b/tests/Fields/Settings/Nullable.php @@ -0,0 +1,23 @@ +make('Nullable')->nullable()->get(); + $this->assertTrue($field['allow_null']); + } +} diff --git a/tests/Fields/Settings/Placeholder.php b/tests/Fields/Settings/Placeholder.php index 05d9e71d..f489ce2e 100644 --- a/tests/Fields/Settings/Placeholder.php +++ b/tests/Fields/Settings/Placeholder.php @@ -17,7 +17,7 @@ trait Placeholder { public function testPlaceholder() { - $field = $this->field::make($this->label('Placeholder'))->placeholder('Jeffrey Way')->get(); + $field = $this->make('Placeholder')->placeholder('Jeffrey Way')->get(); $this->assertSame('Jeffrey Way', $field['placeholder']); } } diff --git a/tests/Fields/Settings/PreviewSize.php b/tests/Fields/Settings/PreviewSize.php new file mode 100644 index 00000000..a4666df1 --- /dev/null +++ b/tests/Fields/Settings/PreviewSize.php @@ -0,0 +1,23 @@ +make('Preview Size')->previewSize('large')->get(); + $this->assertSame('large', $field['preview_size']); + } +} diff --git a/tests/Fields/Settings/Required.php b/tests/Fields/Settings/Required.php index 20e9c4f2..89e86dab 100644 --- a/tests/Fields/Settings/Required.php +++ b/tests/Fields/Settings/Required.php @@ -17,7 +17,7 @@ trait Required { public function testRequired() { - $settings = $this->field::make($this->label('Required'))->required()->get(); + $settings = $this->make('Required')->required()->get(); $this->assertTrue($settings['required']); } } diff --git a/tests/Fields/Settings/ReturnFormat.php b/tests/Fields/Settings/ReturnFormat.php new file mode 100644 index 00000000..dd307a46 --- /dev/null +++ b/tests/Fields/Settings/ReturnFormat.php @@ -0,0 +1,30 @@ +make('Return Format')->returnFormat('array')->get(); + $this->assertSame('array', $field['return_format']); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid argument return format [test].'); + + $this->make('Invalid Return Format')->returnFormat('test')->get(); + } +} diff --git a/tests/Fields/Settings/Step.php b/tests/Fields/Settings/Step.php new file mode 100644 index 00000000..71ede479 --- /dev/null +++ b/tests/Fields/Settings/Step.php @@ -0,0 +1,23 @@ +make('Step')->step(5.2)->get(); + $this->assertSame(5.2, $field['step']); + } +} diff --git a/tests/Fields/Settings/WeekDay.php b/tests/Fields/Settings/WeekDay.php new file mode 100644 index 00000000..8a4c1b3e --- /dev/null +++ b/tests/Fields/Settings/WeekDay.php @@ -0,0 +1,23 @@ +make('First Day Of Week')->firstDayOfWeek(1)->get(); + $this->assertSame(1, $field['first_day']); + } +} diff --git a/tests/Fields/Settings/Wrapper.php b/tests/Fields/Settings/Wrapper.php index b1a49fca..93e57e13 100644 --- a/tests/Fields/Settings/Wrapper.php +++ b/tests/Fields/Settings/Wrapper.php @@ -17,22 +17,22 @@ trait Wrapper { public function testWrapper() { - $field = $this->field::make($this->label('Status'))->wrapper(['id' => 'status'])->get(); + $field = $this->make('Status')->wrapper(['id' => 'status'])->get(); $this->assertSame(['id' => 'status'], $field['wrapper']); } public function testColumn() { - $field = $this->field::make($this->label('Column 60'))->column(60)->get(); + $field = $this->make('Column 60')->column(60)->get(); $this->assertSame(60, $field['wrapper']['width']); - $field = $this->field::make($this->label('Column 70'))->wrapper(['width' => 50])->column(70)->get(); + $field = $this->make('Column 70')->wrapper(['width' => 50])->column(70)->get(); $this->assertSame(70, $field['wrapper']['width']); - $field = $this->field::make($this->label('Column 80'))->column(50)->wrapper(['width' => 80])->get(); + $field = $this->make('Column 80')->column(50)->wrapper(['width' => 80])->get(); $this->assertSame(80, $field['wrapper']['width']); - $field = $this->field::make($this->label('Column 90'))->column(90)->wrapper(['class' => 'column'])->get(); + $field = $this->make('Column 90')->column(90)->wrapper(['class' => 'column'])->get(); $this->assertSame(90, $field['wrapper']['width']); } } diff --git a/tests/Fields/TabTest.php b/tests/Fields/TabTest.php index faf2fe39..23210e7a 100644 --- a/tests/Fields/TabTest.php +++ b/tests/Fields/TabTest.php @@ -14,25 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Tab; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Endpoint; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -class TabTest extends TestCase +class TabTest extends FieldTestCase { - public function testType() - { - $field = Tab::make('Tab')->get(); - $this->assertSame('tab', $field['type']); - } + use ConditionalLogic; + use Endpoint; + + public string $field = Tab::class; + public string $type = 'tab'; public function testPlacement() { - $field = Tab::make('Tab Placement')->placement('top')->get(); + $field = Tab::make('Placement')->placement('top')->get(); $this->assertSame('top', $field['placement']); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid argument placement [test].'); - Tab::make('Invalid Tab Placement')->placement('test')->get(); + Tab::make('Invalid Placement')->placement('test')->get(); } } diff --git a/tests/Fields/TaxonomyTest.php b/tests/Fields/TaxonomyTest.php index 53a2d060..39d90b5d 100644 --- a/tests/Fields/TaxonomyTest.php +++ b/tests/Fields/TaxonomyTest.php @@ -14,49 +14,58 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Taxonomy; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -class TaxonomyTest extends TestCase +class TaxonomyTest extends FieldTestCase { - public function testType() - { - $field = Taxonomy::make('Taxonomy')->get(); - $this->assertSame('taxonomy', $field['type']); - } + use ConditionalLogic; + use Instructions; + use Nullable; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = Taxonomy::class; + public string $type = 'taxonomy'; public function testAppearance() { - $field = Taxonomy::make('Taxonomy Appearance')->appearance('checkbox')->get(); + $field = Taxonomy::make('Appearance')->appearance('checkbox')->get(); $this->assertSame('checkbox', $field['field_type']); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid argument field type [test].'); - Taxonomy::make('Invalid Taxonomy Appearance')->appearance('test')->get(); + Taxonomy::make('Invalid Appearance')->appearance('test')->get(); } public function testCanAddTerm() { - $field = Taxonomy::make('Taxonomy Add Term')->addTerm(false)->get(); + $field = Taxonomy::make('Add Term')->addTerm(false)->get(); $this->assertFalse($field['add_term']); } public function testLoadTerms() { - $field = Taxonomy::make('Taxonomy Load Terms')->loadTerms(false)->get(); + $field = Taxonomy::make('Load Terms')->loadTerms(false)->get(); $this->assertFalse($field['load_terms']); } public function testShouldSaveTerms() { - $field = Taxonomy::make('Taxonomy Save Terms')->saveTerms(false)->get(); + $field = Taxonomy::make('Save Terms')->saveTerms(false)->get(); $this->assertFalse($field['save_terms']); } public function testTaxonomy() { - $field = Taxonomy::make('Taxonomy Taxonomy')->taxonomy('category')->get(); + $field = Taxonomy::make('Taxonomy')->taxonomy('category')->get(); $this->assertSame('category', $field['taxonomy']); } } diff --git a/tests/Fields/TextTest.php b/tests/Fields/TextTest.php index 4bb76155..f88f8103 100644 --- a/tests/Fields/TextTest.php +++ b/tests/Fields/TextTest.php @@ -14,31 +14,30 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Text; -use Symfony\Component\VarDumper\VarDumper; +use Extended\ACF\Tests\Fields\Settings\Affixable; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MaxLength; +use Extended\ACF\Tests\Fields\Settings\Placeholder; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; class TextTest extends FieldTestCase { + use Affixable; + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use MaxLength; + use Placeholder; + use Required; + use Wrapper; + public string $field = Text::class; public string $type = 'text'; - - public function testDisabled() - { - $field = Text::make('Text Disabled')->disabled()->get(); - $this->assertTrue($field['disabled']); - } - - public function testDump() - { - $log = []; - - VarDumper::setHandler(function ($value) use (&$log) { - $log[] = $value; - }); - - Text::make('Dump')->dump(1, 2); - - $this->assertSame([['label' => 'Dump', 'name' => 'dump', 'type' => 'text', 'key' => 'field_076f7d8c'], 1, 2], $log); - - VarDumper::setHandler(null); - } } diff --git a/tests/Fields/TextareaTest.php b/tests/Fields/TextareaTest.php index 7ed7e9d3..16cdbd90 100644 --- a/tests/Fields/TextareaTest.php +++ b/tests/Fields/TextareaTest.php @@ -14,33 +14,32 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\Textarea; -use InvalidArgumentException; -use PHPUnit\Framework\TestCase; - -class TextareaTest extends TestCase +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\MaxLength; +use Extended\ACF\Tests\Fields\Settings\NewLines; +use Extended\ACF\Tests\Fields\Settings\Placeholder; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; + +class TextareaTest extends FieldTestCase { - public function testType() - { - $field = Textarea::make('Textarea')->get(); - $this->assertSame('textarea', $field['type']); - } - - public function testMaxLength() - { - $field = Textarea::make('Max Length')->maxLength(100)->get(); - $this->assertSame(100, $field['maxlength']); - } - - public function testNewLines() - { - $field = Textarea::make('Description')->newLines('br')->get(); - $this->assertSame('br', $field['new_lines']); - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid argument new lines [test].'); - - Textarea::make('Message')->newLines('test')->get(); - } + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use MaxLength; + use NewLines; + use Placeholder; + use Required; + use Wrapper; + + public string $field = Textarea::class; + public string $type = 'textarea'; public function testRows() { diff --git a/tests/Fields/TimePickerTest.php b/tests/Fields/TimePickerTest.php index 3f377854..3af1eee4 100644 --- a/tests/Fields/TimePickerTest.php +++ b/tests/Fields/TimePickerTest.php @@ -14,13 +14,24 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\TimePicker; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DateTimeFormat; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class TimePickerTest extends TestCase +class TimePickerTest extends FieldTestCase { - public function testType() - { - $field = TimePicker::make('Time Picker')->get(); - $this->assertSame('time_picker', $field['type']); - } + use ConditionalLogic; + use DateTimeFormat; + use Disabled; + use Immutable; + use Instructions; + use Required; + use Wrapper; + + public string $field = TimePicker::class; + public string $type = 'time_picker'; } diff --git a/tests/Fields/TrueFalseTest.php b/tests/Fields/TrueFalseTest.php index ee7ddb75..b021c87d 100644 --- a/tests/Fields/TrueFalseTest.php +++ b/tests/Fields/TrueFalseTest.php @@ -14,19 +14,28 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\TrueFalse; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Message; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class TrueFalseTest extends TestCase +class TrueFalseTest extends FieldTestCase { - public function testType() - { - $field = TrueFalse::make('True False')->get(); - $this->assertSame('true_false', $field['type']); - } + use ConditionalLogic; + use DefaultValue; + use Instructions; + use Message; + use Required; + use Wrapper; + + public string $field = TrueFalse::class; + public string $type = 'true_false'; public function testStylized() { - $field = TrueFalse::make('UI')->stylized(off: 'Wax off')->get(); + $field = TrueFalse::make('Stylized')->stylized(off: 'Wax off')->get(); $this->assertTrue($field['ui']); $this->assertArrayNotHasKey('ui_on_text', $field); $this->assertEquals($field['ui_off_text'], 'Wax off'); diff --git a/tests/Fields/URLTest.php b/tests/Fields/URLTest.php index 69b3f603..7ae9fbd9 100644 --- a/tests/Fields/URLTest.php +++ b/tests/Fields/URLTest.php @@ -14,19 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\URL; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Disabled; +use Extended\ACF\Tests\Fields\Settings\Immutable; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Placeholder; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class URLTest extends TestCase +class URLTest extends FieldTestCase { - public function testType() - { - $field = URL::make('URL')->get(); - $this->assertSame('url', $field['type']); - } + use ConditionalLogic; + use DefaultValue; + use Disabled; + use Immutable; + use Instructions; + use Placeholder; + use Required; + use Wrapper; - public function testDefault() - { - $field = URL::make('Default')->default('hotpink')->get(); - $this->assertSame('hotpink', $field['default_value']); - } + public string $field = URL::class; + public string $type = 'url'; } diff --git a/tests/Fields/UserTest.php b/tests/Fields/UserTest.php index b94cb746..5405969c 100644 --- a/tests/Fields/UserTest.php +++ b/tests/Fields/UserTest.php @@ -14,15 +14,26 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\User; -use PHPUnit\Framework\TestCase; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Multiple; +use Extended\ACF\Tests\Fields\Settings\Nullable; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\ReturnFormat; +use Extended\ACF\Tests\Fields\Settings\Wrapper; -class UserTest extends TestCase +class UserTest extends FieldTestCase { - public function testType() - { - $field = User::make('User')->get(); - $this->assertSame('user', $field['type']); - } + use ConditionalLogic; + use Instructions; + use Multiple; + use Nullable; + use Required; + use ReturnFormat; + use Wrapper; + + public string $field = User::class; + public string $type = 'user'; public function testRoles() { diff --git a/tests/Fields/WysiwygEditorTest.php b/tests/Fields/WysiwygEditorTest.php index 2d5e9962..170ba9c1 100644 --- a/tests/Fields/WysiwygEditorTest.php +++ b/tests/Fields/WysiwygEditorTest.php @@ -14,46 +14,53 @@ namespace Extended\ACF\Tests\Fields; use Extended\ACF\Fields\WysiwygEditor; +use Extended\ACF\Tests\Fields\Settings\ConditionalLogic; +use Extended\ACF\Tests\Fields\Settings\DefaultValue; +use Extended\ACF\Tests\Fields\Settings\Instructions; +use Extended\ACF\Tests\Fields\Settings\Required; +use Extended\ACF\Tests\Fields\Settings\Wrapper; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -class WysiwygEditorTest extends TestCase +class WysiwygEditorTest extends FieldTestCase { - public function testType() + use ConditionalLogic; + use DefaultValue; + use Instructions; + use Required; + use Wrapper; + + public string $field = WysiwygEditor::class; + public string $type = 'wysiwyg'; + + public function testDisableMediaUpload() { - $field = WysiwygEditor::make('Wysiwyg Editor')->get(); - $this->assertSame('wysiwyg', $field['type']); + $field = WysiwygEditor::make('Media Upload')->disableMediaUpload()->get(); + $this->assertFalse($field['media_upload']); } public function testLazyLoad() { - $field = WysiwygEditor::make('Wysiwyg Editor Lazy Load')->lazyLoad()->get(); + $field = WysiwygEditor::make('Lazy Load')->lazyLoad()->get(); $this->assertTrue($field['delay']); } - public function testDisableMediaUpload() - { - $field = WysiwygEditor::make('Wysiwyg Editor Media Upload')->disableMediaUpload()->get(); - $this->assertFalse($field['media_upload']); - } - public function testTabs() { - $field = WysiwygEditor::make('Wysiwyg Editor Tabs')->tabs('visual')->get(); + $field = WysiwygEditor::make('Tabs')->tabs('visual')->get(); $this->assertSame('visual', $field['tabs']); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid argument tabs [test].'); - $field = WysiwygEditor::make('Wysiwyg Editor Invalid Tabs')->tabs('test')->get(); + $field = WysiwygEditor::make('Invalid Tabs')->tabs('test')->get(); } public function testToolbar() { - $field = WysiwygEditor::make('Wysiwyg Editor Toolbar')->toolbar('basic')->get(); + $field = WysiwygEditor::make('Toolbar')->toolbar('basic')->get(); $this->assertSame('basic', $field['toolbar']); - $field = WysiwygEditor::make('Wysiwyg Editor Toolbar Array')->toolbar(['bold', 'italic'])->get(); + $field = WysiwygEditor::make('Toolbar Array')->toolbar(['bold', 'italic'])->get(); $this->assertSame('bold_italic', $field['toolbar']); } }