public function testDelElement() { $reg = new Registry(); $element = array("numbers" => array(1, 2, 3, 4, 5), "letters" => array("a", "b", "c", "...")); $reg->add($element); $count = $reg->elementCount(); $this->assertEqual(1, $count); $reg->delete($element); $count = $reg->elementCount(); $this->assertEqual(0, $count); }
/** * Helper function for testTrustXForwardedFor tests that prepares the * environment * * @param $generalConfigData mixed Array containing overwrites for the * general section of the config */ private function getRemoteAddrTestPrepare($generalConfigData = array()) { // Remove cached IP address from registry Registry::delete('remoteIpAddr'); $_SERVER['HTTP_X_FORWARDED_FOR'] = '1.1.1.1'; $_SERVER['REMOTE_ADDR'] = '2.2.2.2'; $configData =& Registry::get('configData', true, array()); $configData['general'] = $generalConfigData; return array($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); }
/** * Mock a web request. * * For correct timing you have to call this method * in the setUp() method of a test after calling * parent::setUp() or in a test method. You can also * call this method as many times as necessary from * within your test and you're guaranteed to receive * a fresh request whenever you call it. * * And make sure that you merge any additional mocked * registry keys with the ones returned from this class. * * @param $path string * @param $userId int * * @return Request */ protected function mockRequest($path = 'index/test-page/test-op', $userId = null) { // Back up the default request. if (!isset($this->registryBackup['request'])) { $this->mockedRegistryKeys[] = 'request'; $this->registryBackup['request'] = Registry::get('request'); } // Create a test request. Registry::delete('request'); $application = PKPApplication::getApplication(); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['PATH_INFO'] = $path; $request = $application->getRequest(); import('classes.core.PageRouter'); // Test router. $router = new PageRouter(); $router->setApplication($application); import('lib.pkp.classes.core.Dispatcher'); $dispatcher = new Dispatcher(); $dispatcher->setApplication($application); $router->setDispatcher($dispatcher); $request->setRouter($router); // Test user. $session = $request->getSession(); $session->setUserId($userId); return $request; }