Completed
Push — master ( 6c0735...dd8543 )
by Dennis
06:47
created

WP_Test_MslsAdmin   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 235
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 235
rs 10
c 0
b 0
f 0
wmc 21
lcom 1
cbo 4

21 Methods

Rating   Name   Duplication   Size   Complexity  
A get_test() 0 6 1
A test_has_problems_no_problem() 0 10 1
A test_has_problems_one_language() 0 12 1
A test_has_problems_is_empty() 0 12 1
A test_subsubsub_empty() 0 5 1
A test_blog_language() 0 6 1
A test_display() 0 6 1
A test_reference_user() 0 6 1
A test_activate_autocomplete() 0 6 1
A test_sort_by_description() 0 6 1
A test_exclude_current_blog() 0 6 1
A test_only_with_translation() 0 6 1
A test_output_current_blog() 0 6 1
A test_description() 0 6 1
A test_content_filter() 0 6 1
A test_content_priority() 0 6 1
A test_render_checkbox() 0 5 1
A test_render_input() 0 5 1
A test_render_select() 0 6 1
A test_validate() 0 8 1
A test_set_blog_language() 0 6 1
1
<?php
2
/**
3
 * Tests for MslsAdmin
4
 *
5
 * @author Dennis Ploetner <[email protected]>
6
 * @package Msls
7
 */
8
9
use lloc\Msls\MslsAdmin;
10
use lloc\Msls\MslsOptions;
11
use lloc\Msls\MslsBlogCollection;
12
use lloc\Msls\MslsBlog;
13
14
/**
15
 * WP_Test_MslsAdmin
16
 */
17
class WP_Test_MslsAdmin extends Msls_UnitTestCase {
18
19
	function get_test() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
		$options    = MslsOptions::instance();
21
		$collection = MslsBlogCollection::instance();
22
23
		return new MslsAdmin( $options, $collection );
24
	}
25
26
	function test_has_problems_no_problem() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
		$options = $this->getMockBuilder( MslsOptions::class )->getMock();
28
		$options->method( 'get_available_languages' )->willReturn( [ 'de_DE', 'it_IT' ] );
29
30
		$collection = MslsBlogCollection::instance();
31
32
		$obj = new MslsAdmin( $options, $collection );
33
34
		$this->assertFalse( $obj->has_problems() );
35
	}
36
37
	function test_has_problems_one_language() {
38
		$options = $this->getMockBuilder( MslsOptions::class )->getMock();
39
		$options->method( 'get_available_languages' )->willReturn( [ 'de_DE' ] );
40
41
		$collection = MslsBlogCollection::instance();
42
43
		$obj = new MslsAdmin( $options, $collection );
44
45
		$this->expectOutputRegex( '/^<div id="msls-warning" class="updated fade"><p>.*$/' );
46
47
		$this->assertTrue( $obj->has_problems() );
48
	}
49
50
	function test_has_problems_is_empty() {
51
		$options = $this->getMockBuilder( MslsOptions::class )->getMock();
52
		$options->method( 'is_empty' )->willReturn( true );
53
54
		$collection = MslsBlogCollection::instance();
55
56
		$obj = new MslsAdmin( $options, $collection );
57
58
		$this->expectOutputRegex( '/^<div id="msls-warning" class="updated fade"><p>.*$/' );
59
60
		$this->assertTrue( $obj->has_problems() );
61
	}
62
63
	public function test_subsubsub_empty() {
64
		$obj = $this->get_test();
65
66
		$this->assertEquals( '', $obj->subsubsub() );
67
	}
68
69
	/* function test_subsubsub_two_blogs() {
70
		$options    = $this->getMockBuilder( MslsOptions::class )->getMock();
71
72
		$blog_1              = $this->getMockBuilder( MslsBlog::class)->disableOriginalConstructor()->getMock();
73
		$blog_1->userblog_id = 1;
74
		$blog_1->blogname    = 'Test 1';
75
		$blog_1->method( 'get_description' )->willReturn( 'Descr 1' );
76
77
		$blog_2              = $this->getMockBuilder( MslsBlog::class)->disableOriginalConstructor()->getMock();
78
		$blog_2->userblog_id = 2;
79
		$blog_2->blogname    = 'Test 2';
80
		$blog_2->method( 'get_description' )->willReturn( 'Descr 2' );
81
82
		$collection = $this->getMockBuilder( MslsBlogCollection::class)->getMock();
83
		$collection->method( 'get_plugin_active_blogs' )->willReturn( [ $blog_1, $blog_2 ] );
84
		$collection->method( 'get_current_blog_id' )->willReturn( 1 );
85
86
		$obj = new MslsAdmin( $options, $collection );
87
88
		$this->assertInternalType( 'string', $obj->subsubsub() );
89
	} */
90
91
	/**
92
	 * Verify the blog_language-method
93
	 */
94
	function test_blog_language() {
95
		$obj = $this->get_test();
96
97
		$this->expectOutputRegex( '/^<select id="blog_language" name="msls\[blog_language\]">.*$/' );
98
		$obj->blog_language();
99
	}
100
101
	/**
102
	 * Verify the display-method
103
	 */
