1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\DataTypes; |
4
|
|
|
|
5
|
|
|
use Craft; |
6
|
|
|
use craft\models\Section; |
7
|
|
|
use Codeception\Test\Unit; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class SectionDataTypeTest. |
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 SectionDataTypeTest extends Unit |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var SectionDataType |
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 SectionDataType(); |
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->getMockSection()]; |
55
|
|
|
|
56
|
|
|
Craft::$app->sections->expects($this->exactly(1)) |
57
|
|
|
->method('getAllSections') |
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|Section |
71
|
|
|
*/ |
72
|
|
|
private function getMockSection() |
73
|
|
|
{ |
74
|
|
|
return $this->getMockBuilder(Section::class)->getMock(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|