[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/lib/ -> testcase-request.php (source)

   1  <?php
   2  
   3  class GP_UnitTestCase_Request extends GP_UnitTestCase {
   4      var $body = null;
   5  
   6      function get( $uri, $get_vars = array() ) {
   7          $this->request( $uri, 'GET', $get_vars );
   8      }
   9  
  10      function post( $uri, $get_vars = array() ) {
  11          $this->request( $uri, 'POST', $get_vars );
  12      }
  13  
  14      private function request( $uri, $method, $vars ) {
  15          $tmp_file_name = tempnam( sys_get_temp_dir(), 'gp-test-request-config' );
  16          if ( !$tmp_file_name) {
  17              return false;
  18          }
  19          $config_vars = array(
  20              'upper_method' => strtoupper( $method ),
  21              'vars' => $vars,
  22              'uri' => $uri,
  23              'gp_config_path' => dirname( __FILE__ ) . '/../unittests-config.php',
  24          );
  25          extract( array_map( function( $value ) {
  26              return var_export( $value, true );
  27              },
  28              $config_vars )
  29          );
  30          $config_php_code = <<<CONFIG
  31  <?php
  32  \$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
  33  \$_SERVER['REQUEST_URI'] = $uri;
  34  \$GLOBALS['_'.$upper_method] = $vars;
  35  \$_SERVER['REQUEST_METHOD'] = $upper_method;
  36  define( 'GP_CONFIG_FILE', $gp_config_path );
  37  CONFIG;
  38          file_put_contents( $tmp_file_name, $config_php_code );
  39          ob_start();
  40          /* We need to start a new PHP process, because header() doesn't like previous output and we have plenty */
  41          system('php '.escapeshellarg( dirname( __FILE__ ) . '/../bin/request.php' ).' '.escapeshellarg( $tmp_file_name ) );
  42          /* We can't get the headers, because there is no way to tell the CLI SAPI to return them */
  43          $this->body = ob_get_contents();
  44          ob_end_clean();
  45      }
  46  
  47      function assertRedirect() {
  48          $this->assertTrue( gp_startswith( $this->body, 'Redirecting to: ') );
  49      }
  50  
  51      function assertResponseContains( $needle ) {
  52          $this->assertTrue( gp_in( $needle, $this->body ) );
  53      }
  54  
  55      function assertResponseNotContains( $needle ) {
  56          $this->assertFalse( gp_in( $needle, $this->body ) );
  57      }
  58  }


Generated: Sun Nov 24 01:01:03 2024 Cross-referenced by PHPXref 0.7.1