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\HTTPRequest; |
10
|
|
|
use SilverStripe\Core\Environment; |
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
13
|
|
|
|
14
|
|
|
class AnnotatableTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Annotatable |
19
|
|
|
*/ |
20
|
|
|
protected $extension; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
parent::setUp(); |
25
|
|
|
$this->extension = Injector::inst()->get(Annotatable::class); |
26
|
|
|
$this->extension->setOwner(Controller::create()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testOutput() |
30
|
|
|
{ |
31
|
|
|
$this->extension->displayMessage('Hello world'); |
32
|
|
|
$this->expectOutputString("\nHello world\n\n"); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testSetUp() |
36
|
|
|
{ |
37
|
|
|
$this->extension->setUp(); |
38
|
|
|
$this->assertInstanceOf(DataObjectAnnotator::class, $this->extension->getAnnotator()); |
39
|
|
|
$this->assertInstanceOf(AnnotatePermissionChecker::class, $this->extension->getPermissionChecker()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testAfterCallActionHandlerRequestBlock() |
43
|
|
|
{ |
44
|
|
|
$request = new HTTPRequest('GET', '/dev/build', ['skipannotation' => true]); |
45
|
|
|
$this->extension->getOwner()->setRequest($request); |
46
|
|
|
|
47
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testAfterCallActionHandlerConfigBlock() |
51
|
|
|
{ |
52
|
|
|
DataObjectAnnotator::config()->set('enabled', false); |
53
|
|
|
|
54
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testAfterCallActionHandlerDevBlock() |
58
|
|
|
{ |
59
|
|
|
Environment::setEnv('SS_ENVIRONMENT_TYPE', 'Live'); |
60
|
|
|
|
61
|
|
|
$this->assertNull($this->extension->afterCallActionHandler()); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.