Skip to content

Commit f45d945

Browse files
committed
Add Test
1 parent 21e22ce commit f45d945

1 file changed

Lines changed: 352 additions & 0 deletions

File tree

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2014 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.validators;
43+
44+
import java.util.Arrays;
45+
import java.util.Collections;
46+
import junit.framework.Assert;
47+
import org.junit.Test;
48+
import org.netbeans.modules.php.api.validation.ValidationResult;
49+
50+
/**
51+
*
52+
* @author junichi11
53+
*/
54+
public class WordPressDirectoryNameValidatorTest {
55+
56+
public WordPressDirectoryNameValidatorTest() {
57+
}
58+
59+
/**
60+
* Test of validateName method, of class WordPressDirectoryNameValidator.
61+
*/
62+
@Test
63+
public void testValidateName() {
64+
// invalid
65+
ValidationResult result = new WordPressDirectoryNameValidator()
66+
.validateName(null)
67+
.getResult();
68+
Assert.assertTrue(result.hasWarnings());
69+
Assert.assertFalse(result.hasErrors());
70+
71+
result = new WordPressDirectoryNameValidator()
72+
.validateName("")
73+
.getResult();
74+
Assert.assertTrue(result.hasWarnings());
75+
Assert.assertFalse(result.hasErrors());
76+
77+
result = new WordPressDirectoryNameValidator()
78+
.validateName("@")
79+
.getResult();
80+
Assert.assertTrue(result.hasWarnings());
81+
Assert.assertFalse(result.hasErrors());
82+
83+
result = new WordPressDirectoryNameValidator()
84+
.validateName(" ")
85+
.getResult();
86+
Assert.assertTrue(result.hasWarnings());
87+
Assert.assertFalse(result.hasErrors());
88+
89+
result = new WordPressDirectoryNameValidator()
90+
.validateName("/")
91+
.getResult();
92+
Assert.assertTrue(result.hasWarnings());
93+
Assert.assertFalse(result.hasErrors());
94+
95+
result = new WordPressDirectoryNameValidator()
96+
.validateName("?")
97+
.getResult();
98+
Assert.assertTrue(result.hasWarnings());
99+
Assert.assertFalse(result.hasErrors());
100+
101+
result = new WordPressDirectoryNameValidator()
102+
.validateName("<")
103+
.getResult();
104+
Assert.assertTrue(result.hasWarnings());
105+
Assert.assertFalse(result.hasErrors());
106+
107+
result = new WordPressDirectoryNameValidator()
108+
.validateName(">")
109+
.getResult();
110+
Assert.assertTrue(result.hasWarnings());
111+
Assert.assertFalse(result.hasErrors());
112+
113+
result = new WordPressDirectoryNameValidator()
114+
.validateName("!")
115+
.getResult();
116+
Assert.assertTrue(result.hasWarnings());
117+
Assert.assertFalse(result.hasErrors());
118+
119+
result = new WordPressDirectoryNameValidator()
120+
.validateName("\"")
121+
.getResult();
122+
Assert.assertTrue(result.hasWarnings());
123+
Assert.assertFalse(result.hasErrors());
124+
125+
result = new WordPressDirectoryNameValidator()
126+
.validateName("#")
127+
.getResult();
128+
Assert.assertTrue(result.hasWarnings());
129+
Assert.assertFalse(result.hasErrors());
130+
131+
result = new WordPressDirectoryNameValidator()
132+
.validateName("$")
133+
.getResult();
134+
Assert.assertTrue(result.hasWarnings());
135+
Assert.assertFalse(result.hasErrors());
136+
137+
result = new WordPressDirectoryNameValidator()
138+
.validateName("%")
139+
.getResult();
140+
Assert.assertTrue(result.hasWarnings());
141+
Assert.assertFalse(result.hasErrors());
142+
143+
result = new WordPressDirectoryNameValidator()
144+
.validateName("&")
145+
.getResult();
146+
Assert.assertTrue(result.hasWarnings());
147+
Assert.assertFalse(result.hasErrors());
148+
149+
result = new WordPressDirectoryNameValidator()
150+
.validateName("'")
151+
.getResult();
152+
Assert.assertTrue(result.hasWarnings());
153+
Assert.assertFalse(result.hasErrors());
154+
155+
result = new WordPressDirectoryNameValidator()
156+
.validateName("(")
157+
.getResult();
158+
Assert.assertTrue(result.hasWarnings());
159+
Assert.assertFalse(result.hasErrors());
160+
161+
result = new WordPressDirectoryNameValidator()
162+
.validateName(")")
163+
.getResult();
164+
Assert.assertTrue(result.hasWarnings());
165+
Assert.assertFalse(result.hasErrors());
166+
167+
result = new WordPressDirectoryNameValidator()
168+
.validateName("=")
169+
.getResult();
170+
Assert.assertTrue(result.hasWarnings());
171+
Assert.assertFalse(result.hasErrors());
172+
173+
result = new WordPressDirectoryNameValidator()
174+
.validateName("~")
175+
.getResult();
176+
Assert.assertTrue(result.hasWarnings());
177+
Assert.assertFalse(result.hasErrors());
178+
179+
result = new WordPressDirectoryNameValidator()
180+
.validateName("|")
181+
.getResult();
182+
Assert.assertTrue(result.hasWarnings());
183+
Assert.assertFalse(result.hasErrors());
184+
185+
result = new WordPressDirectoryNameValidator()
186+
.validateName("\\")
187+
.getResult();
188+
Assert.assertTrue(result.hasWarnings());
189+
Assert.assertFalse(result.hasErrors());
190+
191+
result = new WordPressDirectoryNameValidator()
192+
.validateName("^")
193+
.getResult();
194+
Assert.assertTrue(result.hasWarnings());
195+
Assert.assertFalse(result.hasErrors());
196+
197+
result = new WordPressDirectoryNameValidator()
198+
.validateName("`")
199+
.getResult();
200+
Assert.assertTrue(result.hasWarnings());
201+
Assert.assertFalse(result.hasErrors());
202+
203+
result = new WordPressDirectoryNameValidator()
204+
.validateName("{")
205+
.getResult();
206+
Assert.assertTrue(result.hasWarnings());
207+
Assert.assertFalse(result.hasErrors());
208+
209+
result = new WordPressDirectoryNameValidator()
210+
.validateName("}")
211+
.getResult();
212+
Assert.assertTrue(result.hasWarnings());
213+
Assert.assertFalse(result.hasErrors());
214+
215+
result = new WordPressDirectoryNameValidator()
216+
.validateName("[")
217+
.getResult();
218+
Assert.assertTrue(result.hasWarnings());
219+
Assert.assertFalse(result.hasErrors());
220+
221+
result = new WordPressDirectoryNameValidator()
222+
.validateName("]")
223+
.getResult();
224+
Assert.assertTrue(result.hasWarnings());
225+
Assert.assertFalse(result.hasErrors());
226+
227+
result = new WordPressDirectoryNameValidator()
228+
.validateName("+")
229+
.getResult();
230+
Assert.assertTrue(result.hasWarnings());
231+
Assert.assertFalse(result.hasErrors());
232+
233+
result = new WordPressDirectoryNameValidator()
234+
.validateName("*")
235+
.getResult();
236+
Assert.assertTrue(result.hasWarnings());
237+
Assert.assertFalse(result.hasErrors());
238+
239+
result = new WordPressDirectoryNameValidator()
240+
.validateName(";")
241+
.getResult();
242+
Assert.assertTrue(result.hasWarnings());
243+
Assert.assertFalse(result.hasErrors());
244+
245+
result = new WordPressDirectoryNameValidator()
246+
.validateName(":")
247+
.getResult();
248+
Assert.assertTrue(result.hasWarnings());
249+
Assert.assertFalse(result.hasErrors());
250+
251+
result = new WordPressDirectoryNameValidator()
252+
.validateName(",")
253+
.getResult();
254+
Assert.assertTrue(result.hasWarnings());
255+
Assert.assertFalse(result.hasErrors());
256+
257+
result = new WordPressDirectoryNameValidator()
258+
.validateName("あ")
259+
.getResult();
260+
Assert.assertTrue(result.hasWarnings());
261+
Assert.assertFalse(result.hasErrors());
262+
263+
result = new WordPressDirectoryNameValidator()
264+
.validateName("日本語")
265+
.getResult();
266+
Assert.assertTrue(result.hasWarnings());
267+
Assert.assertFalse(result.hasErrors());
268+
269+
result = new WordPressDirectoryNameValidator()
270+
.validateName("ア")
271+
.getResult();
272+
Assert.assertTrue(result.hasWarnings());
273+
Assert.assertFalse(result.hasErrors());
274+
275+
result = new WordPressDirectoryNameValidator()
276+
.validateName("A")
277+
.getResult();
278+
Assert.assertTrue(result.hasWarnings());
279+
Assert.assertFalse(result.hasErrors());
280+
281+
result = new WordPressDirectoryNameValidator()
282+
.validateName("test/")
283+
.getResult();
284+
Assert.assertTrue(result.hasWarnings());
285+
Assert.assertFalse(result.hasErrors());
286+
287+
// valid
288+
result = new WordPressDirectoryNameValidator()
289+
.validateName("a")
290+
.getResult();
291+
Assert.assertFalse(result.hasWarnings());
292+
Assert.assertFalse(result.hasErrors());
293+
294+
result = new WordPressDirectoryNameValidator()
295+
.validateName("A")
296+
.getResult();
297+
Assert.assertFalse(result.hasWarnings());
298+
Assert.assertFalse(result.hasErrors());
299+
300+
result = new WordPressDirectoryNameValidator()
301+
.validateName("-")
302+
.getResult();
303+
Assert.assertFalse(result.hasWarnings());
304+
Assert.assertFalse(result.hasErrors());
305+
306+
result = new WordPressDirectoryNameValidator()
307+
.validateName(".")
308+
.getResult();
309+
Assert.assertFalse(result.hasWarnings());
310+
Assert.assertFalse(result.hasErrors());
311+
312+
result = new WordPressDirectoryNameValidator()
313+
.validateName("_")
314+
.getResult();
315+
Assert.assertFalse(result.hasWarnings());
316+
Assert.assertFalse(result.hasErrors());
317+
318+
result = new WordPressDirectoryNameValidator()
319+
.validateName("test-child")
320+
.getResult();
321+
Assert.assertFalse(result.hasWarnings());
322+
Assert.assertFalse(result.hasErrors());
323+
324+
}
325+
326+
/**
327+
* Test of validateExistingName method, of class
328+
* WordPressDirectoryNameValidator.
329+
*/
330+
@Test
331+
public void testValidateExistingName() {
332+
// invalid
333+
ValidationResult result = new WordPressDirectoryNameValidator()
334+
.validateExistingName("parent", Arrays.asList("parent", "parent2"))
335+
.getResult();
336+
Assert.assertTrue(result.hasWarnings());
337+
Assert.assertFalse(result.hasErrors());
338+
339+
// valid
340+
result = new WordPressDirectoryNameValidator()
341+
.validateExistingName("child", Arrays.asList("parent", "parent2"))
342+
.getResult();
343+
Assert.assertFalse(result.hasWarnings());
344+
Assert.assertFalse(result.hasErrors());
345+
346+
result = new WordPressDirectoryNameValidator()
347+
.validateExistingName("child", Collections.<String>emptyList())
348+
.getResult();
349+
Assert.assertFalse(result.hasWarnings());
350+
Assert.assertFalse(result.hasErrors());
351+
}
352+
}

0 commit comments

Comments
 (0)