@@ -17,25 +17,25 @@ public function get_test(): MslsOptions {
17
17
return new MslsOptions ();
18
18
}
19
19
20
- public function test_is_main_page_method (): void {
20
+ public function test_is_main_page (): void {
21
21
Functions \when ( 'is_front_page ' )->justReturn ( true );
22
22
23
23
$ this ->assertIsBool ( MslsOptions::is_main_page () );
24
24
}
25
25
26
- public function test_is_tax_page_method (): void {
26
+ public function test_is_tax_page (): void {
27
27
Functions \when ( 'is_category ' )->justReturn ( true );
28
28
29
29
$ this ->assertIsBool ( MslsOptions::is_tax_page () );
30
30
}
31
31
32
- public function test_is_query_page_method (): void {
32
+ public function test_is_query_page (): void {
33
33
Functions \when ( 'is_date ' )->justReturn ( true );
34
34
35
35
$ this ->assertIsBool ( MslsOptions::is_query_page () );
36
36
}
37
37
38
- public function test_create_method (): void {
38
+ public function test_create (): void {
39
39
$ post_type = \Mockery::mock ( MslsPostType::class );
40
40
$ post_type ->shouldReceive ( 'is_taxonomy ' )->once ()->andReturnFalse ();
41
41
@@ -47,7 +47,7 @@ public function test_create_method(): void {
47
47
$ this ->assertInstanceOf ( MslsOptions::class, MslsOptions::create () );
48
48
}
49
49
50
- public function test_get_arg_method (): void {
50
+ public function test_get_arg (): void {
51
51
$ obj = $ this ->get_test ();
52
52
53
53
$ this ->assertNull ( $ obj ->get_arg ( 0 ) );
@@ -56,73 +56,95 @@ public function test_get_arg_method(): void {
56
56
$ this ->assertIsArray ( $ obj ->get_arg ( 0 , array () ) );
57
57
}
58
58
59
- function test_set_method (): void {
59
+ public function test_save (): void {
60
+ $ arr = array (
61
+ 'de_DE ' => 1 ,
62
+ 'it_IT ' => 2 ,
63
+ );
64
+
65
+ Functions \expect ( 'delete_option ' )->once ()->with ( 'msls ' );
66
+ Functions \expect ( 'add_option ' )->once ()->with ( 'msls ' , $ arr , '' , true );
67
+
60
68
$ obj = $ this ->get_test ();
61
69
62
- $ this ->assertTrue ( $ obj ->set ( array () ) );
63
- $ this ->assertTrue (
64
- $ obj ->set (
70
+ $ this ->expectNotToPerformAssertions ();
71
+ $ obj ->save ( $ arr );
72
+ }
73
+
74
+ public static function set_provider (): array {
75
+ return array (
76
+ array ( true , array () ),
77
+ array (
78
+ true ,
65
79
array (
66
80
'temp ' => 'abc ' ,
67
81
'en ' => 1 ,
68
82
'us ' => 2 ,
69
- )
70
- )
83
+ ),
84
+ ),
85
+ array ( false , 'Test ' ),
86
+ array ( false , 1 ),
87
+ array ( false , 1.1 ),
88
+ array ( false , null ),
89
+ array ( false , new \stdClass () ),
71
90
);
91
+ }
92
+
93
+ /**
94
+ * @dataProvider set_provider
95
+ */
96
+ function test_set ( $ expected , $ input ): void {
97
+ $ obj = $ this ->get_test ();
72
98
73
- $ this ->assertFalse ( $ obj ->set ( 'Test ' ) );
74
- $ this ->assertFalse ( $ obj ->set ( 1 ) );
75
- $ this ->assertFalse ( $ obj ->set ( 1.1 ) );
76
- $ this ->assertFalse ( $ obj ->set ( null ) );
77
- $ this ->assertFalse ( $ obj ->set ( new \stdClass () ) );
99
+ $ this ->assertEquals ( $ expected , $ obj ->set ( $ input ) );
78
100
}
79
101
80
- function test_get_permalink_method (): void {
102
+ function test_get_permalink (): void {
81
103
$ obj = $ this ->get_test ();
82
104
83
105
$ this ->assertIsSTring ( $ obj ->get_permalink ( 'de_DE ' ) );
84
106
}
85
107
86
- function test_get_postlink_method (): void {
108
+ function test_get_postlink (): void {
87
109
$ obj = $ this ->get_test ();
88
110
89
111
$ this ->assertIsSTring ( $ obj ->get_postlink ( 'de_DE ' ) );
90
112
$ this ->assertEquals ( '' , $ obj ->get_postlink ( 'de_DE ' ) );
91
113
}
92
114
93
- function test_get_current_link_method (): void {
115
+ function test_get_current_link (): void {
94
116
$ obj = $ this ->get_test ();
95
117
96
118
$ this ->assertIsSTring ( $ obj ->get_current_link () );
97
119
}
98
120
99
- function test_is_excluded_method (): void {
121
+ function test_is_excluded (): void {
100
122
$ obj = $ this ->get_test ();
101
123
102
124
$ this ->assertIsBool ( $ obj ->is_excluded () );
103
125
}
104
126
105
- function test_is_content_filter_method (): void {
127
+ function test_is_content_filter (): void {
106
128
$ obj = $ this ->get_test ();
107
129
108
130
$ this ->assertIsBool ( $ obj ->is_content_filter () );
109
131
}
110
132
111
- function test_get_order_method (): void {
133
+ function test_get_order (): void {
112
134
$ obj = $ this ->get_test ();
113
135
114
136
$ this ->assertIsSTring ( $ obj ->get_order () );
115
137
}
116
138
117
- function test_get_url_method (): void {
139
+ function test_get_url (): void {
118
140
Functions \when ( 'plugins_url ' )->justReturn ( 'https://msls.co/wp-content/plugins ' );
119
141
120
142
$ obj = $ this ->get_test ();
121
143
122
144
$ this ->assertIsSTring ( $ obj ->get_url ( '/dev/test ' ) );
123
145
}
124
146
125
- function test_get_flag_url_method (): void {
147
+ function test_get_flag_url (): void {
126
148
Functions \when ( 'is_admin ' )->justReturn ( true );
127
149
Functions \when ( 'plugins_url ' )->justReturn ( 'https://msls.co/wp-content/plugins ' );
128
150
Functions \when ( 'plugin_dir_path ' )->justReturn ( dirname ( __DIR__ , 2 ) . '/ ' );
@@ -132,7 +154,7 @@ function test_get_flag_url_method(): void {
132
154
$ this ->assertIsSTring ( $ obj ->get_flag_url ( 'de_DE ' ) );
133
155
}
134
156
135
- function test_get_available_languages_method (): void {
157
+ function test_get_available_languages (): void {
136
158
Functions \expect ( 'get_available_languages ' )->once ()->andReturn ( array ( 'de_DE ' , 'it_IT ' ) );
137
159
Functions \expect ( 'format_code_lang ' )->atLeast ()->once ()->andReturnUsing (
138
160
function ( $ code ) {
0 commit comments