|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\DataTypes; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\models\UserGroup; |
|
7
|
|
|
use Codeception\Test\Unit; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class UserGroupDataTypeTest. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Nerds & Company |
|
13
|
|
|
* @copyright Copyright (c) 2015-2017, Nerds & Company |
|
14
|
|
|
* @license MIT |
|
15
|
|
|
* |
|
16
|
|
|
* @see http://www.nerds.company |
|
17
|
|
|
*/ |
|
18
|
|
|
class UserGroupDataTypeTest extends Unit |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var UserGroupDataType |
|
22
|
|
|
*/ |
|
23
|
|
|
private $dataType; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Set the dataType. |
|
27
|
|
|
* |
|
28
|
|
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName) |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function _before() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->dataType = new UserGroupDataType(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
//============================================================================================================== |
|
36
|
|
|
//================================================= TESTS ==================================================== |
|
37
|
|
|
//============================================================================================================== |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get mapper handle test. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testGetMapperHandle() |
|
43
|
|
|
{ |
|
44
|
|
|
$result = $this->dataType->getMapperHandle(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertSame('modelMapper', $result); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get records test. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testGetRecords() |
|
53
|
|
|
{ |
|
54
|
|
|
$records = [$this->getMockUserGroup()]; |
|
55
|
|
|
|
|
56
|
|
|
Craft::$app->userGroups->expects($this->exactly(1)) |
|
57
|
|
|
->method('getAllGroups') |
|
58
|
|
|
->willReturn($records); |
|
59
|
|
|
|
|
60
|
|
|
$result = $this->dataType->getRecords(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame($records, $result); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
//============================================================================================================== |
|
66
|
|
|
//================================================ HELPERS =================================================== |
|
67
|
|
|
//============================================================================================================== |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return Mock|UserGroup |
|
71
|
|
|
*/ |
|
72
|
|
|
private function getMockUserGroup() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getMockBuilder(UserGroup::class)->getMock(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|