|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverLeague\IDEAnnotator\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverLeague\IDEAnnotator\DataObjectAnnotator; |
|
6
|
|
|
use SilverLeague\IDEAnnotator\Extensions\Annotatable; |
|
7
|
|
|
use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker; |
|
8
|
|
|
use SilverStripe\Control\Controller; |
|
9
|
|
|
use SilverStripe\Control\Director; |
|
10
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
11
|
|
|
use SilverStripe\Core\Environment; |
|
12
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
13
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
14
|
|
|
|
|
15
|
|
|
class AnnotatableTest extends SapphireTest |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var Annotatable |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $extension; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
$this->extension = Injector::inst()->get(Annotatable::class); |
|
27
|
|
|
$this->extension->setOwner(Controller::create()); |
|
28
|
|
|
} |
|
29
|
|
|
public function testSetUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->extension->setUp(); |
|
32
|
|
|
$this->assertInstanceOf(DataObjectAnnotator::class, $this->extension->getAnnotator()); |
|
33
|
|
|
$this->assertInstanceOf(AnnotatePermissionChecker::class, $this->extension->getPermissionChecker()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testOutput() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->extension->displayMessage('Hello world'); |
|
39
|
|
|
$this->expectOutputString("\nHello world\n\n"); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testDisplayEndMessage() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->extension->displayMessage('Hello world', true, true); |
|
45
|
|
|
$this->expectOutputString("\nHELLO WORLD"); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testDisplayHeaderMessage() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->extension->displayMessage('Hello world', true); |
|
51
|
|
|
$this->expectOutputString("\nHELLO WORLD\n\n"); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testAfterCallActionHandlerRequestBlock() |
|
55
|
|
|
{ |
|
56
|
|
|
$request = new HTTPRequest('GET', '/dev/build', ['skipannotation' => true]); |
|
57
|
|
|
$this->extension->getOwner()->setRequest($request); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testAfterCallActionHandlerConfigBlock() |
|
63
|
|
|
{ |
|
64
|
|
|
DataObjectAnnotator::config()->set('enabled', false); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testAfterCallActionHandlerDevBlock() |
|
70
|
|
|
{ |
|
71
|
|
|
Environment::setEnv('SS_ENVIRONMENT_TYPE', 'Live'); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testAfterCallActionHandler() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->assertTrue($this->extension->afterCallActionHandler()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testAfterCallActionHandlerRun() |
|
82
|
|
|
{ |
|
83
|
|
|
$request = new HTTPRequest('GET', '/dev/build'); |
|
84
|
|
|
$this->extension->getOwner()->setRequest($request); |
|
85
|
|
|
DataObjectAnnotator::config()->set('enabled', true); |
|
86
|
|
|
DataObjectAnnotator::config()->set('enabled_modules', ['mysite']); |
|
87
|
|
|
|
|
88
|
|
|
$this->extension->afterCallActionHandler(); |
|
89
|
|
|
|
|
90
|
|
|
$output = $this->getActualOutput(); |
|
91
|
|
|
$this->assertContains("GENERATING CLASS DOCBLOCKS", $output); |
|
92
|
|
|
$this->assertContains("+ Page Annotated", $output); |
|
93
|
|
|
$this->assertContains("DOCBLOCK GENERATION FINISHED!", $output); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|