PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.0.12
Responsive Menu – Create Mobile-Friendly Menu v3.0.12
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / tests / app / Repositories / OptionRepositoryTest.php

OptionRepositoryTest.php in Responsive Menu – Create Mobile-Friendly Menu 3.0.12, at tests/app/Repositories/OptionRepositoryTest.php

88 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use PHPUnit\Framework\TestCase;
4
5 class OptionRepositoryTest extends TestCase {
6
7 public function setUp() {
8 $this->db = $this->createMock('ResponsiveMenu\Database\WpDatabase');
9 $this->factory = $this->createMock('ResponsiveMenu\Factories\OptionFactory');
10 $this->defaults = ['a' => 1, 'b' => 2, 'c' => 3];
11
12 $this->repo = new ResponsiveMenu\Repositories\OptionRepository($this->db, $this->factory, $this->defaults);
13 }
14
15 public function testCollectionReturned() {
16 $obj_1 = new \StdClass;
17 $obj_1->name = 'a';
18 $obj_1->value = 1;
19
20 $obj_2 = new \StdClass;
21 $obj_2->name = 'b';
22 $obj_2->value = 2;
23
24 $this->db->method('all')->willReturn([$obj_1, $obj_2]);
25
26 $this->factory->method('build')->will($this->onConsecutiveCalls(
27 new ResponsiveMenu\Models\Option('a', 1),
28 new ResponsiveMenu\Models\Option('b', 2)
29 ));
30
31 $this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $this->repo->all());
32 }
33
34 public function testCollectionCountIsReturned() {
35 $obj_1 = new \StdClass;
36 $obj_1->name = 'a';
37 $obj_1->value = 1;
38
39 $obj_2 = new \StdClass;
40 $obj_2->name = 'b';
41 $obj_2->value = 2;
42
43 $this->db->method('all')->willReturn([$obj_1, $obj_2]);
44
45 $this->factory->method('build')->will($this->onConsecutiveCalls(
46 new ResponsiveMenu\Models\Option('a', 1),
47 new ResponsiveMenu\Models\Option('b', 2)
48 ));
49
50 $this->assertEquals(2, count($this->repo->all()->all()));
51 }
52
53 public function testDbUpdateIsCalled() {
54 $option = $this->createMock('ResponsiveMenu\Models\Option');
55 $option->method('getFiltered')->willReturn(1);
56 $option->method('getName')->willReturn('a');
57 $this->db->method('update')->willReturn(true);
58 $this->assertTrue($this->repo->update($option));
59 }
60
61 public function testDbCreateIsCalled() {
62 $option = $this->createMock('ResponsiveMenu\Models\Option');
63 $option->method('getFiltered')->willReturn(1);
64 $option->method('getName')->willReturn('a');
65 $this->db->method('insert')->willReturn(true);
66 $this->db->method('mySqlTime')->willReturn('123');
67 $this->assertTrue($this->repo->create($option));
68 }
69
70 public function testDbRemoveIsCalled() {
71 $this->db->method('delete')->willReturn(true);
72 $this->assertTrue($this->repo->remove('a'));
73 }
74
75 public function testBuildFromArray() {
76 $opt_1 = new ResponsiveMenu\Models\Option('a', 4);
77 $opt_1->setFilter($this->createMock('ResponsiveMenu\Filters\TextFilter'));
78
79 $opt_2 = new ResponsiveMenu\Models\Option('d', 6);
80 $opt_2->setFilter($this->createMock('ResponsiveMenu\Filters\TextFilter'));
81
82 $this->factory->method('build')->will($this->onConsecutiveCalls($opt_1, $opt_2, $opt_1, $opt_2));
83
84 $this->assertInstanceOf('ResponsiveMenu\Collections\OptionsCollection', $this->repo->buildFromArray(['a' => 4, 'd' => 6]));
85 }
86
87 }
88