| 1 |
<?php |
| 2 |
|
| 3 |
use PHPUnit\Framework\TestCase; |
| 4 |
use ResponsiveMenu\Management\OptionManager; |
| 5 |
use ResponsiveMenu\Collections\OptionsCollection; |
| 6 |
|
| 7 |
class OptionManagerTest extends TestCase { |
| 8 |
|
| 9 |
private $db; |
| 10 |
private $default_options = [ |
| 11 |
'foo' => 'bar', |
| 12 |
'baz' => 'qux' |
| 13 |
]; |
| 14 |
|
| 15 |
public function setUp() { |
| 16 |
$this->db = $this->createMock('ResponsiveMenu\Database\Database'); |
| 17 |
} |
| 18 |
|
| 19 |
public function testUpdateOptionsReturnsCorrectly() { |
| 20 |
$manager = new OptionManager($this->db, $this->default_options); |
| 21 |
$to_update = ['foo' => 'new', 'moon' => 'rise']; |
| 22 |
|
| 23 |
$updated = $manager->updateOptions($to_update); |
| 24 |
|
| 25 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $updated); |
| 26 |
|
| 27 |
$expected = new OptionsCollection([ |
| 28 |
'foo' => 'new', |
| 29 |
'baz' => 'qux', |
| 30 |
'moon' => 'rise' |
| 31 |
]); |
| 32 |
|
| 33 |
$this->assertEquals($expected, $updated); |
| 34 |
} |
| 35 |
|
| 36 |
public function testCreateOptionsReturnsCorrectly() { |
| 37 |
$manager = new OptionManager($this->db, $this->default_options); |
| 38 |
$to_create = ['moon' => 'rise']; |
| 39 |
|
| 40 |
$updated = $manager->createOptions($to_create); |
| 41 |
|
| 42 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $updated); |
| 43 |
|
| 44 |
$expected = new OptionsCollection([ |
| 45 |
'foo' => 'bar', |
| 46 |
'baz' => 'qux', |
| 47 |
'moon' => 'rise' |
| 48 |
]); |
| 49 |
|
| 50 |
$this->assertEquals($expected, $updated); |
| 51 |
} |
| 52 |
|
| 53 |
public function testRemoveOptionsReturnsCorrectly() { |
| 54 |
$manager = new OptionManager($this->db, $this->default_options); |
| 55 |
$to_remove = ['foo' => 'new', 'moon' => 'rise']; |
| 56 |
|
| 57 |
$updated = $manager->removeOptions($to_remove); |
| 58 |
|
| 59 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $updated); |
| 60 |
|
| 61 |
$expected = new OptionsCollection([ |
| 62 |
'baz' => 'qux' |
| 63 |
]); |
| 64 |
|
| 65 |
$this->assertEquals($expected, $updated); |
| 66 |
} |
| 67 |
|
| 68 |
public function testBuildFromArrayReturnsCorrectly() { |
| 69 |
$manager = new OptionManager($this->db, $this->default_options); |
| 70 |
$to_remove = ['foo' => 'new', 'moon' => 'rise']; |
| 71 |
|
| 72 |
$updated = $manager->buildFromArray($to_remove); |
| 73 |
|
| 74 |
$this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $updated); |
| 75 |
|
| 76 |
$expected = new OptionsCollection([ |
| 77 |
'foo' => 'new', |
| 78 |
'baz' => 'qux', |
| 79 |
'moon' => 'rise' |
| 80 |
]); |
| 81 |
|
| 82 |
$this->assertEquals($expected, $updated); |
| 83 |
} |
| 84 |
|
| 85 |
} |