/** * init the test framework */ public function initFramework() { $this->setWhiteAndBlacklists(); // get config $configData = @(include 'phpunitconfig.inc.php'); if ($configData === false) { $configData = (include 'config.inc.php'); } if ($configData === false) { die('central configuration file config.inc.php not found in includepath: ' . get_include_path()); } $config = new Zend_Config($configData); Zend_Registry::set('testConfig', $config); $_SERVER['DOCUMENT_ROOT'] = $config->docroot; $_SERVER['REQUEST_URI'] = ''; Tinebase_Core::startCoreSession(); Tinebase_Core::initFramework(); // set default test mailer Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array()); // set max execution time Tinebase_Core::setExecutionLifeTime(1200); if ($config->locale) { Tinebase_Core::setupUserLocale($config->locale); } // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others) Zend_Session::$_unitTestEnabled = TRUE; }
public function setUp() { $options = array('env' => 'testing', 'resources' => array('Cache', 'Config', 'Path', 'Session')); $path = GENE_APP_PATH; Gene::app($path, $options); Zend_Session::$_unitTestEnabled = true; }
/** * @group ServerTests */ public function testAccountBlocking() { Zend_Session::$_unitTestEnabled = true; $request = \Zend\Http\PhpEnvironment\Request::fromString(<<<EOS POST /index.php HTTP/1.1 Content-Type: application/json Content-Length: 122 Host: 192.168.122.158 Connection: keep-alive Origin: http://192.168.1.158 X-Tine20-Request-Type: JSON X-Tine20-Jsonkey: undefined User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36 X-Tine20-Transactionid: 9c7129898e9f8ab7e4621fddf7077a1eaa425aac X-Requested-With: XMLHttpRequest Accept: */* Referer: http://192.168.122.158/tine20dev/ Accept-Encoding: gzip,deflate Accept-Language: de-DE,de;q=0.8,en-GB;q=0.6,en;q=0.4 EOS ); $credentials = $this->getTestCredentials(); $maxLoginFailures = Tinebase_Config::getInstance()->get(Tinebase_Config::MAX_LOGIN_FAILURES, 5); for ($i = 0; $i <= $maxLoginFailures; $i++) { $result = Tinebase_Controller::getInstance()->login($credentials['username'], 'foobar', $request); $this->assertFalse($result); } // account must be blocked now $result = Tinebase_Controller::getInstance()->login($credentials['username'], $credentials['password'], $request); $this->assertFalse($result); }
protected function setUp() { $this->_frontController = System_Application::getInstance()->getBootstrap()->getResource('FrontController'); $this->frontController->setParam('bootstrap', System_Application::getInstance()->getBootstrap()); $this->getRequest()->setBaseUrl($this->frontController->getBaseUrl()); Zend_Session::$_unitTestEnabled = true; }
/** * tear down tests */ protected function tearDown() { Zend_Session::$_unitTestEnabled = false; if ($this->_transactionId) { Tinebase_TransactionManager::getInstance()->rollBack(); } }
public function testInitSetsSaveHandler() { Zend_Session::$_unitTestEnabled = true; $saveHandler = $this->getMock('Zend_Session_SaveHandler_Interface'); $this->resource->setSaveHandler($saveHandler); $this->resource->init(); $this->assertSame($saveHandler, Zend_Session::getSaveHandler()); }
protected function setUp() { \Zend_Controller_Front::getInstance()->resetInstance(); $this->request = new \Zend_Controller_Request_Http(); \Zend_Session::$_unitTestEnabled = true; $this->acl = new \Zend_Acl(); $this->acl->deny(); $this->acl->addRole(new \Zend_Acl_Role(Acl::ROLE_GUEST)); $this->acl->addRole(new \Zend_Acl_Role(Acl::ROLE_AUTHENTICATED), Acl::ROLE_GUEST); parent::setUp(); }
public function testShouldNotAuthNoExistingUserAndReturnErrorCode() { //GIVEN Zend_Session::$_unitTestEnabled = true; $oApiUser = new AM_Api_User(); //WHEN $aResult = $oApiUser->login('no-existing-user', 'password'); //THEN $aExpectedResult = array('code' => Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, 'messages' => array('A record with the supplied identity could not be found.')); $this->assertEquals($aExpectedResult, $aResult); }
static function setUp() { set_include_path(implode(PATH_SEPARATOR, array(realpath(dirname(__FILE__) . '/../application'), realpath(dirname(__FILE__) . '/../library'), get_include_path()))); require_once realpath(dirname(__FILE__) . '/../application/Bootstrap.php'); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); self::$bootstrap = new Bootstrap(getenv('APPLICATION_ENV')); Zend_Session::$_unitTestEnabled = true; Zend_Loader::loadClass('Sql'); $sql = new Sql(); $sql->reset(); }
protected function setUp() { parent::setUp(); $this->rediska->set('user_ids:test', 1); $data = new stdClass(); $data->login = '******'; $data->password = '******'; $this->rediska->set('users:1', $data); Zend_Session::$_unitTestEnabled = true; $this->auth = Zend_Auth::getInstance(); $this->adapter = new Rediska_Zend_Auth_Adapter_Redis(); }
public static function setUpBeforeClass() { require_once 'var/Test/ServiceMock.php'; require_once 'var/Test/BeforeHookMock.php'; require_once 'var/Test/AfterHookMock.php'; require_once 'var/Test/Validator.php'; $iniPath = GENE_TEST_ROOT . '/var/config/database.ini'; $file = GENE_TEST_ROOT . '/var/sql/create.sql'; Gene_TestHelper::trancate($iniPath, $file, 'production'); $options = array('env' => 'testing', 'resources' => array('Cache', 'Config', 'Path', 'Db')); $path = GENE_APP_PATH; Gene::app($path, $options); Zend_Session::$_unitTestEnabled = true; }
protected function _init($componentClass) { Kwf_Component_Data_Root::setComponentClass($componentClass); Zend_Session::$_unitTestEnabled = true; $this->_root = Kwf_Component_Data_Root::getInstance(); $this->_root->setFilename('kwf/kwctest/' . $componentClass); if (function_exists('apc_clear_cache')) { apc_clear_cache('user'); } Kwf_Component_Cache_Memory::getInstance()->_clean(); Kwf_Cache_Simple::resetZendCache(); Kwc_FulltextSearch_MetaModel::setInstance(new Kwf_Model_FnF(array('primaryKey' => 'page_id'))); Kwf_Assets_Package_Default::clearInstances(); Kwf_Component_LogDuplicateModel::setInstance(new Kwf_Model_FnF(array())); Kwf_Media_MemoryCache::getInstance()->clean(); return $this->_root; }
/** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { $registry = Zend_Registry::getInstance(); if (isset($registry['router'])) { unset($registry['router']); } if (isset($registry['dispatcher'])) { unset($registry['dispatcher']); } if (isset($registry['plugin'])) { unset($registry['plugin']); } if (isset($registry['viewRenderer'])) { unset($registry['viewRenderer']); } Zend_Session::$_unitTestEnabled = false; session_id(uniqid()); }
/** * Set up the test case */ public function setUp() { parent::setUp(); $dir = Enlight_TestHelper::Instance()->TestPath('TempFiles'); $this->db = Enlight_Components_Db::factory('PDO_SQLITE', array('dbname' => Enlight_TestHelper::Instance()->TestPath('TempFiles') . 'auth.db')); $this->lockeduntilColumn = 'lockeduntil'; $this->createDb($this->lockeduntilColumn); $this->createDefaultUser($this->lockeduntilColumn); // Needed to simulate web environment - otherwise we would get a nasty notice. $GLOBALS['_SESSION'] = array(); Zend_Session::$_unitTestEnabled = true; Zend_Session::start(); $this->auth = Enlight_Components_Auth::getInstance(); $this->authAdapter = new Enlight_Components_Auth_Adapter_DbTable($this->db, 'test_auth', 'username', 'password'); $this->authAdapter->setIdentityColumn('username')->setCredentialColumn('password')->setExpiryColumn('lastlogin')->setSessionIdColumn('sessionID')->setSessionId('s4inr04o6apmclk7u88qau4r57'); $storage = new Zend_Auth_Storage_Session('Enlight', 'Auth'); $this->auth->setAdapter($this->authAdapter); $this->assertInstanceOf('Enlight_Components_Auth_Adapter_DbTable', $this->auth->getAdapter()); $this->auth->setStorage($storage); }
/** * init the test framework */ public function initFramework() { $this->setWhiteAndBlacklists(); $config = $this->getConfig(); // set some server vars. sabredav complains if REQUEST_URI is not set $_SERVER['DOCUMENT_ROOT'] = $config->docroot; $_SERVER['REQUEST_URI'] = ''; Tinebase_Core::startCoreSession(); Tinebase_Core::initFramework(); // set default test mailer Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array()); // set max execution time Tinebase_Core::setExecutionLifeTime(1200); if ($config->locale) { Tinebase_Core::setupUserLocale($config->locale); } // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others) Zend_Session::$_unitTestEnabled = TRUE; Tinebase_Core::set('frameworkInitialized', true); }
public function testShouldReturnListOfApplicationsForLoggedInUser() { //GIVEN date_default_timezone_set('Etc/GMT'); Zend_Session::$_unitTestEnabled = true; $oStorageMock = $this->getMock('Zend_Auth_Storage_Session'); Zend_Auth::getInstance()->setStorage($oStorageMock); $oExpectedUserObject = new stdClass(); $oExpectedUserObject->first_name = 'John'; $oExpectedUserObject->last_name = 'Doe'; $oExpectedUserObject->login = '******'; $oExpectedUserObject->email = '*****@*****.**'; $oExpectedUserObject->id = 1; $oExpectedUserObject->client = 1; $oExpectedUserObject->is_admin = 0; $oApiUser = new AM_Api_User(); //THEN $oStorageMock->expects($this->any())->method('read')->will($this->returnValue($oExpectedUserObject)); //WHEN $aResult = $oApiUser->getApplications('vp23rk326iem65udi5q38ob0o7'); //THEN $aExpectedResult = array('code' => AM_Api_User::RESULT_SUCCESS, 'applications' => array(1 => array('application_id' => 1, 'application_title' => 'Title', 'application_description' => 'Description', 'application_product_id' => 'com.padcms.application_1', 'application_notification_email' => 'Email message', 'application_notification_email_title' => 'Email title', 'application_notification_twitter' => 'Twitter message', 'application_notification_facebook' => 'Facebook message', 'application_preview' => 2, 'issues' => array(1 => array('issue_id' => 1, 'issue_title' => 'Title', 'issue_number' => 1, 'issue_state' => 'work-in-progress', 'issue_product_id' => 'com.padcms.issue_1', 'revisions' => array(1 => array('revision_id' => 1, 'revision_title' => 'Title', 'revision_state' => 'work-in-progress', 'revision_cover_image_list' => '/resources/export-cover-vertical/element/00/00/00/01/resource.jpg?', 'revision_video' => '/resources/none/element/00/00/00/02/resource.mp4', 'revision_color' => 'd9411a', 'revision_horizontal_mode' => '2pages', 'revision_orientation' => 'vertical', 'help_pages' => array(AM_Model_Db_IssueHelpPage::TYPE_HORIZONTAL => '/issue-help-page-horizontal/00/00/00/01/horizontal.png', AM_Model_Db_IssueHelpPage::TYPE_VERTICAL => '/issue-help-page-vertical/00/00/00/01/vertical.png'), 'revision_created' => '2012-05-04T15:47:03+00:00'))))))); $this->assertEquals($aExpectedResult, $aResult); }
/** * Reset MVC state * * Creates new request/response objects, resets the front controller * instance, and resets the action helper broker. * * @todo Need to update Zend_Layout to add a resetInstance() method * @return void */ public function reset() { $_SESSION = array(); $_GET = array(); $_POST = array(); $_COOKIE = array(); $this->resetRequest(); $this->resetResponse(); Zend_Layout::resetMvcInstance(); Zend_Controller_Action_HelperBroker::resetHelpers(); $this->frontController->resetInstance(); Zend_Session::$_unitTestEnabled = true; }
/** * Set up tests environment */ function setUp() { // _unitTestEnabled is utilised by other tests to handle session data processing // Zend_Session tests should pass with _unitTestEnabled turned off Zend_Session::$_unitTestEnabled = false; }
/** * Check that when using server->setSession you get an amf header that has an append to gateway sessionID * @group ZF-5381 */ public function testSessionAmf3() { Zend_Session::$_unitTestEnabled = true; Zend_Session::start(); $this->_server->setClass('Zend_Amf_testSession'); $this->_server->setSession(); // create a mock remoting message $message = new Zend_Amf_Value_Messaging_RemotingMessage(); $message->operation = 'getCount'; $message->source = 'Zend_Amf_testSession'; $message->body = array(); // create a mock message body to place th remoting message inside $newBody = new Zend_Amf_Value_MessageBody(null, "/1", $message); $request = new Zend_Amf_Request(); // at the requested service to a request $request->addAmfBody($newBody); $request->setObjectEncoding(0x3); // let the server handle mock request $result = $this->_server->handle($request); $response = $this->_server->getResponse(); $responseBody = $response->getAmfBodies(); // Now check if the return data was properly set. $acknowledgeMessage = $responseBody[0]->getData(); // check that we have a message beening returned $this->assertEquals(1, $acknowledgeMessage->body); // check that a header is being returned for the session id $headerBody = $response->getAmfHeaders(); $this->assertEquals('AppendToGatewayUrl', $headerBody[0]->name); // Do not stop session since it still can be used by other tests // Zend_Session::stop(); }
/** * set up test case */ protected function setUp() { $this->_formHelperToken = new Idun_Form_Helper_Token(); Zend_Session::$_unitTestEnabled = true; }
public function _after(\Codeception\TestCase $test) { $_SESSION = []; $_GET = []; $_POST = []; $_COOKIE = []; if ($this->bootstrap) { $fc = $this->bootstrap->getBootstrap()->getResource('frontcontroller'); if ($fc) { $fc->resetInstance(); } } \Zend_Layout::resetMvcInstance(); \Zend_Controller_Action_HelperBroker::resetHelpers(); \Zend_Session::$_unitTestEnabled = true; $this->queries = 0; $this->time = 0; }
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =========================================================================*/ error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); define('BASE_PATH', realpath(dirname(__FILE__) . '/../')); define('APPLICATION_ENV', 'testing'); define('APPLICATION_PATH', BASE_PATH . '/core'); define('LIBRARY_PATH', BASE_PATH . '/library'); define('TESTS_PATH', BASE_PATH . '/tests'); require_once BASE_PATH . '/vendor/autoload.php'; require_once BASE_PATH . '/core/include.php'; date_default_timezone_set('UTC'); Zend_Session::$_unitTestEnabled = true; Zend_Session::start(); require_once 'ControllerTestCase.php'; require_once 'DatabaseTestCase.php'; Zend_Registry::set('logger', null); $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true); $configGlobal->environment = 'testing'; Zend_Registry::set('configGlobal', $configGlobal); $config = new Zend_Config_Ini(APPLICATION_CONFIG, 'testing'); Zend_Registry::set('config', $config); $databaseIni = getenv('MIDAS_DATABASE_INI'); if (!file_exists($databaseIni)) { if (file_exists(BASE_PATH . '/tests/configs/lock.mysql.ini')) { $databaseIni = BASE_PATH . '/tests/configs/lock.mysql.ini'; } elseif (file_exists(BASE_PATH . '/tests/configs/lock.pgsql.ini')) { $databaseIni = BASE_PATH . '/tests/configs/lock.pgsql.ini';
/** * @group ZF-3378 */ public function testInvalidPreexistingSessionIdDoesNotPreventRegenerationOfSid() { // Pattern: [0-9a-v]* ini_set('session.hash_bits_per_character', 5); // Session store $sessionCharSet = array_merge(range(0, 9), range('a', 'v')); $sessionStore = dirname(__FILE__) . DIRECTORY_SEPARATOR . "_files" . DIRECTORY_SEPARATOR . "ZF-3378"; if (!is_dir($sessionStore)) { @mkdir($sessionStore, 0755, true); } ini_set('session.save_path', "1;666;" . $sessionStore); // When using subdirs for session.save_path, the directory structure // is your own responsibility...set it up, or else bad things happen foreach ($sessionCharSet as $subdir) { @mkdir($sessionStore . DIRECTORY_SEPARATOR . $subdir); } // Set session ID to invalid value session_id('xxx'); // Attempt to start the session try { /** @see Zend_Session */ require_once "Zend/Session.php"; Zend_Session::start(); } catch (Zend_Session_Exception $e) { Zend_Session::regenerateId(); } // Get the current SID $sid = Zend_Session::getId(); // We don't need the session any more, clean it up //but we don't to want to destroy it completely, while other tests can start Zend_Session::$_unitTestEnabled = true; Zend_Session::destroy(); foreach ($sessionCharSet as $subdir) { @rmdir($sessionStore . DIRECTORY_SEPARATOR . $subdir); } @rmdir($sessionStore); // Check the result $this->assertRegExp('/^[0-9a-v]+$/', $sid); $this->assertNotEquals('xxx', $sid); }
protected function setUp() { Zend_Session::$_unitTestEnabled = true; // init a mock object $this->_form = $this->getMock('Zle_Form', array('initComponents')); }
/** * Set up test case */ public function setUp() { Zend_Session::$_unitTestEnabled = true; }
public function _after(\Codeception\TestCase $test) { $_SESSION = array(); $_GET = array(); $_POST = array(); $_COOKIE = array(); $this->front = $this->bootstrap->getBootstrap()->getContainer()->frontcontroller->resetInstance(); \Zend_Layout::resetMvcInstance(); \Zend_Controller_Action_HelperBroker::resetHelpers(); \Zend_Session::$_unitTestEnabled = true; $this->queries = 0; $this->time = 0; }
/** * test for method getNamespace() * * @group ZF-1982 * @return void */ public function testGetNameSpaceMethod() { Zend_Session::$_unitTestEnabled = true; $namespace = array('FooBar', 'Foo_Bar', 'Foo-Bar', 'Foo1000'); foreach ($namespace as $v) { $s = new Zend_Session_Namespace($v); $this->assertEquals($v, $s->getNamespace()); } }
public function testLogout() { Zend_Session::$_unitTestEnabled = true; $this->_server->setAuth(new RightPassword("testuser", "testrole")); $this->_acl->addRole(new Zend_Acl_Role("testrole")); $this->_acl->allow("testrole", null, null); $this->_server->setAcl($this->_acl); $resp = $this->_callServiceAuth("testuser", ""); $this->assertTrue($resp[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage); $this->assertContains("hello", $resp[1]->getData()); // After logout same request should not be allowed $this->setUp(); $this->_server->setAuth(new RightPassword("testuser", "testrole")); $this->_server->setAcl($this->_acl); $request = new Zend_Amf_Request(); $request->setObjectEncoding(0x3); $this->_addLogout($request); $this->_addServiceCall($request); $this->_server->handle($request); $resp = $this->_server->getResponse()->getAmfBodies(); $this->assertTrue($resp[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage); $data = $resp[1]->getData(); $this->assertTrue($data instanceof Zend_Amf_Value_Messaging_ErrorMessage); $this->assertContains("not allowed", $data->faultString); }
/** * Reset MVC state * * Creates new request/response objects, resets the front controller * instance, and resets the action helper broker. * * @todo Need to update Zend_Layout to add a resetInstance() method * @return void */ public function reset() { $_SESSION = array(); $this->_request = null; $this->_response = null; Zend_Controller_Action_HelperBroker::resetHelpers(); $this->frontController->resetInstance(); Zend_Session::$_unitTestEnabled = true; }