1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace lloc\Msls\ContentImport; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class ImportCoordinatesTest extends \Msls_UnitTestCase { |
7
|
|
|
|
8
|
|
|
function setUp() { |
|
|
|
|
9
|
|
|
parent::setUp(); |
10
|
|
|
unset( |
11
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ], |
|
|
|
|
12
|
|
|
$_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ], |
|
|
|
|
13
|
|
|
$_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] |
|
|
|
|
14
|
|
|
); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testValidate() { |
|
|
|
|
18
|
|
|
$dest_lang = 'en_US'; |
19
|
|
|
$source_lang = 'de_DE'; |
20
|
|
|
|
21
|
|
|
$obj = new ImportCoordinates(); |
22
|
|
|
|
23
|
|
|
$this->assertFalse( $obj->validate() ); |
24
|
|
|
|
25
|
|
|
$source_blog_id = $this->factory->blog->create(); |
26
|
|
|
$obj->source_blog_id = $source_blog_id; |
27
|
|
|
|
28
|
|
|
$this->assertFalse( $obj->validate() ); |
29
|
|
|
|
30
|
|
|
switch_to_blog( $source_blog_id ); |
|
|
|
|
31
|
|
|
$source_post = $this->factory->post->create_and_get(); |
32
|
|
|
$source_post_id = $source_post->ID; |
33
|
|
|
|
34
|
|
|
$obj->source_post_id = $source_post_id; |
35
|
|
|
$obj->source_post = $source_post; |
36
|
|
|
|
37
|
|
|
$this->assertFalse( $obj->validate() ); |
38
|
|
|
|
39
|
|
|
$dest_blog_id = $this->factory->blog->create(); |
40
|
|
|
|
41
|
|
|
$obj->dest_blog_id = $dest_blog_id; |
42
|
|
|
|
43
|
|
|
$this->assertFalse( $obj->validate() ); |
44
|
|
|
|
45
|
|
|
update_option( 'WPLANG', $source_lang ); |
46
|
|
|
|
47
|
|
|
$obj->source_lang = $source_lang; |
48
|
|
|
|
49
|
|
|
$this->assertFalse( $obj->validate() ); |
50
|
|
|
|
51
|
|
|
switch_to_blog( $dest_blog_id ); |
|
|
|
|
52
|
|
|
$dest_post_id = $this->factory->post->create(); |
53
|
|
|
|
54
|
|
|
$obj->dest_post_id = $dest_post_id; |
55
|
|
|
|
56
|
|
|
$this->assertFalse( $obj->validate() ); |
57
|
|
|
|
58
|
|
|
update_option( 'WPLANG', $dest_lang ); |
59
|
|
|
|
60
|
|
|
$obj->dest_lang = $dest_lang; |
61
|
|
|
|
62
|
|
|
$this->assertTrue( $obj->validate() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test set_importer_for |
67
|
|
|
*/ |
68
|
|
|
public function test_set_importer_for() { |
69
|
|
|
$obj = new ImportCoordinates(); |
70
|
|
|
|
71
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
72
|
|
|
|
73
|
|
|
$obj->set_importer_for( 'foo', 'bar' ); |
74
|
|
|
|
75
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
76
|
|
|
|
77
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'baz' ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test parse_importers from REQUEST |
82
|
|
|
*/ |
83
|
|
|
public function test_parse_importers_from_REQUEST() { |
|
|
|
|
84
|
|
|
$obj = new ImportCoordinates(); |
85
|
|
|
|
86
|
|
|
unset( $_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$obj->parse_importers_from_request(); |
89
|
|
|
|
90
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
91
|
|
|
|
92
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = []; |
93
|
|
|
|
94
|
|
|
$obj->parse_importers_from_request(); |
95
|
|
|
|
96
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
97
|
|
|
|
98
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'foo' => 'bar' ]; |
99
|
|
|
|
100
|
|
|
$obj->parse_importers_from_request(); |
101
|
|
|
|
102
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Test parse_importers from POST |
107
|
|
|
*/ |
108
|
|
|
public function test_parse_importers_from_POST() { |
|
|
|
|
109
|
|
|
$obj = new ImportCoordinates(); |
110
|
|
|
|
111
|
|
|
unset( $_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$obj->parse_importers_from_request(); |
114
|
|
|
|
115
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
116
|
|
|
|
117
|
|
|
$_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = []; |
118
|
|
|
|
119
|
|
|
$obj->parse_importers_from_request(); |
120
|
|
|
|
121
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
122
|
|
|
|
123
|
|
|
$_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'foo' => 'bar' ]; |
124
|
|
|
|
125
|
|
|
$obj->parse_importers_from_request(); |
126
|
|
|
|
127
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Test parse_importers from GET |
132
|
|
|
*/ |
133
|
|
|
public function test_parse_importers_from_GET() { |
|
|
|
|
134
|
|
|
$obj = new ImportCoordinates(); |
135
|
|
|
|
136
|
|
|
unset( $_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
137
|
|
|
|
138
|
|
|
$obj->parse_importers_from_request(); |
139
|
|
|
|
140
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
141
|
|
|
|
142
|
|
|
$_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = []; |
143
|
|
|
|
144
|
|
|
$obj->parse_importers_from_request(); |
145
|
|
|
|
146
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
147
|
|
|
|
148
|
|
|
$_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'foo' => 'bar' ]; |
149
|
|
|
|
150
|
|
|
$obj->parse_importers_from_request(); |
151
|
|
|
|
152
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Test parse_importers from REQUEST and POST |
157
|
|
|
*/ |
158
|
|
|
public function test_parse_importers_from_REQUEST_and_POST() { |
|
|
|
|
159
|
|
|
$obj = new ImportCoordinates(); |
160
|
|
|
|
161
|
|
|
unset( $_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
162
|
|
|
unset( $_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
163
|
|
|
|
164
|
|
|
$obj->parse_importers_from_request(); |
165
|
|
|
|
166
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
167
|
|
|
|
168
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = []; |
169
|
|
|
$_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'some' => 'baz' ]; |
170
|
|
|
|
171
|
|
|
$obj->parse_importers_from_request(); |
172
|
|
|
|
173
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
174
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'some' ) ); |
175
|
|
|
|
176
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'foo' => 'bar' ]; |
177
|
|
|
$_POST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'some' => 'baz' ]; |
178
|
|
|
|
179
|
|
|
$obj->parse_importers_from_request(); |
180
|
|
|
|
181
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
182
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'some' ) ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Test parse_importers from REQUEST and GET |
187
|
|
|
*/ |
188
|
|
|
public function test_parse_importers_from_REQUEST_and_GET() { |
|
|
|
|
189
|
|
|
$obj = new ImportCoordinates(); |
190
|
|
|
|
191
|
|
|
unset( $_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
192
|
|
|
unset( $_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] ); |
|
|
|
|
193
|
|
|
|
194
|
|
|
$obj->parse_importers_from_request(); |
195
|
|
|
|
196
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
197
|
|
|
|
198
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = []; |
199
|
|
|
$_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'some' => 'baz' ]; |
200
|
|
|
|
201
|
|
|
$obj->parse_importers_from_request(); |
202
|
|
|
|
203
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'foo' ) ); |
204
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'some' ) ); |
205
|
|
|
|
206
|
|
|
$_REQUEST[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'foo' => 'bar' ]; |
207
|
|
|
$_GET[ ImportCoordinates::IMPORTERS_GLOBAL_KEY ] = [ 'some' => 'baz' ]; |
208
|
|
|
|
209
|
|
|
$obj->parse_importers_from_request(); |
210
|
|
|
|
211
|
|
|
$this->assertEquals( 'bar', $obj->get_importer_for( 'foo' ) ); |
212
|
|
|
$this->assertEmpty( $obj->get_importer_for( 'some' ) ); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.