public function testDoi() { // Mock a router. $router = new PKPRouter(); $application = PKPApplication::getApplication(); $router->setApplication($application); // Mock a request. $mockRequest = $this->getMock('PKPRequest', array('getRouter', 'getJournal')); $mockRequest->expects($this->any())->method('getRouter')->will($this->returnValue($router)); $mockRequest->expects($this->any())->method('getJournal')->will($this->returnValue(null)); Registry::set('request', $mockRequest); // Retrieve test article from test database. $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId(1); // Create a SWORD deposit package. $deposit = new OJSSwordDeposit($publishedArticle); $deposit->setMetadata(); // Test DOI. self::assertEquals('10.1234/t.v1i1.1', $deposit->package->sac_identifier); // FIXME: Current requirement is only for a DOI regression test. Test whole package if required. }
$curDir = dirname(dirname(__FILE__)); // Load system files, initialize if (basename($_SERVER['SCRIPT_FILENAME'], ".php") == "rfiles") { $baseDir = dirname($baseDir); } define('INDEX_FILE_LOCATION', $baseDir . '/index.php'); // Load and execute initialization code chdir($baseDir); require $baseDir . '/lib/pkp/includes/bootstrap.inc.php'; // Manually set up a context router to get access // to the application context (required by Locale). $application =& PKPApplication::getApplication(); $request =& $application->getRequest(); import('core.PKPRouter'); $router = new PKPRouter(); $router->setApplication($application); $request->setRouter($router); Locale::initialize(); // Load user variables $sessionManager =& SessionManager::getManager(); $userSession =& $sessionManager->getUserSession(); $user =& $userSession->getUser(); // Insert system variables into associative array to be used by iBrowser $init['publicDir'] = Config::getVar('files', 'public_files_dir'); if (isset($user)) { // User is logged in $init['user'] = $user->getUsername(); //$init['lang'] = String::substr(Locale::getLocale(), 0, 2); $init['lang'] = 'en'; $init['baseUrl'] = Config::getVar('general', 'base_url'); $init['baseDir'] = $baseDir;
/** * Mocks the context of an application by manipulating * the registered DAOs. * @param $contextIds array an array of context IDs to be set up. * Missing IDs will be replaced with null. * @param $userId the user id to be returned by the request */ private function mockContext($contextIds, $userId) { $application = PKPApplication::getApplication(); // Mock the context if (count($contextIds)) { $_SERVER['PATH_INFO'] = '/' . implode('/', array_fill(0, count($contextIds), 'context')) . '/'; } else { $_SERVER['PATH_INFO'] = '/'; } foreach ($application->getContextList() as $contextName) { // Get a mock DAO for the requested context. $contextClass = ucfirst($contextName); $daoName = $contextClass . 'DAO'; $daoMethod = 'get' . $contextClass . 'ByPath'; $mockContextDao = $this->getMock($daoName, array($daoMethod)); // Set up the mock context retrieval method $mockContextDao->expects($this->any())->method($daoMethod)->will($this->returnValue($this->getMockContext($contextClass, array_shift($contextIds)))); // Register the mock context DAO DAORegistry::registerDAO($daoName, $mockContextDao); unset($mockContextDao); } // Mock the UserDAO and the session with a test user if (is_null($userId)) { $user = null; } else { $user = new User(); $user->setId($userId); } $mockUserDao = $this->getMock('UserDAO', array('getUser')); $mockUserDao->expects($this->any())->method('getUser')->will($this->returnValue($user)); DAORegistry::registerDAO('UserDAO', $mockUserDao); $sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $session->setUserId($userId); // Mock the request $mockRequest = $this->getMock('Request', array('getRouter', 'getBasePath', 'getRemoteAddr', 'getUserAgent')); $router = new PKPRouter(); $router->setApplication($application); $mockRequest->expects($this->any())->method('getRouter')->will($this->returnValue($router)); $mockRequest->expects($this->any())->method('getBasePath')->will($this->returnValue('/')); $mockRequest->expects($this->any())->method('getRemoteAddr')->will($this->returnValue('')); $mockRequest->expects($this->any())->method('getUserAgent')->will($this->returnValue('')); Registry::set('request', $mockRequest); }