| 1 |
<?php |
| 2 |
|
| 3 |
use PHPUnit\Framework\TestCase; |
| 4 |
use ResponsiveMenu\Services\OptionService; |
| 5 |
|
| 6 |
class OptionsServiceTest extends TestCase { |
| 7 |
|
| 8 |
public function setUp() { |
| 9 |
$this->repository = $this->createMock('ResponsiveMenu\Repositories\OptionRepository'); |
| 10 |
$this->factory = $this->createMock('ResponsiveMenu\Factories\OptionFactory'); |
| 11 |
$this->translator = $this->createMock('ResponsiveMenu\Translation\Translator'); |
| 12 |
$this->scripts_builder = $this->createMock('ResponsiveMenu\Filesystem\ScriptsBuilder'); |
| 13 |
|
| 14 |
$this->service = new OptionService($this->repository, $this->factory, $this->translator, $this->scripts_builder); |
| 15 |
} |
| 16 |
|
| 17 |
public function testCombiningBasicOptions() { |
| 18 |
$this->assertSame(['one' => 1, 'two' => 'two'], $this->service->combineOptions(['one' => 1],['two' => 'two'])); |
| 19 |
} |
| 20 |
|
| 21 |
public function testCombiningStringZeroOptions() { |
| 22 |
$this->assertSame(['one' => '0'], $this->service->combineOptions(['one' => 'default'],['one' => '0'])); |
| 23 |
} |
| 24 |
|
| 25 |
public function testCombiningIntegerZeroOptions() { |
| 26 |
$this->assertSame(['one' => 0], $this->service->combineOptions(['one' => 'default'],['one' => 0])); |
| 27 |
} |
| 28 |
|
| 29 |
public function testOverwritingDefaultOptionValue() { |
| 30 |
$this->assertSame(['one' => 'updated'], $this->service->combineOptions(['one' => 'default'],['one' => 'updated'])); |
| 31 |
} |
| 32 |
|
| 33 |
public function testRepositoryReturn() { |
| 34 |
$this->repository->method('all')->willReturn('a'); |
| 35 |
$this->assertEquals('a', $this->service->all()); |
| 36 |
} |
| 37 |
|
| 38 |
public function testBuildPostArray() { |
| 39 |
$this->repository->method('buildFromArray')->willReturn('a'); |
| 40 |
$this->assertEquals('a', $this->service->buildFromPostArray([])); |
| 41 |
} |
| 42 |
|
| 43 |
public function testUpdateOptions() { |
| 44 |
$this->repository->method('all')->willReturn(new ResponsiveMenu\Collections\OptionsCollection); |
| 45 |
$this->repository->method('update')->willReturn('a'); |
| 46 |
$this->factory->method('build')->willReturn(new ResponsiveMenu\Models\Option('a', 1)); |
| 47 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $this->service->updateOptions(['a' => 1])); |
| 48 |
} |
| 49 |
|
| 50 |
public function testCreateOptions() { |
| 51 |
$collection = new ResponsiveMenu\Collections\OptionsCollection; |
| 52 |
$collection->add(new ResponsiveMenu\Models\Option('external_files', 'on')); |
| 53 |
$this->repository->method('all')->willReturn($collection); |
| 54 |
$this->repository->method('create')->willReturn('a'); |
| 55 |
$this->factory->method('build')->willReturn(new ResponsiveMenu\Models\Option('a', 1)); |
| 56 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $this->service->createOptions(['a' => 1])); |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|