Source of file ControllerAnnotatorTest.php
Size: 5,486 Bytes - Last Modified: 2021-12-23T10:24:49+00:00
/var/www/docs.ssmods.com/process/src/tests/unit/ControllerAnnotatorTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | <?php namespace SilverLeague\IDEAnnotator\Tests; use PHPUnit_Framework_TestCase; use SilverLeague\IDEAnnotator\DataObjectAnnotator; use SilverLeague\IDEAnnotator\Helpers\AnnotateClassInfo; use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; /** * Class DataObjectAnnotatorTest * * Several tests to make sure the Annotator does it's job correctly * * @mixin PHPUnit_Framework_TestCase */ class ControllerAnnotatorTest extends SapphireTest { /** * @var MockDataObjectAnnotator */ private $annotator; /** * @var AnnotatePermissionChecker $permissionChecker */ private $permissionChecker; /** * Check if Page is annotated correctly */ public function testPageGetsAnnotated() { $classInfo = new AnnotateClassInfo(TestAnnotatorPage::class); $filePath = $classInfo->getClassFilePath(); $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TestAnnotatorPage::class); $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage', $content); $this->assertContains('@property string $SubTitle', $content); } public function testPageControllerGetsAnnotator() { $classInfo = new AnnotateClassInfo(TestAnnotatorPageController::class); $filePath = $classInfo->getClassFilePath(); $content = $this->annotator->getGeneratedFileContent( file_get_contents($filePath), TestAnnotatorPageController::class ); $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPageController', $content); $this->assertContains('@property \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage dataRecord', $content); $this->assertContains('@method \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage data()', $content); $this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage', $content); $this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage_Extension', $content); } /** * Test the generation of annotations for an Extension */ public function testAnnotateControllerExtension() { $classInfo = new AnnotateClassInfo(TestAnnotatorPage_Extension::class); $filePath = $classInfo->getClassFilePath(); $original = file_get_contents($filePath); $annotated = $this->annotator->getGeneratedFileContent($original, TestAnnotatorPage_Extension::class); $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage_Extension', $annotated); $this->assertContains( '@property \SilverLeague\IDEAnnotator\Tests\TestAnnotatorPageController|\SilverLeague\IDEAnnotator\Tests\TestAnnotatorPage_Extension $owner', $annotated ); } public function testShortPageGetsAnnotated() { Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); $classInfo = new AnnotateClassInfo(TestAnnotatorPage::class); $filePath = $classInfo->getClassFilePath(); $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), TestAnnotatorPage::class); $this->assertContains('@property string $SubTitle', $content); } public function testShortPageControllerGetsAnnotator() { Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); $classInfo = new AnnotateClassInfo(TestAnnotatorPageController::class); $filePath = $classInfo->getClassFilePath(); $content = $this->annotator->getGeneratedFileContent( file_get_contents($filePath), TestAnnotatorPageController::class ); $this->assertContains('@property TestAnnotatorPage dataRecord', $content); $this->assertContains('@method TestAnnotatorPage data()', $content); $this->assertContains('@mixin TestAnnotatorPage', $content); $this->assertContains('@mixin TestAnnotatorPage_Extension', $content); } /** * Test the generation of annotations for an Extension */ public function testShortAnnotateControllerExtension() { Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', true); $classInfo = new AnnotateClassInfo(TestAnnotatorPage_Extension::class); $filePath = $classInfo->getClassFilePath(); $original = file_get_contents($filePath); $annotated = $this->annotator->getGeneratedFileContent($original, TestAnnotatorPage_Extension::class); $this->assertContains( '@property TestAnnotatorPageController|TestAnnotatorPage_Extension $owner', $annotated ); } public function tearDown() { parent::tearDown(); } /** * Setup Defaults */ protected function setUp() { parent::setUp(); Config::modify()->set(DataObjectAnnotator::class, 'use_short_name', false); Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']); $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class); $this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); } } |