getName()] = $info; } return $result; } public static function setUpBeforeClass() { file_put_contents(self::$LOG = './result/'.__CLASS__.'.log', date('d.m.Y H:i:s')."\n"); if(!defined('USE_MCMS')) define('USE_MCMS', true); if(!defined('DEBUG')) define('DEBUG', true); importlib('MCMS.system'); self::$dbcfg = array( 'dsn' => 'mysqli:localhost/test', 'user' => 'tester', 'passwd' => 'tester', 'option' => [] ); $db = Mammut\DB\DB::newInstance(self::$dbcfg['dsn'], self::$dbcfg['user'], self::$dbcfg['passwd']); $db->query("SET FOREIGN_KEY_CHECKS = 0"); $tables = self::getTableInfos(); foreach ($tables as $table) { if ($db->tableExists($table->getName())) $db->dropTable($table->getName()); $db->createTable($table); } $db->query("SET FOREIGN_KEY_CHECKS = 1"); // adding demo data $row = ['type' => 'system', 'key' => 'mcmsdb', 'version' => '1.1.0.0']; $db->table('installinfos')->insert($row); $row = ['domain' => '*', 'online' => 'y']; $db->table('websites')->insert($row); $row = ['site_id' => -1, 'instance' => 'home', 'key' => 'text1', 'content' => 'DemoText1234']; $db->table('contents')->insert($row); $db->close(); } public static function tearDownAfterClass() { $db = Mammut\DB\DB::newInstance(self::$dbcfg['dsn'], self::$dbcfg['user'], self::$dbcfg['passwd']); $tables = self::getTableInfos(); $tables = array_reverse($tables, true); $db->query("SET FOREIGN_KEY_CHECKS = 0"); foreach ($tables as $table) $db->dropTable($table); $db->query("SET FOREIGN_KEY_CHECKS = 1"); $db->close(); } protected function tearDown() { try { // clean up system instance if it hasn't been shut down if (System::isInitialized()) System::shutdown(); } catch (Exception $ex) { } } protected function setBasics($instance = 'home') { $_GET = array('instance' => $instance); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_HOST'] = 'localhost'; } public function testExecuteRunnerSteps() { file_put_contents(self::$LOG, "\n### ".__METHOD__." ################\n",FILE_APPEND); $this->setBasics(); $appender = new ArrayAppender(); $LOG = Logger::getInstance(); $LOG->addAppender($appender); $session = new \MCMS\Session\CLISession(); System::init(); $system = System::getInstance(); $system->setConfig('syskey', 'key123'); $system->setConfig('db', self::$dbcfg); $system->injectSession($session); file_put_contents(self::$LOG, "\n### Runner() ###\n",FILE_APPEND); $runner = new Runner(); file_put_contents(self::$LOG, "\n### doInit() ###\n",FILE_APPEND); $runner->doInit(); file_put_contents(self::$LOG, "\n### doRoute() ###\n",FILE_APPEND); $runner->doRoute(); file_put_contents(self::$LOG, "\n### doBeforeRun() ###\n",FILE_APPEND); $runner->doBeforeRun(); file_put_contents(self::$LOG, "\n### doRun() ###\n",FILE_APPEND); $runner->doRun(); file_put_contents(self::$LOG, "\n### doAfterRun() ###\n",FILE_APPEND); $runner->doAfterRun(); ob_start(); $runner->doOutput(); file_put_contents('./result/mcms-main.html', ob_get_clean()); file_put_contents(self::$LOG, "\n### doCleanup() ###\n",FILE_APPEND); $runner->doCleanup(); System::shutdown(); $log = $appender->getLog(); file_put_contents(self::$LOG, "\n### LOG: ###\n",FILE_APPEND); foreach ($log as $l) file_put_contents(self::$LOG, sprintf("%-20s %-7s %-50s %s\n", $l['timestamp'], $l['level'], $l['xtend']['class'].$l['xtend']['calltype'].$l['xtend']['function'],$l['message']),FILE_APPEND); $LOG->removeAppender($appender); } public function testExecuteRunnerRun() { file_put_contents(self::$LOG, "\n### ".__METHOD__." ################\n",FILE_APPEND); $this->setBasics(); $appender = new ArrayAppender(); $LOG = Logger::getInstance(); $LOG->addAppender($appender); $session = new \MCMS\Session\CLISession(); System::init(); $system = System::getInstance(); $system->setConfig('syskey', 'key123'); $system->setConfig('db', self::$dbcfg); $system->injectSession($session); file_put_contents(self::$LOG, "\n### Runner() ###\n",FILE_APPEND); $runner = new Runner(); file_put_contents(self::$LOG, "\n### run() ###\n",FILE_APPEND); ob_start(); $runner->run([ // 'doLoadConfig', 'doInit', 'doRoute', 'doBeforeRun', 'doRun', 'doAfterRun', 'doOutput', 'doCleanup' ]); file_put_contents('./result/mcms-main-run.html', ob_get_clean()); System::shutdown(); $log = $appender->getLog(); file_put_contents(self::$LOG, "\n### LOG: ###\n",FILE_APPEND); foreach ($log as $l) file_put_contents(self::$LOG, sprintf("%-20s %-7s %-50s %s\n", $l['timestamp'], $l['level'], $l['xtend']['class'].$l['xtend']['calltype'].$l['xtend']['function'],$l['message']),FILE_APPEND); $LOG->removeAppender($appender); } public function testExecuteRunnerUser() { file_put_contents(self::$LOG, "\n### ".__METHOD__." ################\n",FILE_APPEND); $this->setBasics(); $appender = new ArrayAppender(); $LOG = Logger::getInstance(); $LOG->addAppender($appender); $session = new \MCMS\Session\CLISession(); System::init(); $system = System::getInstance(); $system->setConfig('syskey', 'key123'); $system->setConfig('db', self::$dbcfg); $system->injectSession($session); $user = new UserDefault(); $user->login = 'testusr'; $user->masteradmin = true; $user->email = 'no@email.com'; $user->password = 'testpasswd'; file_put_contents(self::$LOG, "\n### Runner() ###\n",FILE_APPEND); $runner = new Runner(); file_put_contents(self::$LOG, "\n### doInit() ###\n",FILE_APPEND); $runner->doInit(); $system->getUserSvc()->createUser($user); $system->getUserSvc()->loginUser($user->login, $user->password); $usr = $system->getUserSvc()->getUser(); $this->assertNotNull($usr, "No user object returned"); $this->assertTrue($system->getUserSvc()->userHasPriv($usr)); // file_put_contents(self::$LOG, "\n### doRoute() ###\n",FILE_APPEND); // $runner->doRoute(); // file_put_contents(self::$LOG, "\n### doBeforeRun() ###\n",FILE_APPEND); // $runner->doBeforeRun(); // file_put_contents(self::$LOG, "\n### doRun() ###\n",FILE_APPEND); // $runner->doRun(); // file_put_contents(self::$LOG, "\n### doAfterRun() ###\n",FILE_APPEND); // $runner->doAfterRun(); // ob_start(); // $runner->doOutput(); // file_put_contents('./result/mcms-main.html', ob_get_clean()); file_put_contents(self::$LOG, "\n### doCleanup() ###\n",FILE_APPEND); $runner->doCleanup(); $log = $appender->getLog(); file_put_contents(self::$LOG, "\n### LOG: ###\n",FILE_APPEND); foreach ($log as $l) file_put_contents(self::$LOG, sprintf("%-20s %-7s %-50s %s\n", $l['timestamp'], $l['level'], $l['xtend']['class'].$l['xtend']['calltype'].$l['xtend']['function'],$l['message']),FILE_APPEND); $LOG->removeAppender($appender); } }