/** * @see PKPTestCase::setUp() */ protected function setUp() { parent::setUp(); // We need a router for URL generation. $application = PKPApplication::getApplication(); $_SERVER['REQUEST_METHOD'] = 'GET'; $request = $application->getRequest(); if (!is_a($request->getRouter(), 'PKPRouter')) { $router = new PageRouter(); $router->setApplication($application); $request->setRouter($router); } // Add the indexing state as setting. HookRegistry::register('articledao::getAdditionalFieldNames', array($this, 'callbackAdditionalFieldNames')); // Set translations. This must be done early // as these translations will be saved statically // during the first request. AppLocale::setTranslations(array('search.operator.not' => 'nicht', 'search.operator.and' => 'und', 'search.operator.or' => 'oder')); // Instantiate our web service for testing. $this->solrWebService = new SolrWebService('http://localhost:8983/solr/ojs/search', 'admin', 'please change', 'test-inst'); }
function CommandLineTool($argv = array()) { // Initialize the a request object with a page router $application =& PKPApplication::getApplication(); $request =& $application->getRequest(); // FIXME: Write and use a CLIRouter here (see classdoc) import('classes.core.PageRouter'); $router = new PageRouter(); $router->setApplication($application); $request->setRouter($router); // Initialize the locale and load generic plugins. AppLocale::initialize(); PluginRegistry::loadCategory('generic'); $this->argv = isset($argv) && is_array($argv) ? $argv : array(); if (isset($_SERVER['SERVER_NAME'])) { die('This script can only be executed from the command-line'); } $this->scriptName = isset($this->argv[0]) ? array_shift($this->argv) : ''; if (isset($this->argv[0]) && $this->argv[0] == '-h') { $this->usage(); exit(0); } }
function main() { global $gvPath; // Get the requested page $requestUri = str_replace($gvPath, '', $_SERVER['REQUEST_URI']); // Remove query string $requestUri = preg_replace('/^([^?]*)(\\?.*)?$/', '$1', $requestUri); // Remove optional first slash if (strpos($requestUri, '/') === 0 && strlen($requestUri) >= 2) { $requestUri = substr($requestUri, 1); } // Remove optional trailing slashes $requestUri = preg_replace('#^(.*)/+$#', '$1', $requestUri); gfDebug("RequestUri: {$requestUri}"); Session::start(); $userLevel = $_SESSION['userLevel']; $target = PageRouter::getClassOrRedirect($requestUri); if (is_object($target)) { $target->output(); return; } else { $page = new $target(); } if (!$page->canUse($userLevel)) { $redirect = new RedirectOutput($gvPath . "/application/loginPage"); $redirect->output(); return; } $page->afterPermissionCheck(); $output = true; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // execute() returns true, false or an Output object // True means: get the output of the page and show it // False means: something has already been sent as output, do nothing // Output object means: output the object that is returned $output = $page->execute(); } if ($output) { // True or object if (!is_object($output)) { $output = $page->getOutput(); } $output->output(); } }
/** * Fake a router for CLI tests. * @return Request */ protected function fakeRouter($host = null) { if ($host) { $_SERVER['HTTP_HOST'] = $host; } $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PATH_INFO'] = '/test'; $application = PKPApplication::getApplication(); $request = $application->getRequest(); import('classes.core.PageRouter'); $router = new PageRouter(); $router->setApplication($application); $request->setRouter($router); return $request; }
/** * 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; }
* @class fbvVisualResults * @ingroup tools * * @brief Tool that generates a page containing the visual presentation of forms coded with the form builder vocabulary. * Use this tool to quickly inspect the results of an fbv-coded test form within the context of the application. * @see lib/pkp/tests/ui/fbv/* */ define('INDEX_FILE_LOCATION', dirname(dirname(__FILE__)) . '/index.php'); chdir(dirname(INDEX_FILE_LOCATION)); /* Change to base directory */ require 'lib/pkp/includes/bootstrap.inc.php'; $application = PKPApplication::getApplication(); $request = $application->getRequest(); // FIXME: Write and use a CLIRouter here (see classdoc) import('classes.core.PageRouter'); $router = new PageRouter(); $router->setApplication($application); $request->setRouter($router); import('classes.template.TemplateManager'); import('lib.pkp.classes.form.Form'); // Extend the TemplateManager class to: // - access test templates // - adjust $baseUrl to obtain proper paths to application js+css // - prevent the creation of urls from within templates // - modify the initialization procedure, // allowing Form::display() to use FBVTemplateManager class FBVTemplateManager extends TemplateManager { function FBVTemplateManager() { parent::TemplateManager();