files[] = $tmpfname; if (!empty($pContent)) { $handle = fopen($tmpfname, "w"); fwrite($handle, $pContent); fclose($handle); } return $tmpfname; } protected function getSampleDir() { return __DIR__ . '/samples'; } /** * Cleanup of files * @see SimpleTestCase::after() */ public function after($method) { parent::after($method); foreach ($this->files as $file) { @unlink($file); } $this->files = []; } /** * shared methods for test initialization */ public static function initTest() { //connect the API if (!self::$connected) { common_session_SessionManager::startSession(new common_test_TestUserSession()); self::$connected = true; } } public function restoreTestSession() { return common_session_SessionManager::startSession(new common_test_TestUserSession()); } /** * * @author Lionel Lecaque, lionel@taotesting.com * @param string $var * @param string $className * @deprecated use assertInstanceOf instead */ public function assertIsA($var, $className) { $this->assertInstanceOf($className, $var); } public function installExtension($extid) { if (!common_ext_ExtensionsManager::singleton()->isInstalled($extid)) { $extension = common_ext_ExtensionsManager::singleton()->getExtensionById($extid); $installer = new common_ext_ExtensionInstaller($extension); $installer->install(); } } public function uninstallExtension($extid) { if (common_ext_ExtensionsManager::singleton()->isInstalled($extid)) { $extension = common_ext_ExtensionsManager::singleton()->getExtensionById($extid); $installer = new common_ext_ExtensionUninstaller($extension); $installer->uninstall(); } } protected function disableCache() { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('generis') ; $this->config = $ext->getConfig(common_persistence_Manager::SERVICE_ID); $conf = $this->config; if (isset($conf['cache']) && isset($conf['cache']['driver'])) { $conf['cache']['driver'] = 'no_storage'; \common_Logger::i('Set cache on NO STORAGE'); $ext->setConfig(_common_persistence_Manager::SERVICE_ID, $conf); } } protected function restoreCache() { \common_Logger::i('Restore cache persistence'); $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('generis') ; $ext->setConfig(common_persistence_Manager::SERVICE_ID, $this->config); } /** * Returns the test session if available * @throws common_exception_Error * @return common_test_TestUserSession */ public static function getTestSession() { if (!self::$connected) { throw new common_exception_Error('Trying to retrieve TestSession without initialising it first via initTest()'); } $session = common_session_SessionManager::getSession(); if (!$session instanceof common_test_TestUserSession) { throw new common_exception_Error('current session is no longer a common_test_TestUserSession'); } return $session; } /** * Should be used only from integration tests to bootstrap application. */ protected static function loadGenerisConfig() { common_Config::load(); } }