[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/t/ -> test_urls.php (source)

   1  <?php
   2  require_once ('init.php');
   3  
   4  class GP_Test_Urls extends GP_UnitTestCase {
   5      
   6  	function setUp() {
   7          $this->sub_dir = '/gp/';
   8          $this->url = 'http://example.org' . $this->sub_dir;
   9          parent::setUp();
  10      }
  11      
  12      function test_gp_url_should_just_add_simple_path_string_if_query_is_missing() {
  13          $this->assertEquals( $this->sub_dir . 'baba', gp_url( 'baba' ) );
  14      }
  15      function test_gp_url_should_not_add_query_string_if_query_is_empty_string() {
  16          $this->assertEquals( $this->sub_dir . 'baba', gp_url( 'baba', '' ) );
  17      }
  18      
  19      function test_gp_url_should_not_add_query_string_if_query_is_empty_array() {
  20          $this->assertEquals( $this->sub_dir . 'baba', gp_url( 'baba', array() ) );
  21      }
  22  
  23      function test_gp_url_should_properly_add_query_string_if_path_is_empty() {
  24          $this->assertEquals( $this->sub_dir . '?a=b', gp_url( '', '?a=b' ) );
  25      }
  26  
  27      function test_gp_url_should_add_question_mark_if_query_string_does_not_have_one() {
  28          $this->assertEquals( $this->sub_dir . 'baba?a=b', gp_url( 'baba', 'a=b' ) );
  29      }
  30          
  31  	function test_gp_url_should_expand_query_array() {
  32          $this->assertEquals( $this->sub_dir . '?a=b', gp_url( '', array('a' => 'b') ) );
  33      }
  34          
  35      function test_gp_url_should_add_ampersand_if_path_is_empty_and_query_array_has_more_than_one_value() {
  36          $this->assertEquals( $this->sub_dir . '?a=b&b=c', gp_url( '', array('a' => 'b', 'b' => 'c') ) );
  37      }
  38  
  39      function test_gp_url_should_add_ampersand_if_query_array_has_more_than_one_value() {
  40          $this->assertEquals( $this->sub_dir . 'baba?a=b&b=c', gp_url( 'baba', array('a' => 'b', 'b' => 'c') ) );
  41      }
  42          
  43      function test_gp_url_should_not_add_double_slash_if_path_starts_with_slash() {
  44          $this->assertEquals( $this->sub_dir . 'baba/wink', gp_url( '/baba/wink' ) );
  45      }
  46      
  47  	function test_gp_url_should_urlencode_query_var_values() {
  48          $this->assertEquals( $this->sub_dir . 'baba?a=a%26b&b=c', gp_url( 'baba', array('a' => 'a&b', 'b' => 'c') ) );
  49      }
  50      
  51      function test_gp_url_join_should_return_the_string_if_single_string_without_slashes_is_passed() {
  52          $this->assertEquals( 'baba', gp_url_join( 'baba' ) );
  53      }
  54      
  55      function test_gp_url_join_should_join_with_slash_two_strings_without_slashes() {
  56          $this->assertEquals( 'baba/dyado', gp_url_join( 'baba', 'dyado' ) );
  57      }
  58      
  59      function test_gp_url_join_should_include_only_one_slash_if_first_string_ends_with_slash_and_next_begins_with_slash() {
  60          $this->assertEquals( 'baba/dyado', gp_url_join( 'baba/', '/dyado' ) );
  61      }
  62      
  63      function test_gp_url_join_should_discard_multiple_slashes_in_the_end_of_component() {
  64          $this->assertEquals( '/baba/dyado', gp_url_join( '/baba//', 'dyado' ) );
  65      }
  66      
  67      function test_gp_url_join_should_discard_multiple_slashes_in_the_beginning_of_component() {
  68          $this->assertEquals( '/baba/dyado', gp_url_join( '/baba/', '//dyado' ) );
  69      }
  70  
  71      function test_gp_url_join_should_not_discard_slash_if_the_whole_first_component_is_slash() {
  72              $this->assertEquals( '/baba/', gp_url_join( '/baba/', '/' ) );
  73              $this->assertEquals( '/baba/', gp_url_join( '/baba/', '//' ) );
  74      }
  75  
  76      function test_gp_url_join_should_not_discard_slash_if_the_whole_last_component_is_slash() {
  77              $this->assertEquals( '/baba/', gp_url_join( '/', '/baba/' ) );
  78              $this->assertEquals( '/baba/', gp_url_join( '//', '/baba/' ) );
  79      }
  80      
  81      function test_gp_url_join_should_return_only_one_slash_if_the_only_component_is_a_slash() {
  82          $this->assertEquals( '/', gp_url_join( '/' ) );
  83      }
  84      
  85      function test_gp_url_join_should_return_only_one_slash_if_all_components_are_slashes() {
  86          $this->assertEquals( '/', gp_url_join( '/', '/' ) );
  87      }
  88      
  89      function test_gp_url_join_should_return_only_one_slash_if_all_components_are_multiple_slashes() {
  90          $this->assertEquals( '/', gp_url_join( '///', '///' ) );
  91      }
  92      
  93  	function test_gp_url_join_should_skip_empty_components() {
  94          $this->assertEquals( 'a/b', gp_url_join( 'a', '', 'b' ) );
  95      }
  96      
  97  	function test_gp_url_join_should_skip_empty_components_in_the_beginning() {
  98          $this->assertEquals( 'a/b', gp_url_join( '', 'a', 'b' ) );
  99      }
 100  
 101  	function test_gp_url_join_should_skip_empty_components_in_the_end() {
 102          $this->assertEquals( 'a/b', gp_url_join( 'a', 'b', '' ) );
 103      }
 104          
 105      function test_gp_url_join_should_accept_array_component_with_one_element_and_return_this_element() {
 106          $this->assertEquals( 'baba', gp_url_join( array( 'baba' ) ) );
 107      }
 108      
 109      function test_gp_url_join_should_join_array_component_values_as_if_they_were_given_as_different_arguments() {
 110          $this->assertEquals( 'baba/dyado', gp_url_join( array( 'baba', 'dyado' ) ) );
 111      }
 112      
 113  	function test_gp_url_join_should_flatten_nested_arrays() {
 114          $this->assertEquals( 'baba/dyado/chicho/lelya', gp_url_join( array( 'baba', array( 'dyado', array( 'chicho' ), 'lelya' ) ) ) );
 115      }
 116      
 117      function test_gp_url_join_should_return_empty_string_with_nested_empty_arrays() {
 118          $this->assertEquals( '', gp_url_join( array( array() ), array() ) );
 119      }
 120      
 121  	function test_gp_url_join_should_not_break_http() {
 122          $this->assertEquals( 'http://dir.bg/baba', gp_url_join( 'http://dir.bg/', 'baba' ) );
 123      }
 124      
 125  	function test_gp_url_project_should_join_its_arguments() {
 126          $url_from_gp_url_project = gp_url_project( '/x', 'import-originals' );
 127          $url_manually_joined = gp_url_join( gp_url_project( '/x' ), 'import-originals' );
 128           $this->assertEquals( $url_manually_joined, $url_from_gp_url_project );
 129      }
 130      function test_gp_url_project_should_join_its_array_arguments() {
 131          $url_from_gp_url_project = gp_url_project( '/x', array( 'slug', 'slugslug', 'import-translations' ) );
 132          $url_manually_joined = gp_url_join( gp_url_project( '/x' ), 'slug', 'slugslug', 'import-translations' );
 133          $this->assertEquals( $url_manually_joined, $url_from_gp_url_project );
 134      }    
 135  }


Generated: Thu May 24 03:59:35 2012 Hosted by follow the white rabbit.