コード例 #1
0
 public function test_index()
 {
     set_is_cli(FALSE);
     $this->warningOff();
     $output = $this->request('GET', ['cli', 'index']);
     $this->warningOn();
     set_is_cli(TRUE);
     $expected = 'Okay';
     $this->assertEquals($expected, $output);
 }
コード例 #2
0
    public function test_users_get_id_query_string_format_xml_uri_query_string()
    {
        set_is_cli(FALSE);
        //		$this->warningOff();
        $output = $this->request('GET', 'api/example/users/id/1?format=xml');
        set_is_cli(TRUE);
        //		$this->warningOn();
        $this->assertEquals('<?xml version="1.0" encoding="utf-8"?>
<xml><id>1</id><name>John</name><email>john@example.com</email><fact>Loves coding</fact></xml>
', $output);
        $this->assertResponseCode(200);
    }
コード例 #3
0
    public function test_index_delete()
    {
        set_is_cli(FALSE);
        $this->warningOff();
        try {
            $output = $this->request('DELETE', 'api/rest_test?name=John%20O%27reilly&city=Tokyo', 'id=abc&password=xyz');
        } catch (CIPHPUnitTestExitException $e) {
            $output = ob_get_clean();
        }
        set_is_cli(TRUE);
        $this->warningOn();
        $expected = <<<'EOL'
{"delete":{"id":"abc","password":"******"},"query":{"name":"John O'reilly","city":"Tokyo"}}
EOL;
        $this->assertEquals($expected, $output);
        $this->assertResponseCode(200);
    }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
ファイル: CIPHPUnitTestCase.php プロジェクト: Nsity/eschool
 /**
  * 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;
 }