Repository navigation
Expand file tree
/
Copy pathtest-c2c-plugin.php
More file actions
115 lines (85 loc) · 2.28 KB
/
Copy pathtest-c2c-plugin.php
File metadata and controls
115 lines (85 loc) · 2.28 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
defined( 'ABSPATH' ) or die();
class c2c_Plugin extends WP_UnitTestCase {
protected $obj;
public function setUp() {
parent::setUp();
add_filter( 'gettext_admin-trim-interface', array( $this, 'translate_text' ), 10, 2 );
$this->obj = c2c_AdminTrimInterface::get_instance();
}
public function tearDown() {
parent::tearDown();
}
//
//
// HELPERS
//
//
public function translate_text( $translation, $text ) {
if ( 'Donate' === $text ) {
$translation = 'Donar';
}
return $translation;
}
//
//
// DATA PROVIDERS
//
//
public static function wp_version_comparisons() {
return array(
//[ WP ver, version to compare to, operator, expected result ]
[ '5.5', '5.5.1', '>=', false ],
[ '5.5', '5.6', '>=', false ],
[ '5.5', '5.5', '>=', true ],
[ '5.5', '5.4.3', '>=', true ],
[ '5.5', '5.5.1', '', false ],
[ '5.5', '5.6', '', false ],
[ '5.5', '5.5', '', true ],
[ '5.5', '5.5', '>', false ],
[ '5.5', '5.5', '<', false ],
[ '5.5', '5.5.1', '<=', true ],
[ '5.5', '5.6', '<=', true ],
[ '5.5', '5.5', '<=', true ],
[ '5.5', '5.4.3', '<=', false ],
[ '5.5', '5.5', '=', true ],
[ '5.5', '5.5.1', '=', false ],
[ '5.5', '5.5', '!=', false ],
);
}
//
//
// TESTS
//
//
/*
* is_wp_version_cmp()
*/
/**
* @dataProvider wp_version_comparisons
*/
public function test_is_wp_version_cmp( $wp_ver, $ver, $op, $expected ) {
global $wp_version;
$orig_wp_verion = $wp_version;
$wp_version = $wp_ver;
$this->{ $expected ? 'assertTrue' : 'assertFalse' }( $this->obj->is_wp_version_cmp( $ver, $op ) );
$wp_version = $orig_wp_verion;
}
/*
* get_c2c_string()
*/
public function test_get_c2c_string_size() {
$this->assertEquals( 21, count( $this->obj->get_c2c_string( '' ) ) );
}
public function test_get_c2c_string_for_unknown_string() {
$str = 'unknown string';
$this->assertEquals( $str, $this->obj->get_c2c_string( $str ) );
}
public function test_get_c2c_string_for_known_string_translated() {
$this->assertEquals( 'Donar', $this->obj->get_c2c_string( 'Donate' ) );
}
public function test_get_c2c_string_for_known_string_untranslated() {
$str = 'A value is required for: "%s"';
$this->assertEquals( $str, $this->obj->get_c2c_string( $str ) );
}
}