diff --git a/App.php b/App.php index 824e541..f6dedbe 100644 --- a/App.php +++ b/App.php @@ -11,6 +11,7 @@ use Exception; use Pico; use SeacmsAppPlugin; use SeaCMS\Api\SpecialOutputException; +use SeaCMS\App\TestInterface; use Throwable; set_error_handler(function ( @@ -51,7 +52,7 @@ class App */ protected $pico; - public function __construct(string $contentFolderFromRoot) + public function __construct(string $contentFolderFromRoot, ?TestInterface $testRunner = null) { // sanitize content folder $cwd = getcwd(); @@ -76,7 +77,7 @@ class App self::PLUGINS_PATH, // plugins dir self::THEMES_PATH // themes dir ); - $this->pico->loadPlugin(new SeacmsAppPlugin($this->pico)); + $this->pico->loadPlugin(new SeacmsAppPlugin($this->pico, $testRunner)); $this->update_SERVERIfNeeded($this->pico, $contentFolderFromRoot); } diff --git a/SeacmsAppPlugin.php b/SeacmsAppPlugin.php index 73db11f..fb8b36d 100644 --- a/SeacmsAppPlugin.php +++ b/SeacmsAppPlugin.php @@ -5,6 +5,7 @@ use SeaCMS\Api\LateApiAware; use SeaCMS\Api\JsonResponse; use SeaCMS\App\MdResponse; +use SeaCMS\App\TestInterface; /** * A plugin for SeaCMS-app. @@ -17,6 +18,30 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware */ const API_VERSION = 4; + /** + * define if test output should be defined + * @var bool + */ + protected $triggerTest; + + /** + * define test + * @var TestInterface + */ + protected $testRunner; + + /** + * construct + * @param Pico $pico current instance of Pico + * @param ?TestInterface $testRunner optional + */ + public function __construct(Pico $pico, $testRunner = null) + { + parent::__construct($pico); + $this->triggerTest = !empty($testRunner) && ($testRunner instanceof TestInterface); + $this->testRunner = ($this->triggerTest) ? $testRunner : null; + } + /** * return api routes * @return array @@ -136,4 +161,16 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware return $this->apiPageAsMd("$folder1/$folder2/$folder3/$pageName"); } + /** + * Triggered after Pico has rendered the page + * + * @param string &$output contents which will be sent to the user + */ + public function onPageRendered(&$output) + { + if ($this->triggerTest){ + $this->testRunner->run($this,$output); + } + } + } \ No newline at end of file diff --git a/src/TestException.php b/src/TestException.php new file mode 100644 index 0000000..1345f48 --- /dev/null +++ b/src/TestException.php @@ -0,0 +1,14 @@ +runPico(); + $this->assertTrue($app instanceof App); + } + public function testFailure(): void + { + $this->assertTrue(false); + } +} \ No newline at end of file