Completed
Push — master ( a2c5ce...b3c15f )
by Ruud
328:10 queued 318:03
created

Tests/unit/AdminList/AdminListTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\AdminList;
4
5
use Kunstmaan\AdminListBundle\AdminList\AdminList;
6
use Kunstmaan\AdminListBundle\AdminList\BulkAction\BulkActionInterface;
7
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
8
use Kunstmaan\AdminListBundle\AdminList\FilterBuilder;
9
use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface;
10
use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface;
11
use Pagerfanta\Pagerfanta;
12
use PHPUnit\Framework\TestCase;
13
14
/**
15
 * Class AdminListTest
16
 */
17
class AdminListTest extends TestCase
18
{
19
    /** @var AdminList */
20
    protected $adminList;
21
22
    public function setUp()
23
    {
24
        /** @var AdminListConfiguratorInterface */
25
        $configurator = $this->createMock(AdminListConfiguratorInterface::class);
26
27
        $configurator->method('getFilterBuilder')->willReturn(new FilterBuilder());
28
        $configurator->method('getFields')->willReturn(['a', 'b']);
29
        $configurator->method('getExportFields')->willReturn(['c', 'd']);
30
        $configurator->method('getCount')->willReturn('666');
31
        $configurator->method('getItems')->willReturn(['item']);
32
        $configurator->method('getSortFields')->willReturn(['e', 'f']);
33
        $configurator->method('canEdit')->willReturn(true);
34
        $configurator->method('canAdd')->willReturn(true);
35
        $configurator->method('canView')->willReturn(true);
36
        $configurator->method('canDelete')->willReturn(true);
37
        $configurator->method('canExport')->willReturn(true);
38
        $configurator->method('getIndexUrl')->willReturn([]);
39
        $configurator->method('getEditUrlFor')->willReturn([]);
40
        $configurator->method('getDeleteUrlFor')->willReturn([]);
41
        $configurator->method('getAddUrlFor')->willReturn([]);
42
        $configurator->method('getExportUrl')->willReturn([]);
43
        $configurator->method('getViewUrlFor')->willReturn([]);
44
        $configurator->method('getValue')->willReturn('test');
45
        $configurator->method('getStringValue')->willReturn('stringtest');
46
        $configurator->method('getOrderBy')->willReturn('name');
47
        $configurator->method('getOrderDirection')->willReturn('up');
48
        $configurator->method('getItemActions')->willReturn([$this->createMock(ItemActionInterface::class)]);
49
        $configurator->method('hasItemActions')->willReturn(true);
50
        $configurator->method('getListActions')->willReturn([$this->createMock(ListActionInterface::class)]);
51
        $configurator->method('hasListActions')->willReturn(true);
52
        $configurator->method('getBulkActions')->willReturn([$this->createMock(BulkActionInterface::class)]);
53
        $configurator->method('hasBulkActions')->willReturn(true);
54
        $configurator->method('getPagerfanta')->willReturn($this->createMock(Pagerfanta::class));
55
56
        $this->adminList = new AdminList($configurator);
57
    }
58
59
    public function testGetConfigurator()
60
    {
61
        $this->assertInstanceOf(AdminListConfiguratorInterface::class, $this->adminList->getConfigurator());
62
    }
63
64
    public function testGetFilterBuilder()
65
    {
66
        $this->assertInstanceOf(FilterBuilder::class, $this->adminList->getFilterBuilder());
67
    }
68
69
    public function testGetColumns()
70
    {
71
        $this->assertContains('a', $this->adminList->getColumns());
72
    }
73
74
    public function testGetExportColumns()
75
    {
76
        $this->assertContains('c', $this->adminList->getExportColumns());
77
    }
78
79
    public function testGetCount()
80
    {
81
        $this->assertEquals(666, $this->adminList->getCount());
82
    }
83
84
    public function testGetItems()
85
    {
86
        $this->assertContains('item', $this->adminList->getItems());
87
    }
88
89
    public function testHasSort()
90
    {
91
        $this->assertEquals(2, $this->adminList->hasSort());
92
        $this->assertTrue($this->adminList->hasSort('e'));
93
    }
94
95
    public function testCanEdit()
96
    {
97
        $item = new \stdClass();
98
        $this->assertTrue($this->adminList->canEdit($item));
99
    }
100
101
    public function testCanAdd()
102
    {
103
        $item = new \stdClass();
104
        $this->assertTrue($this->adminList->canAdd($item));
0 ignored issues
show
The call to AdminList::canAdd() has too many arguments starting with $item.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
105
    }
106
107
    public function testCanView()
108
    {
109
        $item = new \stdClass();
110
        $this->assertTrue($this->adminList->canView($item));
111
    }
112
113
    public function testCanDelete()
114
    {
115
        $item = new \stdClass();
116
        $this->assertTrue($this->adminList->canDelete($item));
117
    }
118
119
    public function testCanExport()
120
    {
121
        $this->assertTrue($this->adminList->canExport());
122
    }
123
124
    public function testGetIndexUrl()
125
    {
126
        $this->assertTrue(is_array($this->adminList->getIndexUrl()));
127
    }
128
129
    public function testGetEditUrlFor()
130
    {
131
        $item = new \stdClass();
132
        $this->assertTrue(is_array($this->adminList->getEditUrlFor($item)));
133
    }
134
135
    public function testGetDeleteUrlFor()
136
    {
137
        $item = new \stdClass();
138
        $this->assertTrue(is_array($this->adminList->getDeleteUrlFor($item)));
139
    }
140
141
    public function testGetAddUrlFor()
142
    {
143
        $this->assertTrue(is_array($this->adminList->getAddUrlFor([])));
144
    }
145
146
    public function testGetExportUrl()
147
    {
148
        $this->assertTrue(is_array($this->adminList->getExportUrl()));
149
    }
150
151
    public function testGetViewUrl()
152
    {
153
        $item = new \stdClass();
154
        $this->assertTrue(is_array($this->adminList->getViewUrlFor($item)));
155
    }
156
157
    public function testGetValue()
158
    {
159
        $object = new \stdClass();
160
        $this->assertEquals('test', $this->adminList->getValue($object, 'test'));
161
    }
162
163
    public function testGetStringValue()
164
    {
165
        $object = new \stdClass();
166
        $this->assertEquals('stringtest', $this->adminList->getStringValue($object, 'test'));
167
    }
168
169
    public function testGetOrderBy()
170
    {
171
        $this->assertEquals('name', $this->adminList->getOrderBy());
172
    }
173
174
    public function testGetOrderDirection()
175
    {
176
        $this->assertEquals('up', $this->adminList->getOrderDirection());
177
    }
178
179
    public function testGetItemActions()
180
    {
181
        $itemActions = $this->adminList->getItemActions();
182
        $this->assertTrue(is_array($itemActions));
183
        $this->assertInstanceOf(ItemActionInterface::class, current($itemActions));
184
    }
185
186
    public function testHasItemActions()
187
    {
188
        $this->assertTrue($this->adminList->hasItemActions());
189
    }
190
191
    public function testHasListActions()
192
    {
193
        $this->assertTrue($this->adminList->hasListActions());
194
    }
195
196
    public function testGetListActions()
197
    {
198
        $listActions = $this->adminList->getListActions();
199
        $this->assertTrue(is_array($listActions));
200
        $this->assertInstanceOf(ListActionInterface::class, current($listActions));
201
    }
202
203
    public function testGetBulkActions()
204
    {
205
        $bulkActions = $this->adminList->getBulkActions();
206
        $this->assertTrue(is_array($bulkActions));
207
        $this->assertInstanceOf(BulkActionInterface::class, current($bulkActions));
208
    }
209
210
    public function testHasBulkActions()
211
    {
212
        $this->assertTrue($this->adminList->hasBulkActions());
213
    }
214
215
    public function testGetPagerfanta()
216
    {
217
        $this->assertInstanceOf(Pagerfanta::class, $this->adminList->getPagerfanta());
218
    }
219
}
220