1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\IDEAnnotator\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
use SilverLeague\IDEAnnotator\AnnotateClassInfo; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use SilverStripe\Core\Config\Config; |
9
|
|
|
use SilverLeague\IDEAnnotator\AnnotatePermissionChecker; |
10
|
|
|
use SilverLeague\IDEAnnotator\DataObjectAnnotator; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class DataObjectAnnotatorTest |
15
|
|
|
* |
16
|
|
|
* Several tests to make sure the Annotator does it's job correctly |
17
|
|
|
* |
18
|
|
|
* @mixin PHPUnit_Framework_TestCase |
19
|
|
|
*/ |
20
|
|
|
class ControllerAnnotatorTest extends SapphireTest |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var MockDataObjectAnnotator |
24
|
|
|
*/ |
25
|
|
|
private $annotator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var AnnotatePermissionChecker $permissionChecker |
29
|
|
|
*/ |
30
|
|
|
private $permissionChecker; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Setup Defaults |
34
|
|
|
*/ |
35
|
|
|
protected function setUp() |
36
|
|
|
{ |
37
|
|
|
parent::setUp(); |
38
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', false); |
39
|
|
|
|
40
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); |
41
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']); |
42
|
|
|
|
43
|
|
|
$this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class); |
44
|
|
|
$this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testPageGetsAnnotated() |
48
|
|
|
{ |
49
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTest::class); |
50
|
|
|
$filePath = $classInfo->getClassFilePath(); |
51
|
|
|
|
52
|
|
|
$content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), AnnotatorPageTest::class); |
53
|
|
|
|
54
|
|
|
$this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest', $content); |
55
|
|
|
$this->assertContains('@property string $SubTitle', $content); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testPageControllerGetsAnnotator() |
59
|
|
|
{ |
60
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTestController::class); |
61
|
|
|
$filePath = $classInfo->getClassFilePath(); |
62
|
|
|
|
63
|
|
|
$content = $this->annotator->getGeneratedFileContent( |
64
|
|
|
file_get_contents($filePath), |
65
|
|
|
AnnotatorPageTestController::class |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTestController', $content); |
69
|
|
|
$this->assertContains('@property \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest dataRecord', $content); |
70
|
|
|
$this->assertContains('@method \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest data()', $content); |
71
|
|
|
$this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest', $content); |
72
|
|
|
$this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension', $content); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test the generation of annotations for an Extension |
77
|
|
|
*/ |
78
|
|
|
public function testAnnotateControllerExtension() |
79
|
|
|
{ |
80
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTest_Extension::class); |
81
|
|
|
$filePath = $classInfo->getClassFilePath(); |
82
|
|
|
$original = file_get_contents($filePath); |
83
|
|
|
$annotated = $this->annotator->getGeneratedFileContent($original, AnnotatorPageTest_Extension::class); |
84
|
|
|
|
85
|
|
|
$this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension', $annotated); |
86
|
|
|
$this->assertContains( |
87
|
|
|
'@property \SilverLeague\IDEAnnotator\Tests\AnnotatorPageTestController|\SilverLeague\IDEAnnotator\Tests\AnnotatorPageTest_Extension $owner', |
88
|
|
|
$annotated |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testShortPageGetsAnnotated() |
93
|
|
|
{ |
94
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); |
95
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTest::class); |
96
|
|
|
$filePath = $classInfo->getClassFilePath(); |
97
|
|
|
|
98
|
|
|
$content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), AnnotatorPageTest::class); |
99
|
|
|
|
100
|
|
|
$this->assertContains('@property string $SubTitle', $content); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testShortPageControllerGetsAnnotator() |
104
|
|
|
{ |
105
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); |
106
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTestController::class); |
107
|
|
|
$filePath = $classInfo->getClassFilePath(); |
108
|
|
|
|
109
|
|
|
$content = $this->annotator->getGeneratedFileContent( |
110
|
|
|
file_get_contents($filePath), |
111
|
|
|
AnnotatorPageTestController::class |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$this->assertContains('@property AnnotatorPageTest dataRecord', $content); |
115
|
|
|
$this->assertContains('@method AnnotatorPageTest data()', $content); |
116
|
|
|
$this->assertContains('@mixin AnnotatorPageTest', $content); |
117
|
|
|
$this->assertContains('@mixin AnnotatorPageTest_Extension', $content); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Test the generation of annotations for an Extension |
122
|
|
|
*/ |
123
|
|
|
public function testShortAnnotateControllerExtension() |
124
|
|
|
{ |
125
|
|
|
Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); |
126
|
|
|
$classInfo = new AnnotateClassInfo(AnnotatorPageTest_Extension::class); |
127
|
|
|
$filePath = $classInfo->getClassFilePath(); |
128
|
|
|
$original = file_get_contents($filePath); |
129
|
|
|
$annotated = $this->annotator->getGeneratedFileContent($original, AnnotatorPageTest_Extension::class); |
130
|
|
|
|
131
|
|
|
$this->assertContains( |
132
|
|
|
'@property AnnotatorPageTestController|AnnotatorPageTest_Extension $owner', |
133
|
|
|
$annotated |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function tearDown() |
138
|
|
|
{ |
139
|
|
|
parent::tearDown(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|