Skip to content

Commit

Permalink
Added tests for better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Hopkins committed Aug 7, 2018
1 parent aba1c1d commit bd1b28c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"require": {
"php": "^7.0",
"rareloop/lumberjack-core": "^3.2.0"
},
"require-dev": {
Expand Down
4 changes: 3 additions & 1 deletion src/AcfFields/CheckboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use IceAgency\Lumberjack\AcfFields\Field;

use Exception;

class CheckboxField extends Field
{
public $type = 'checkbox';

public $options = [];

public function withOptions($options)
public function withOptions($options = '')
{
if (!is_array($options)) {
throw new Exception('You must provide an array of options with a CheckboxField');
Expand Down
4 changes: 3 additions & 1 deletion src/AcfFields/RadioField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use IceAgency\Lumberjack\AcfFields\Field;

use Exception;

class RadioField extends Field
{
public $type = 'radio';

public $options = [];

public function withOptions($options)
public function withOptions($options = '')
{
if (!is_array($options)) {
throw new Exception('You must provide an array of options with a RadioField');
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/AcfFieldGroups/FieldGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public function testCreateFieldGroup()
]);
}

public function testCreateFieldGroupWithoutName()
{
$post_type_name = '';
$this->expectException(Exception::class);
$field_group = FieldGroup::create($post_type_name);

$this->assertNull($field_group);
}

public function testAddField()
{
$post_type_name = 'post';
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/AcfFields/CheckboxFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPUnit\Framework\TestCase;

use Exception;

use IceAgency\Lumberjack\AcfFields\CheckboxField;

class CheckboxFieldTest extends TestCase
Expand All @@ -24,6 +26,17 @@ public function testOptions()
]);
}

public function testEmptyOptions()
{
$field_name = 'example_field';
$field = CheckboxField::create($field_name);

$this->expectException(Exception::class);
$field->withOptions();

$this->assertNull($field->options);
}

public function testOptionalData()
{
$field_name = 'example_field';
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/AcfFields/RadioFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use IceAgency\Lumberjack\AcfFields\RadioField;

use Exception;

class RadioFieldTest extends TestCase
{
public function testOptions()
Expand All @@ -24,6 +26,17 @@ public function testOptions()
]);
}

public function testEmptyOptions()
{
$field_name = 'example_field';
$field = RadioField::create($field_name);

$this->expectException(Exception::class);
$field->withOptions();

$this->assertNull($field->options);
}

public function testOptionalData()
{
$field_name = 'example_field';
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/AcfFields/WysiwygFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPUnit\Framework\TestCase;

use Exception;

use IceAgency\Lumberjack\AcfFields\WysiwygField;

class WysiwygFieldTest extends TestCase
Expand All @@ -26,6 +28,16 @@ public function testTabs()
$this->assertEquals($field->tabs, 'text');
}

public function testInvalidTabs()
{
$field_name = 'example_field';
$field = WysiwygField::create($field_name);

$this->expectException(Exception::class);
$field->withTabs('other');
$this->assertNull($field->tabs);
}

public function testToolbar()
{
$field_name = 'example_field';
Expand All @@ -40,6 +52,16 @@ public function testToolbar()
$this->assertEquals($field->toolbar, 'basic');
}

public function testInvalidToolbar()
{
$field_name = 'example_field';
$field = WysiwygField::create($field_name);

$this->expectException(Exception::class);
$field->withToolbar('other');
$this->assertNull($field->toolbar);
}

public function testCanUploadMedia()
{
$field_name = 'example_field';
Expand Down

0 comments on commit bd1b28c

Please sign in to comment.