[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  class GP_UnitTestCase_Route extends GP_UnitTestCase {
   4      var $route;
   5      var $route_class;
   6  
   7  	function setUp() {
   8          parent::setUp();
   9          $this->route = new $this->route_class;
  10          $this->route->fake_request = true;
  11          $this->route->errors = array();
  12          $this->route->notices = array();
  13      }
  14  
  15  	function assertRedirected() {
  16          $this->assertTrue( $this->route->redirected, "Wasn't redirected" );
  17      }
  18  
  19  	function assertRedirectURLContains( $text ) {
  20          $this->assertRedirected();
  21          $this->assertContains( $text, $this->route->redirected_to );
  22      }
  23  
  24  	function assertThereIsAnErrorContaining( $text ) {
  25          $this->assertThereIsAnArrayElementContaining( $text, $this->route->errors, "No error contains '$text'" );
  26      }
  27  
  28  	function assertThereIsANoticeContaining( $text ) {
  29          $this->assertThereIsAnArrayElementContaining( $text, $this->route->notices, "No notice contains '$text'" );
  30      }
  31  
  32  	function assertThereIsAnArrayElementContaining( $text, $array, $message = null ) {
  33          $this->assertGreaterThan( 0, count( $array ), 'The array is empty.' );
  34          $message = $message? $message : "No array element contains '$text'";
  35  
  36          $this->assertTrue( gp_array_any( function( $e ) use ( $text) { return gp_in( $text, $e ); }, $array ), $message );
  37      }
  38  
  39  	function assertNotAllowedRedirect() {
  40          $this->assertRedirected();
  41          $this->assertThereIsAnErrorContaining( 'allowed' );
  42      }
  43  
  44  	function assertInvalidNonceRedirect() {
  45          $this->assertRedirected();
  46          $this->assertThereIsAnErrorContaining( 'occurred' );
  47      }
  48  
  49  	function assertInvalidRedirect() {
  50          $this->assertRedirected();
  51          $this->assertThereIsAnErrorContaining( 'invalid' );
  52      }
  53  
  54  	function assertErrorRedirect() {
  55          $this->assertRedirected();
  56          $this->assertThereIsAnErrorContaining( 'Error' );
  57      }
  58  
  59  	function assertTemplateLoadedIs( $template ) {
  60          $this->assertTrue( $this->route->rendered_template, "No template was rendered" );
  61          $this->assertEquals( $template, $this->route->loaded_template );
  62      }
  63  
  64  	function assertTemplateOutputNotEmpty() {
  65          $this->assertFalse( empty( $this->route->template_output ), "Template output is empty" );
  66      }
  67  
  68  	function assert404() {
  69          $this->assertTemplateLoadedIs( '404' );
  70      }
  71  
  72    /**
  73     * Parses and returns the API response.
  74     */
  75    function api_response() {
  76      return json_decode( $this->route->template_output );
  77    }
  78  
  79  }


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1