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