104
	function test_display() {
105
		$obj = $this->get_test();
106
107
		$this->expectOutputRegex( '/^<select id="display" name="msls\[display\]">.*$/' );
108
		$obj->display();
109
	}
110
111
	/**
112
	 * Verify the reference_user-method
113
	 */
114
	function test_reference_user() {
115
		$obj = $this->get_test();
116
117
		$this->expectOutputRegex( '/^<select id="reference_user" name="msls\[reference_user\]">.*$/' );
118
		$obj->reference_user();
119
	}
120
121
	/**
122
	 * Verify the activate_autocomplete-method
123
	 */
124
	function test_activate_autocomplete() {
125
		$obj = $this->get_test();
126
127
		$this->expectOutputString( '<input type="checkbox" id="activate_autocomplete" name="msls[activate_autocomplete]" value="1" /> <label for="activate_autocomplete">Activate experimental autocomplete inputs</label>' );
128
		$obj->activate_autocomplete();
129
	}
130
131
	/**
132
	 * Verify the sort_by_description-method
133
	 */
134
	function test_sort_by_description() {
135
		$obj = $this->get_test();
136
137
		$this->expectOutputString( '<input type="checkbox" id="sort_by_description" name="msls[sort_by_description]" value="1" /> <label for="sort_by_description">Sort languages by description</label>' );
138
		$obj->sort_by_description();
139
	}
140
141
	/**
142
	 * Verify the exclude_current_blog-method
143
	 */
144
	function test_exclude_current_blog() {
145
		$obj = $this->get_test();
146
147
		$this->expectOutputString( '<input type="checkbox" id="exclude_current_blog" name="msls[exclude_current_blog]" value="1" /> <label for="exclude_current_blog">Exclude this blog from output</label>' );
148
		$obj->exclude_current_blog();
149
	}
150
151
	/**
152
	 * Verify the only_with_translation-method
153
	 */
154
	function test_only_with_translation() {
155
		$obj = $this->get_test();
156
157
		$this->expectOutputString( '<input type="checkbox" id="only_with_translation" name="msls[only_with_translation]" value="1" /> <label for="only_with_translation">Show only links with a translation</label>' );
158
		$obj->only_with_translation();
159
	}
160
161
	/**
162
	 * Verify the output_current_blog-method
163
	 */
164
	function test_output_current_blog() {
165
		$obj = $this->get_test();
166
167
		$this->expectOutputString( '<input type="checkbox" id="output_current_blog" name="msls[output_current_blog]" value="1" /> <label for="output_current_blog">Display link to the current language</label>' );
168
		$obj->output_current_blog();
169
	}
170
171
	/**
172
	 * Verify the description-method
173
	 */
174
	function test_description() {
175
		$obj = $this->get_test();
176
177
		$this->expectOutputString( '<input type="text" class="regular-text" id="description" name="msls[description]" value="" size="40"/>' );
178
		$obj->description();
179
	}
180
181
	/**
182
	 * Verify the content_filter-method
183
	 */
184
	function test_content_filter() {
185
		$obj = $this->get_test();
186
187
		$this->expectOutputString( '<input type="checkbox" id="content_filter" name="msls[content_filter]" value="1" /> <label for="content_filter">Add hint for available translations</label>' );
188
		$obj->content_filter();
189
	}
190
191
	/**
192
	 * Verify the content_priority-method
193
	 */
194
	function test_content_priority() {
195
		$obj = $this->get_test();
196
197
		$this->expectOutputRegex( '/^<select id="content_priority" name="msls\[content_priority\]">.*$/' );
198
		$obj->content_priority();
199
	}
200
201
	/**
202
	 * Verify the render_checkbox-method
203
	 */
204
	function test_render_checkbox() {
205
		$obj = $this->get_test();
206
207
		$this->assertInternalType( 'string', $obj->render_checkbox( 'test' ) );
208
	}
209
210
	/**
211
	 * Verify the render_input-method
212
	 */
213
	function test_render_input() {
214
		$obj = $this->get_test();
215
216
		$this->assertInternalType( 'string', $obj->render_input( 'test' ) );
217
	}
218
219
	/**
220
	 * Verify the render_select-method
221
	 */
222
	function test_render_select() {
223
		$obj = $this->get_test();
224
225
		$arr = array( 'a', 'b', 'c' );
226
		$this->assertInternalType( 'string', $obj->render_select( 'test', $arr ) );
227
	}
228
229
	/**
230
	 * Verify the validate-method
231
	 */
232
	function test_validate() {
233
		$obj = $this->get_test();
234
235
		$arr = array();
236
		$this->assertEquals( array( 'display' => 0 ), $obj->validate( $arr ) );
237
		$arr = array( 'image_url' => '/test/', 'display' => '1' );
238
		$this->assertEquals( array( 'image_url' => '/test', 'display' => 1 ), $obj->validate( $arr ) );
239
	}
240
241
	/**
242
	 * Verify the set_blog_language-method
243
	 */
244
	function test_set_blog_language() {
245
		$obj = $this->get_test();
246
247
		$arr = array( 'abc' => true, 'blog_language' => 'it_IT' );
248
		$this->assertEquals( array( 'abc' => true ), $obj->set_blog_language( $arr ) );
249
	}
250
251
}
252