Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
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 Codeception\Test\Unit;
6
use Kunstmaan\AdminListBundle\AdminList\AdminList;
7
use Kunstmaan\AdminListBundle\AdminList\BulkAction\BulkActionInterface;
8
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
9
use Kunstmaan\AdminListBundle\AdminList\FilterBuilder;
10
use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface;
11
use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface;
12
use Pagerfanta\Pagerfanta;
13
14
/**
15
 * Class AdminListTest
16
 *
17
 * @todo add the getViewUrlFor test after fixing the issue that this function currently does not exist in the AdminListConfiguratorInterface
18
 */
19
class AdminListTest extends Unit
20
{
21
    /** @var AdminList */
22
    protected $adminList;
23
24
    public function _before()
25
    {
26
        /** @var AdminListConfiguratorInterface */
27
        $configurator = $this->makeEmpty(AdminListConfiguratorInterface::class, [
28
            'getFilterBuilder' => new FilterBuilder(),
29
            'getFields' => ['a', 'b'],
30
            'getExportFields' => ['c', 'd'],
31
            'getCount' => '666',
32
            'getItems' => ['item'],
33
            'getIterator' => $this->makeEmpty(\Iterator::class),
34
            'getSortFields' => ['e', 'f'],
35
            'canEdit' => true,
36
            'canAdd' => true,
37
            'canView' => true,
38
            'canDelete' => true,
39
            'canExport' => true,
40
            'getIndexUrl' => [],
41
            'getEditUrlFor' => [],
42
            'getDeleteUrlFor' => [],
43
            'getAddUrlFor' => [],
44
            'getExportUrl' => [],
45
            'getValue' => 'test',
46
            'getStringValue' => 'stringtest',
47
            'getOrderBy' => 'name',
48
            'getOrderDirection' => 'up',
49
            'getItemActions' => [$this->makeEmpty(ItemActionInterface::class)],
50
            'hasItemActions' => true,
51
            'getListActions' => [$this->makeEmpty(ListActionInterface::class)],
52
            'hasListActions' => true,
53
            'getBulkActions' => [$this->makeEmpty(BulkActionInterface::class)],
54
            'hasBulkActions' => true,
55
            'getPagerfanta' => $this->makeEmpty(Pagerfanta::class),
56
        ]);
57
58
        $this->adminList = new AdminList($configurator);
59
    }
60
61
    public function testGetConfigurator()
62
    {
63
        $this->assertInstanceOf(AdminListConfiguratorInterface::class, $this->adminList->getConfigurator());
64
    }
65
66
    public function testGetFilterBuilder()
67
    {
68
        $this->assertInstanceOf(FilterBuilder::class, $this->adminList->getFilterBuilder());
69
    }
70
71
    public function testGetColumns()
72
    {
73
        $this->assertContains('a', $this->adminList->getColumns());
74
    }
75
76
    public function testGetExportColumns()
77
    {
78
        $this->assertContains('c', $this->adminList->getExportColumns());
79
    }
80
81
    public function testGetCount()
82
    {
83
        $this->assertEquals(666, $this->adminList->getCount());
84
    }
85
86
    public function testGetItems()
87
    {
88
        $this->assertContains('item', $this->adminList->getItems());
89
    }
90
91
    public function getIterator()
92
    {
93
        $this->assertInstanceOf(\Iterator::class, $this->adminList->getIterator());
94
    }
95
96
    public function testHasSort()
97
    {
98
        $this->assertEquals(2, $this->adminList->hasSort());
99
        $this->assertTrue($this->adminList->hasSort('e'));
100
    }
101
102
    public function testCanEdit()
103
    {
104
        $item = new \stdClass();
105
        $this->assertTrue($this->adminList->canEdit($item));
106
    }
107
108
    public function testCanAdd()
109
    {
110
        $item = new \stdClass();
111
        $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...
112
    }
113
114
    public function testCanView()
115
    {
116
        $item = new \stdClass();
117
        $this->assertTrue($this->adminList->canView($item));
118
    }
119
120
    public function testCanDelete()
121
    {
122
        $item = new \stdClass();
123
        $this->assertTrue($this->adminList->canDelete($item));
124
    }
125
126
    public function testCanExport()
127
    {
128
        $this->assertTrue($this->adminList->canExport());
129
    }
130
131
    public function testGetIndexUrl()
132
    {
133
        $this->assertTrue(is_array($this->adminList->getIndexUrl()));
134
    }
135
136
    public function testGetEditUrlFor()
137
    {
138
        $item = new \stdClass();
139
        $this->assertTrue(is_array($this->adminList->getEditUrlFor($item)));
140
    }
141
142
    public function testGetDeleteUrlFor()
143
    {
144
        $item = new \stdClass();
145
        $this->assertTrue(is_array($this->adminList->getDeleteUrlFor($item)));
146
    }
147
148
    public function testGetAddUrlFor()
149
    {
150
        $this->assertTrue(is_array($this->adminList->getAddUrlFor([])));
151
    }
152
153
    public function testGetExportUrl()
154
    {
155
        $this->assertTrue(is_array($this->adminList->getExportUrl()));
156
    }
157
158
    public function testGetValue()
159
    {
160
        $object = new \stdClass();
161
        $this->assertEquals('test', $this->adminList->getValue($object, 'test'));
162
    }
163
164
    public function testGetStringValue()
165
    {
166
        $object = new \stdClass();
167
        $this->assertEquals('stringtest', $this->adminList->getStringValue($object, 'test'));
168
    }
169
170
    public function testGetOrderBy()
171
    {
172
        $this->assertEquals('name', $this->adminList->getOrderBy());
173
    }
174
175
    public function testGetOrderDirection()
176
    {
177
        $this->assertEquals('up', $this->adminList->getOrderDirection());
178
    }
179
180
    public function testGetItemActions()
181
    {
182
        $itemActions = $this->adminList->getItemActions();
183
        $this->assertTrue(is_array($itemActions));
184
        $this->assertInstanceOf(ItemActionInterface::class, current($itemActions));
185
    }
186
187
    public function testHasItemActions()
188
    {
189
        $this->assertTrue($this->adminList->hasItemActions());
190
    }
191
192
    public function testHasListActions()
193
    {
194
        $this->assertTrue($this->adminList->hasListActions());
195
    }
196
197
    public function testGetListActions()
198
    {
199
        $listActions = $this->adminList->getListActions();
200
        $this->assertTrue(is_array($listActions));
201
        $this->assertInstanceOf(ListActionInterface::class, current($listActions));
202
    }
203
204
    public function testGetBulkActions()
205
    {
206
        $bulkActions = $this->adminList->getBulkActions();
207
        $this->assertTrue(is_array($bulkActions));
208
        $this->assertInstanceOf(BulkActionInterface::class, current($bulkActions));
209
    }
210
211
    public function testHasBulkActions()
212
    {
213
        $this->assertTrue($this->adminList->hasBulkActions());
214
    }
215
216
    public function testGetPagerfanta()
217
    {
218
        $this->assertInstanceOf(Pagerfanta::class, $this->adminList->getPagerfanta());
219
    }
220
}
221