/** * Create a controller instance * * @param string $classname * @return CI_Controller */ public function newController($classname) { reset_instance(); $controller = new $classname(); $this->CI =& get_instance(); return $controller; }
/** * Reset CodeIgniter instance and assign new CodeIgniter instance as $this->CI */ public function resetInstance() { reset_instance(); if (!CIPHPUnitTest::wiredesignzHmvcInstalled()) { new CI_Controller(); } else { new CI(); new MX_Controller(); } $this->CI =& get_instance(); }
public function test_get_category_list() { // Create mock objects for CI_DB_pdo_result and CI_DB_pdo_sqlite_driver $return = [0 => (object) ['id' => '1', 'name' => 'Book'], 1 => (object) ['id' => '2', 'name' => 'CD'], 2 => (object) ['id' => '3', 'name' => 'DVD']]; $db_result = $this->getMockBuilder('CI_DB_pdo_result')->disableOriginalConstructor()->getMock(); $db_result->method('result')->willReturn($return); $db = $this->getMockBuilder('CI_DB_pdo_sqlite_driver')->disableOriginalConstructor()->getMock(); $db->method('get')->willReturn($db_result); // Verify invocations $this->verifyInvokedOnce($db_result, 'result', []); $this->verifyInvokedOnce($db, 'order_by', ['id']); $this->verifyInvokedOnce($db, 'get', ['category']); // Replace property db with mock object $this->obj->db = $db; $expected = [1 => 'Book', 2 => 'CD', 3 => 'DVD']; $list = $this->obj->get_category_list(); foreach ($list as $category) { $this->assertEquals($expected[$category->id], $category->name); } // Reset CI object for next test case, unless property db won't work reset_instance(); new CI_Controller(); }
/** * Reset CodeIgniter instance and assign new CodeIgniter instance as $this->CI */ public function resetInstance() { reset_instance(); new CI_Controller(); $this->CI =& get_instance(); }
/** * Request to URI * * @param string $http_method HTTP method * @param string $uri URI string * @param array|string $request_params POST params/GET params|raw_input_stream */ protected function requestUri($http_method, $uri, $request_params) { $_SERVER['argv'] = ['index.php', $uri]; // Force cli mode because if not, it changes URI (and RTR) behavior $cli = is_cli(); set_is_cli(TRUE); // Reset CodeIgniter instance state reset_instance(); $this->setRawInputStream($request_params); // Get route list($class, $method, $params) = $this->router->getRoute(); // Restore cli mode set_is_cli($cli); // $request = [ // 'REQUEST_METHOD' => $_SERVER['REQUEST_METHOD'], // 'class' => $class, // 'method' => $method, // 'params' => $params, // '$_GET' => $_GET, // '$_POST' => $_POST, // ]; // var_dump($request, $_SERVER['argv']); return $this->createAndCallController($class, $method, $params); }
/** * Request to URI * * @param string $http_method HTTP method * @param string $uri URI string * @param array $request_params POST parameters/Query string * @param callable $callable [deprecated] function to run after controller instantiation. Use setCallable() method instead */ protected function requestUri($http_method, $uri, $request_params, $callable = null) { $_SERVER['REQUEST_METHOD'] = $http_method; $_SERVER['argv'] = ['index.php', $uri]; if ($http_method === 'POST') { $_POST = $request_params; } elseif ($http_method === 'GET') { $_GET = $request_params; } // Force cli mode because if not, it changes URI (and RTR) behavior $cli = is_cli(); set_is_cli(TRUE); // Reset CodeIgniter instance state reset_instance(); // Get route $RTR =& load_class('Router', 'core'); $URI =& load_class('URI', 'core'); list($class, $method, $params) = $this->getRoute($RTR, $URI); // Restore cli mode set_is_cli($cli); // $request = [ // 'REQUEST_METHOD' => $_SERVER['REQUEST_METHOD'], // 'class' => $class, // 'method' => $method, // 'params' => $params, // '$_GET' => $_GET, // '$_POST' => $_POST, // ]; // var_dump($request, $_SERVER['argv']); // @deprecated if (is_callable($callable)) { $this->callable = $callable; } return $this->createAndCallController($class, $method, $params); }
/** * Request to URI * * @param string $http_method HTTP method * @param string $uri URI string * @param array $params POST parameters/Query string * @param callable $callable */ protected function requestUri($method, $uri, $params = [], $callable = null) { $_SERVER['REQUEST_METHOD'] = $method; $_SERVER['argv'] = ['index.php', $uri]; if ($method === 'POST') { $_POST = $params; } elseif ($method === 'GET') { $_GET = $params; } // Force cli mode because if not, it changes URI (and RTR) behavior $cli = is_cli(); set_is_cli(TRUE); // Reset CodeIgniter instance state reset_instance(); // Get route $RTR =& load_class('Router', 'core'); $URI =& load_class('URI', 'core'); list($class, $method, $params) = $this->getRoute($RTR, $URI); // Restore cli mode set_is_cli($cli); // $request = [ // 'REQUEST_METHOD' => $_SERVER['REQUEST_METHOD'], // 'class' => $class, // 'method' => $method, // 'params' => $params, // '$_GET' => $_GET, // '$_POST' => $_POST, // ]; // var_dump($request, $_SERVER['argv']); // Create controller $this->obj = new $class(); $this->CI =& get_instance(); if (is_callable($callable)) { $callable($this->CI); } // Call controller method ob_start(); call_user_func_array([$this->obj, $method], $params); $output = ob_get_clean(); if ($output == '') { $output = $this->CI->output->get_output(); } return $output; }
/** * Reset CodeIgniter instance and assign new CodeIgniter instance as $this->CI */ public function resetInstance() { reset_instance(); CIPHPUnitTest::createCodeIgniterInstance(); $this->CI =& get_instance(); }
/** * This function is used by the reset_course_userdata function in moodlelib. * This function will remove all posts from the specified forum * and clean up any related data. * * @global object * @param $data the data submitted from the reset course. * @return array status array */ function hotquestion_reset_userdata($data) { global $DB; $status = array(); if (!empty($data->reset_hotquestion)) { $instances = $DB->get_records('hotquestion', array('course' => $data->courseid)); foreach ($instances as $instance) { if (reset_instance($instance->id)) { $status[] = array('component' => get_string('modulenameplural', 'hotquestion'), 'item' => get_string('resethotquestion', 'hotquestion') . ': ' . $instance->name, 'error' => false); } } } return $status; }
/** * Get new CodeIgniter instance * @deprecated * * @return CI_Controller */ function get_new_instance() { reset_instance(); $controller = new CI_Controller(); return $controller; }