[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/testcases/ -> test_strings.php (source)

   1  <?php
   2  
   3  /**
   4   * @group strings
   5   */
   6  class GP_Test_Strings extends GP_UnitTestCase {
   7  	function test_gp_string_similarity() {
   8          $string1 = 'Word';
   9          $string2 = 'Word!';
  10          $string3 = 'Word';
  11  
  12          $similarity = gp_string_similarity( $string1, $string2 );
  13          $similarity_2 = gp_string_similarity( $string1, $string3 );
  14  
  15          $this->assertEquals( $similarity, 0.775 );
  16          $this->assertEquals( $similarity_2, 1 );
  17      }
  18  
  19      /**
  20       * @dataProvider data_attributes_with_entities
  21       */
  22  	function test_gp_esc_attr_with_entities( $expected, $attribute ) {
  23          $this->assertEquals( $expected, gp_esc_attr_with_entities( $attribute ) );
  24      }
  25  
  26  	function data_attributes_with_entities() {
  27          return array(
  28              array( '&amp;#8212;', '&#8212;' ), // https://glotpress.trac.wordpress.org/ticket/12
  29              array( 'Foo &amp; Bar', 'Foo & Bar' ),
  30              array( '&quot;&amp;hellip;&quot;', '"&hellip;"' ),
  31          );
  32      }
  33  
  34      /**
  35       * @dataProvider data_translations_with_entities
  36       */
  37  	function test_esc_translation( $expected, $translation ) {
  38          $this->assertEquals( $expected, esc_translation( $translation ) );
  39      }
  40  
  41  	function data_translations_with_entities() {
  42          return array(
  43              array( 'Foo bar&amp;hellip;', 'Foo bar&hellip;' ),
  44              array( 'Foo &lt;span class="count"&gt;(%s)&lt;/span&gt;', 'Foo <span class="count">(%s)</span>' ),
  45              array( '"&amp;hellip;"', '"&hellip;"' ),
  46          );
  47      }
  48  
  49  	function test_gp_sanitize_project_name() {
  50          $this->assertEquals( gp_sanitize_slug( 'plugin V1.2.1' ), 'plugin-v1.2.1' );
  51          $this->assertEquals( gp_sanitize_slug( 'plugin \/<1.2.1>' ), 'plugin' );
  52          $this->assertEquals( gp_sanitize_slug( 'GlotPress&Plugin@1.1.1' ), 'glotpressplugin1.1.1' );
  53      }
  54  }


Generated: Sun Dec 22 01:01:04 2024 Cross-referenced by PHPXref 0.7.1