| 1 |
<?php |
| 2 |
|
| 3 |
use PHPUnit\Framework\TestCase; |
| 4 |
|
| 5 |
class OptionFactoryTest extends TestCase { |
| 6 |
|
| 7 |
public static function setUpBeforeClass() { |
| 8 |
if(!function_exists('stripslashes_deep')): |
| 9 |
function stripslashes_deep($a) { |
| 10 |
return $a; |
| 11 |
} |
| 12 |
endif; |
| 13 |
} |
| 14 |
|
| 15 |
public function setUp() { |
| 16 |
$defaults = ['a' => 1, 'b' => 2, 'c' => 3]; |
| 17 |
$helpers = ['a' => ['filter' => 'ResponsiveMenu\Filters\HtmlFilter'], 'c' => ['filter' => 'ResponsiveMenu\Filters\JsonFilter']]; |
| 18 |
$this->factory = new ResponsiveMenu\Factories\OptionFactory($defaults, $helpers); |
| 19 |
} |
| 20 |
|
| 21 |
public function testSetFilterIsReturned() { |
| 22 |
$option = $this->factory->build('a', 4); |
| 23 |
$this->assertInstanceOf('ResponsiveMenu\Filters\HtmlFilter', $option->getFilter()); |
| 24 |
} |
| 25 |
|
| 26 |
public function testDefaultFilterIsReturned() { |
| 27 |
$option = $this->factory->build('b', 4); |
| 28 |
$this->assertInstanceOf('ResponsiveMenu\Filters\TextFilter', $option->getFilter()); |
| 29 |
} |
| 30 |
|
| 31 |
public function testOptionIsReturned() { |
| 32 |
$option = $this->factory->build('b', 4); |
| 33 |
$this->assertInstanceOf('ResponsiveMenu\Models\Option', $option); |
| 34 |
} |
| 35 |
|
| 36 |
public function testDefaultIsReturnedIfValueIsNull() { |
| 37 |
$option = $this->factory->build('b', null); |
| 38 |
$this->assertEquals(2, $option->getValue()); |
| 39 |
} |
| 40 |
|
| 41 |
public function testZeroIsReturnedAndNotDefault() { |
| 42 |
$option = $this->factory->build('b', 0); |
| 43 |
$this->assertEquals(0, $option->getValue()); |
| 44 |
} |
| 45 |
|
| 46 |
public function testUpdatedValueIsReturned() { |
| 47 |
$option = $this->factory->build('a', 'updated'); |
| 48 |
$this->assertEquals('updated', $option->getValue()); |
| 49 |
} |
| 50 |
|
| 51 |
public function testDecodingArrayData() { |
| 52 |
$option = $this->factory->build('a', ['a' => 1, 'b' => ['a' => 1, 'b' => 2]]); |
| 53 |
$this->assertEquals(['a' => 1, 'b' => ['a' => 1, 'b' => 2]], $option->getValue()); |
| 54 |
} |
| 55 |
|
| 56 |
public function testDecodedOfJsonDataToArray() { |
| 57 |
$option = $this->factory->build('c', '{"a":"1","b":"2"}'); |
| 58 |
$this->assertEquals('{"a":"1","b":"2"}', $option->getValue()); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|