diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MetaboxFieldTest.php | 53 | ||||
-rw-r--r-- | tests/MetaboxTest.php | 65 |
2 files changed, 118 insertions, 0 deletions
diff --git a/tests/MetaboxFieldTest.php b/tests/MetaboxFieldTest.php new file mode 100644 index 0000000..6d7ede7 --- /dev/null +++ b/tests/MetaboxFieldTest.php @@ -0,0 +1,53 @@ +<?php + +use PHPUnit\Framework\TestCase; +use PostTypes\MetaboxField; + +class MetaboxFieldTest extends TestCase +{ + /** + * @var MetaboxField + */ + public $field; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->field = new MetaboxField('test_field'); + } + + /** + * @test + */ + public function hasFieldKeyOnInstantiation() + { + $this->assertEquals('field_test_field', $this->field->key); + } + + /** + * @test + */ + public function hasNamesOnInstantiation() + { + $expectedNames = [ + 'label' => 'Test Field', + 'name' => 'test_field', + ]; + + $this->assertEquals($expectedNames, $this->field->names); + } + + /** + * @test + */ + public function adjustsParentGroupKey() + { + $this->field->parent('metabox_test'); + $this->assertEquals('group_metabox_test', $this->field->parent); + + $this->field->parent('group_metabox_test'); + $this->assertEquals('group_metabox_test', $this->field->parent); + } +} diff --git a/tests/MetaboxTest.php b/tests/MetaboxTest.php new file mode 100644 index 0000000..d5a27a3 --- /dev/null +++ b/tests/MetaboxTest.php @@ -0,0 +1,65 @@ +<?php + +use PHPUnit\Framework\TestCase; +use PostTypes\Metabox; +use PostTypes\MetaboxField; + +class MetaboxTest extends TestCase +{ + /** + * @var Metabox + */ + public $metabox; + + /** + * @var MetaboxField + */ + public $field; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->metabox = new Metabox('Test Metabox'); + $this->field = new MetaboxField('Test Field'); + } + + /** + * @test + */ + public function hasGroupKeyOnInstantiation() + { + $this->assertEquals('group_test_metabox', $this->metabox->key); + } + + /** + * @test + */ + public function assignsPostTypeOnce() + { + $this->metabox->posttype(['post', 'page']); + + $expectedPostTypes = [ + 'post' => 'post', + 'page' => 'page', + ]; + + $this->assertEquals($expectedPostTypes, $this->metabox->posttypes); + + $this->metabox->posttype('post'); + + $this->assertEquals($expectedPostTypes, $this->metabox->posttypes); + } + + /** + * @test + */ + public function modifiesAndHoldsPassedField() + { + $this->metabox->field($this->field); + + $this->assertEquals($this->field->parent, $this->metabox->key); + $this->assertEquals($this->metabox->fields[$this->field->key], $this->field); + } +} |