Custom Post Type UI - Version 1.0.8

Version Description

  • Register taxonomies at a higher priority than post types.
Download this release

Release Info

Developer tw2113
Plugin Icon 128x128 Custom Post Type UI
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

README.md ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ custom-post-type-ui
2
+ ===================
3
+
4
+ Admin UI for creating custom post types and custom taxonomies in WordPress
composer.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "WebDevStudios/wp-custom-post-type-ui",
3
+ "description": "The Custom Post Type UI Plugin for Wordpress found at https://wordpress.org/plugins/custom-post-type-ui/ ",
4
+ "homepage": "https://github.com/WebDevStudios/custom-post-type-ui",
5
+ "license": "MIT",
6
+ "authors": [
7
+ {
8
+ "name": "WebDevStudios",
9
+ "email": "hello@WebDevStudios",
10
+ "homepage": "https://github.com/WebDevStudios/custom-post-type-ui"
11
+ }
12
+ ],
13
+ "minimum-stability": "dev",
14
+ "require": {
15
+ "php": ">=5.3.0"
16
+ },
17
+ "autoload": {
18
+ "psr-0": { "CPT": "src/" }
19
+ }
20
+ }
custom-post-type-ui.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Post Type UI
4
  Plugin URI: https://github.com/WebDevStudios/custom-post-type-ui/
5
  Description: Admin panel for creating custom post types and custom taxonomies in WordPress
6
  Author: WebDevStudios
7
- Version: 1.0.7
8
  Author URI: http://webdevstudios.com/
9
  Text Domain: cpt-plugin
10
  Domain Path: /languages
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'CPT_VERSION', '1.0.7' );
20
  define( 'CPTUI_WP_VERSION', get_bloginfo( 'version' ) );
21
 
22
  /**
@@ -232,7 +232,7 @@ function cptui_create_custom_taxonomies() {
232
  }
233
  }
234
  }
235
- add_action( 'init', 'cptui_create_custom_taxonomies' );
236
 
237
  /**
238
  * Helper function to register the actual taxonomy.
4
  Plugin URI: https://github.com/WebDevStudios/custom-post-type-ui/
5
  Description: Admin panel for creating custom post types and custom taxonomies in WordPress
6
  Author: WebDevStudios
7
+ Version: 1.0.8
8
  Author URI: http://webdevstudios.com/
9
  Text Domain: cpt-plugin
10
  Domain Path: /languages
16
  exit;
17
  }
18
 
19
+ define( 'CPT_VERSION', '1.0.8' );
20
  define( 'CPTUI_WP_VERSION', get_bloginfo( 'version' ) );
21
 
22
  /**
232
  }
233
  }
234
  }
235
+ add_action( 'init', 'cptui_create_custom_taxonomies', 9 );
236
 
237
  /**
238
  * Helper function to register the actual taxonomy.
phpunit.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <phpunit
2
+ bootstrap="tests/bootstrap.php"
3
+ backupGlobals="false"
4
+ colors="true"
5
+ convertErrorsToExceptions="true"
6
+ convertNoticesToExceptions="true"
7
+ convertWarningsToExceptions="true"
8
+ >
9
+ <testsuites>
10
+ <testsuite>
11
+ <!--<directory prefix="test-" suffix=".php">./</directory>-->
12
+ <directory suffix=".php">./tests/</directory>
13
+ </testsuite>
14
+ </testsuites>
15
+ </phpunit>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: williamsba1, tw2113, webdevstudios
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3084056
4
  Tags: custom post types, CPT, CMS, post, types, post type, cck, taxonomy, tax, custom
5
  Requires at least: 3.8
6
- Tested up to: 4.1.1
7
- Stable tag: 1.0.7
8
  License: GPLv2
9
 
10
  Admin UI for creating custom post types and custom taxonomies in WordPress
@@ -37,6 +37,9 @@ Implied credit to:
37
 
38
  == Changelog ==
39
 
 
 
 
40
  = 1.0.7 =
41
  * Preventive measures for potential XSS security issues with add_query_arg()
42
 
@@ -234,6 +237,9 @@ Implied credit to:
234
 
235
  == Upgrade Notice ==
236
 
 
 
 
237
  = 1.0.7 =
238
  * Preventive measures for potential XSS security issues with add_query_arg()
239
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3084056
4
  Tags: custom post types, CPT, CMS, post, types, post type, cck, taxonomy, tax, custom
5
  Requires at least: 3.8
6
+ Tested up to: 4.2
7
+ Stable tag: 1.0.8
8
  License: GPLv2
9
 
10
  Admin UI for creating custom post types and custom taxonomies in WordPress
37
 
38
  == Changelog ==
39
 
40
+ = 1.0.8 =
41
+ * Register taxonomies at a higher priority than post types.
42
+
43
  = 1.0.7 =
44
  * Preventive measures for potential XSS security issues with add_query_arg()
45
 
237
 
238
  == Upgrade Notice ==
239
 
240
+ = 1.0.8 =
241
+ * Register taxonomies at a higher priority than post types.
242
+
243
  = 1.0.7 =
244
  * Preventive measures for potential XSS security issues with add_query_arg()
245
 
tests/CPTUI-Admin-UI-Core-Test.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( 'CPTUI-Base-Tests.php' );
3
+
4
+ /**
5
+ * An example test case.
6
+ */
7
+ class CPTUI_Admin_UI_Core extends CPTUI_Base_Tests {
8
+
9
+ public function setUp() {
10
+ parent::setUp();
11
+ }
12
+
13
+ public function tearDown() {
14
+ parent::tearDown();
15
+ }
16
+
17
+ /**
18
+ * Tests for our file being present and available.
19
+ */
20
+ public function test_CPTUI_Admin_UI_Exists() {
21
+ $this->assertFileExists( CPTUI_DIRECTORY_PATH . '/classes/class.cptui_admin_ui.php' );
22
+ }
23
+
24
+ /**
25
+ * Test that we are able to instantiate our class and get an object back.
26
+ */
27
+ public function test_CPTUI_Admin_UI_Objects() {
28
+ $ui = new cptui_admin_ui();
29
+ $this->assertInstanceOf( 'cptui_admin_ui', $ui );
30
+ }
31
+ }
tests/CPTUI-Admin-UI-Inputs-Test.php ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( 'CPTUI-Base-Tests.php' );
3
+
4
+ /**
5
+ * An example test case.
6
+ */
7
+ class CPTUI_Admin_UI_Inputs_Test extends CPTUI_Base_Tests {
8
+
9
+ public function setUp() {
10
+ parent::setUp();
11
+ }
12
+
13
+ public function tearDown() {
14
+ parent::tearDown();
15
+ }
16
+
17
+ /**
18
+ * Tests our label method.
19
+ */
20
+ public function test_CPTUI_Label() {
21
+ $ui = new cptui_admin_ui();
22
+ $expected = '<label for="testing">Testing</label>';
23
+
24
+ $this->assertEquals( $expected, $ui->get_label( 'testing', 'Testing' ) );
25
+ }
26
+
27
+ /**
28
+ * Tests our required field method.
29
+ */
30
+ public function test_CPTUI_Required() {
31
+ $ui = new cptui_admin_ui();
32
+ $expected = '<span class="required">*</span>';
33
+
34
+ $this->assertEquals( $expected, $ui->get_required() );
35
+ }
36
+
37
+ /**
38
+ * Tests our textarea field method.
39
+ */
40
+ public function test_CPTUI_Textarea() {
41
+ $ui = new cptui_admin_ui();
42
+
43
+ $expected = '<tr valign="top">
44
+ <th scope="row">
45
+ <label for="name">Description</label>
46
+ <a href="#" title="Helper text." class="cptui-help wp-ui-highlight">?</a>
47
+ </th>
48
+ <td>
49
+ <textarea id="name" name="name_array[name]" rows="4" cols="40">saved value</textarea>
50
+ </td>
51
+ </tr>';
52
+
53
+ $args = array(
54
+ 'namearray' => 'name_array',
55
+ 'name' => 'name',
56
+ 'rows' => '4',
57
+ 'cols' => '40',
58
+ 'textvalue' => 'saved value',
59
+ 'labeltext' => 'Description',
60
+ 'helptext' => 'Helper text.'
61
+ );
62
+
63
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_textarea_input( $args ) );
64
+ }
65
+
66
+ /**
67
+ * Tests our text field method.
68
+ */
69
+ public function test_CPTUI_Text() {
70
+ $ui = new cptui_admin_ui();
71
+
72
+ $expected = '<tr valign="top">
73
+ <th scope="row">
74
+ <label for="name">Description</label>
75
+ <a href="#" title="Helper text." class="cptui-help wp-ui-highlight">?</a>
76
+ </th>
77
+ <td>
78
+ <input type="text" id="name" name="name_array[name]" value="saved value" /><br/>
79
+ </td>
80
+ </tr>';
81
+
82
+ $args = array(
83
+ 'namearray' => 'name_array',
84
+ 'name' => 'name',
85
+ 'rows' => '4',
86
+ 'cols' => '40',
87
+ 'textvalue' => 'saved value',
88
+ 'labeltext' => 'Description',
89
+ 'helptext' => 'Helper text.'
90
+ );
91
+
92
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_text_input( $args ) );
93
+ }
94
+
95
+ /**
96
+ * Tests our select input.
97
+ *
98
+ * This test checks for no required boolean and no saved value.
99
+ */
100
+ public function test_CPTUI_Select_No_Required_No_Saved() {
101
+ $ui = new cptui_admin_ui();
102
+
103
+ $select = array(
104
+ 'options' => array(
105
+ array( 'attr' => '0', 'text' => __( 'False', 'cpt-plugin' ) ),
106
+ array( 'attr' => '1', 'text' => __( 'True', 'cpt-plugin' ), 'default' => 'true' )
107
+ )
108
+ );
109
+
110
+ $select['selected'] = '';
111
+ $args = array(
112
+ 'namearray' => 'cpt_custom_post_type',
113
+ 'name' => 'public',
114
+ 'labeltext' => __( 'Public', 'cpt-plugin' ),
115
+ 'aftertext' => __( '(default: True)', 'cpt-plugin' ),
116
+ 'helptext' => esc_attr__( 'Whether posts of this type should be shown in the admin UI', 'cpt-plugin' ),
117
+ 'selections' => $select
118
+ );
119
+
120
+ $expected = '<tr valign="top">
121
+ <th scope="row">
122
+ <label for="public">Public</label>
123
+ <a href="#" title="Whether posts of this type should be shown in the admin UI" class="cptui-help wp-ui-highlight">?</a>
124
+ </th>
125
+ <td>
126
+ <select id="public" name="cpt_custom_post_type[public]">
127
+ <option value="0">False</option>
128
+ <option value="1" selected="selected">True</option>
129
+ </select>
130
+ (default: True)
131
+ </td>
132
+ </tr>';
133
+
134
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
135
+ }
136
+
137
+ /**
138
+ * Tests our select input.
139
+ *
140
+ * This test checks for no required boolean and no saved value.
141
+ */
142
+ public function test_CPTUI_Select_Required_No_Saved() {
143
+ $ui = new cptui_admin_ui();
144
+
145
+ $select = array(
146
+ 'options' => array(
147
+ array( 'attr' => '0', 'text' => __( 'False', 'cpt-plugin' ) ),
148
+ array( 'attr' => '1', 'text' => __( 'True', 'cpt-plugin' ), 'default' => 'true' )
149
+ )
150
+ );
151
+
152
+ $select['selected'] = '';
153
+ $args = array(
154
+ 'namearray' => 'cpt_custom_post_type',
155
+ 'name' => 'public',
156
+ 'labeltext' => __( 'Public', 'cpt-plugin' ),
157
+ 'aftertext' => __( '(default: True)', 'cpt-plugin' ),
158
+ 'helptext' => esc_attr__( 'Whether posts of this type should be shown in the admin UI', 'cpt-plugin' ),
159
+ 'selections' => $select,
160
+ 'required' => true
161
+ );
162
+
163
+ $expected = '<tr valign="top">
164
+ <th scope="row">
165
+ <label for="public">Public</label><span class="required">*</span>
166
+ <a href="#" title="Whether posts of this type should be shown in the admin UI" class="cptui-help wp-ui-highlight">?</a>
167
+ </th>
168
+ <td>
169
+ <select id="public" name="cpt_custom_post_type[public]">
170
+ <option value="0">False</option>
171
+ <option value="1" selected="selected">True</option>
172
+ </select>
173
+ (default: True)
174
+ </td>
175
+ </tr>';
176
+
177
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
178
+ }
179
+
180
+ /**
181
+ * Tests our select input.
182
+ *
183
+ * This test checks for no required boolean and a "true" saved value.
184
+ */
185
+ public function test_CPTUI_Select_No_Required_True_Saved() {
186
+ $ui = new cptui_admin_ui();
187
+
188
+ $select = array(
189
+ 'options' => array(
190
+ array( 'attr' => '0', 'text' => __( 'False', 'cpt-plugin' ) ),
191
+ array( 'attr' => '1', 'text' => __( 'True', 'cpt-plugin' ), 'default' => 'true' )
192
+ )
193
+ );
194
+
195
+ $select['selected'] = '1';
196
+ $args = array(
197
+ 'namearray' => 'cpt_custom_post_type',
198
+ 'name' => 'public',
199
+ 'labeltext' => __( 'Public', 'cpt-plugin' ),
200
+ 'aftertext' => __( '(default: True)', 'cpt-plugin' ),
201
+ 'helptext' => esc_attr__( 'Whether posts of this type should be shown in the admin UI', 'cpt-plugin' ),
202
+ 'selections' => $select,
203
+ );
204
+
205
+ $expected = '<tr valign="top">
206
+ <th scope="row">
207
+ <label for="public">Public</label>
208
+ <a href="#" title="Whether posts of this type should be shown in the admin UI" class="cptui-help wp-ui-highlight">?</a>
209
+ </th>
210
+ <td>
211
+ <select id="public" name="cpt_custom_post_type[public]">
212
+ <option value="0">False</option>
213
+ <option value="1" selected="selected">True</option>
214
+ </select>
215
+ (default: True)
216
+ </td>
217
+ </tr>';
218
+
219
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
220
+ }
221
+
222
+ /**
223
+ * Tests our select input.
224
+ *
225
+ * This test checks for no required boolean and a "false" saved value.
226
+ */
227
+ public function test_CPTUI_Select_No_Required_False_Saved() {
228
+ $ui = new cptui_admin_ui();
229
+
230
+ $select = array(
231
+ 'options' => array(
232
+ array( 'attr' => '0', 'text' => __( 'False', 'cpt-plugin' ) ),
233
+ array( 'attr' => '1', 'text' => __( 'True', 'cpt-plugin' ), 'default' => 'true' )
234
+ )
235
+ );
236
+
237
+ $select['selected'] = '0';
238
+ $args = array(
239
+ 'namearray' => 'cpt_custom_post_type',
240
+ 'name' => 'public',
241
+ 'labeltext' => __( 'Public', 'cpt-plugin' ),
242
+ 'aftertext' => __( '(default: True)', 'cpt-plugin' ),
243
+ 'helptext' => esc_attr__( 'Whether posts of this type should be shown in the admin UI', 'cpt-plugin' ),
244
+ 'selections' => $select,
245
+ );
246
+
247
+ $expected = '<tr valign="top">
248
+ <th scope="row">
249
+ <label for="public">Public</label>
250
+ <a href="#" title="Whether posts of this type should be shown in the admin UI" class="cptui-help wp-ui-highlight">?</a>
251
+ </th>
252
+ <td>
253
+ <select id="public" name="cpt_custom_post_type[public]">
254
+ <option value="0" selected="selected">False</option>
255
+ <option value="1">True</option>
256
+ </select>
257
+ (default: True)
258
+ </td>
259
+ </tr>';
260
+
261
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
262
+ }
263
+
264
+ /**
265
+ * Tests non boolean based select inputs
266
+ */
267
+ public function test_CPTUI_Select_Non_Bool_No_Option() {
268
+ $ui = new cptui_admin_ui();
269
+
270
+ $select = array();
271
+ $select['options'] = array();
272
+
273
+ $select['options'][] = array( 'attr' => '', 'text' => '--' );
274
+ $select['options'][] = array( 'attr' => 'movie', 'text' => 'Movies' );
275
+ $select['options'][] = array( 'attr' => 'tv_show', 'text' => 'TV Show' );
276
+
277
+ $select['selected'] = '';
278
+ $args = array(
279
+ 'namearray' => 'cptui_selected_post_type',
280
+ 'name' => 'post_type',
281
+ 'selections' => $select,
282
+ 'wrap' => false
283
+ );
284
+
285
+ $expected = '<select id="post_type" name="cptui_selected_post_type[post_type]">
286
+ <option value="">--</option>
287
+ <option value="movie">Movies</option>
288
+ <option value="tv_show">TV Show</option>
289
+ </select>';
290
+
291
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
292
+ }
293
+
294
+ /**
295
+ * Tests non boolean based select inputs
296
+ */
297
+ public function test_CPTUI_Select_Non_Bool_First_Option() {
298
+ $ui = new cptui_admin_ui();
299
+
300
+ $select = array();
301
+ $select['options'] = array();
302
+
303
+ $select['options'][] = array( 'attr' => '', 'text' => '--' );
304
+ $select['options'][] = array( 'attr' => 'movie', 'text' => 'Movies' );
305
+ $select['options'][] = array( 'attr' => 'tv_show', 'text' => 'TV Show' );
306
+
307
+ $select['selected'] = 'movie';
308
+ $args = array(
309
+ 'namearray' => 'cptui_selected_post_type',
310
+ 'name' => 'post_type',
311
+ 'selections' => $select,
312
+ 'wrap' => false
313
+ );
314
+
315
+ $expected = '<select id="post_type" name="cptui_selected_post_type[post_type]">
316
+ <option value="">--</option>
317
+ <option value="movie" selected="selected">Movies</option>
318
+ <option value="tv_show">TV Show</option>
319
+ </select>';
320
+
321
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
322
+ }
323
+
324
+ /**
325
+ * Tests non boolean based select inputs
326
+ */
327
+ public function test_CPTUI_Select_Non_Bool_Second_Option() {
328
+ $ui = new cptui_admin_ui();
329
+
330
+ $select = array();
331
+ $select['options'] = array();
332
+
333
+ $select['options'][] = array( 'attr' => '', 'text' => '--' );
334
+ $select['options'][] = array( 'attr' => 'movie', 'text' => 'Movies' );
335
+ $select['options'][] = array( 'attr' => 'tv_show', 'text' => 'TV Show' );
336
+
337
+ $select['selected'] = 'tv_show';
338
+ $args = array(
339
+ 'namearray' => 'cptui_selected_post_type',
340
+ 'name' => 'post_type',
341
+ 'selections' => $select,
342
+ 'wrap' => false
343
+ );
344
+
345
+ $expected = '<select id="post_type" name="cptui_selected_post_type[post_type]">
346
+ <option value="">--</option>
347
+ <option value="movie">Movies</option>
348
+ <option value="tv_show" selected="selected">TV Show</option>
349
+ </select>';
350
+
351
+ $this->assertHTMLstringsAreEqual( $expected, $ui->get_select_input( $args ) );
352
+ }
353
+
354
+ public function providertest_something()
355
+ {
356
+ return array(
357
+ array('This string will be sluggified', 'this-string-will-be-sluggified'),
358
+ array('THIS STRING WILL BE SLUGGIFIED', 'this-string-will-be-sluggified'),
359
+ array('This1 string2 will3 be 44 sluggified10', 'this1-string2-will3-be-44-sluggified10'),
360
+ array('This! @string#$ %$will ()be "sluggified', 'this-string-will-be-sluggified'),
361
+ array("Tänk efter nu – förr'n vi föser dig bort", 'tank-efter-nu-forrn-vi-foser-dig-bort'),
362
+ array('', ''),
363
+ );
364
+ }
365
+ }
tests/CPTUI-Admin-UI-Wrappers-Test.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( 'CPTUI-Base-Tests.php' );
3
+
4
+ /**
5
+ * An example test case.
6
+ */
7
+ class CPTUI_Admin_UI_Wrappers extends CPTUI_Base_Tests {
8
+
9
+ public function setUp() {
10
+ parent::setUp();
11
+ }
12
+
13
+ public function tearDown() {
14
+ parent::tearDown();
15
+ }
16
+
17
+ /**
18
+ * Tests our opening tr method.
19
+ */
20
+ public function test_CPTUI_Opening_TR() {
21
+ $ui = new cptui_admin_ui();
22
+ $expected = '<tr valign="top">';
23
+
24
+ $this->assertEquals( $expected, $ui->get_tr_start() );
25
+ }
26
+
27
+ /**
28
+ * Tests our closing tr method.
29
+ */
30
+ public function test_CPTUI_Closing_TR() {
31
+ $ui = new cptui_admin_ui();
32
+ $expected = '</tr>';
33
+
34
+ $this->assertEquals( $expected, $ui->get_tr_end() );
35
+ }
36
+
37
+ /**
38
+ * Tests our opening th method.
39
+ */
40
+ public function test_CPTUI_Opening_TH() {
41
+ $ui = new cptui_admin_ui();
42
+ $expected = '<th scope="row">';
43
+
44
+ $this->assertEquals( $expected, $ui->get_th_start() );
45
+ }
46
+
47
+ /**
48
+ * Tests our closing th method.
49
+ */
50
+ public function test_CPTUI_Closing_TH() {
51
+ $ui = new cptui_admin_ui();
52
+ $expected = '</th>';
53
+
54
+ $this->assertEquals( $expected, $ui->get_th_end() );
55
+ }
56
+
57
+ /**
58
+ * Tests our opening td method.
59
+ */
60
+ public function test_CPTUI_Opening_TD() {
61
+ $ui = new cptui_admin_ui();
62
+ $expected = '<td>';
63
+
64
+ $this->assertEquals( $expected, $ui->get_td_start() );
65
+ }
66
+
67
+ /**
68
+ * Tests our closing td method.
69
+ */
70
+ public function test_CPTUI_Closing_TD() {
71
+ $ui = new cptui_admin_ui();
72
+ $expected = '</td>';
73
+
74
+ $this->assertEquals( $expected, $ui->get_td_end() );
75
+ }
76
+
77
+ /**
78
+ * Tests our wrapping p tag.
79
+ */
80
+ public function test_CPTUI_P_Wrap() {
81
+ $ui = new cptui_admin_ui();
82
+ $expected = '<p>CPTUI is Awesome!</p>';
83
+
84
+ $this->assertEquals( $expected, $ui->get_p( 'CPTUI is Awesome!' ) );
85
+
86
+ }
87
+ }
tests/CPTUI-Base-Tests.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class CPTUI_Base_Tests extends WP_UnitTestCase {
4
+
5
+ public function setUp() {
6
+ parent::setUp();
7
+ }
8
+
9
+ public function tearDown() {
10
+ parent::tearDown();
11
+ }
12
+
13
+ public function assertHTMLstringsAreEqual( $expected_string, $string_to_test ) {
14
+ $expected_string = $this->normalize_string( $expected_string );
15
+ $string_to_test = $this->normalize_string( $string_to_test );
16
+ $compare = strcmp( $expected_string, $string_to_test );
17
+ if ( 0 !== $compare ) {
18
+ $compare = strspn( $expected_string ^ $string_to_test, "\0" );
19
+ $chars_to_show = 50;
20
+ $start = ( $compare - 5 );
21
+ $pointer = '|--->>';
22
+ $sep = "\n". str_repeat( '-', 75 );
23
+ $compare = sprintf(
24
+ $sep . "\nFirst difference at position %d:\n\n Expected: \t%s\n Actual: \t%s\n" . $sep,
25
+ $compare,
26
+ substr( $expected_string, $start, 5 ) . $pointer . substr( $expected_string, $compare, $chars_to_show ),
27
+ substr( $string_to_test, $start, 5 ) . $pointer . substr( $string_to_test, $compare, $chars_to_show )
28
+ );
29
+ }
30
+ return $this->assertEquals( $expected_string, $string_to_test, ! empty( $compare ) ? $compare : null );
31
+ }
32
+
33
+
34
+ public function assertIsDefined( $definition ) {
35
+ return $this->assertTrue( defined( $definition ), "$definition is not defined." );
36
+ }
37
+
38
+ public function normalize_string( $string ) {
39
+ return trim( preg_replace( array(
40
+ '/[\t\n\r]/', // Remove tabs and newlines
41
+ '/\s{2,}/', // Replace repeating spaces with one space
42
+ '/> </', // Remove spaces between carats
43
+ ), array(
44
+ '',
45
+ ' ',
46
+ '><',
47
+ ), $string ) );
48
+ }
49
+ }
tests/CPTUI-Utilities-Test.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once( 'CPTUI-Base-Tests.php' );
3
+
4
+ class CPTUI_Utility extends CPTUI_Base_Tests {
5
+
6
+ public $post_type_array = array();
7
+ public $taxonomy_array = array();
8
+
9
+ public function setUp() {
10
+ parent::setUp();
11
+ }
12
+
13
+ public function tearDown() {
14
+ parent::tearDown();
15
+ }
16
+
17
+ /**
18
+ * @before
19
+ */
20
+ public function setupPostTypeTax() {
21
+ $this->post_type_array = $this->setup_cpt_option();
22
+ $this->taxonomy_array = $this->setup_tax_option();
23
+ }
24
+
25
+ /**
26
+ * @after
27
+ */
28
+ public function removePostTypeTax() {
29
+ _unregister_post_type( 'movie' );
30
+ _unregister_taxonomy( 'actors' );
31
+ }
32
+
33
+ /**
34
+ * Tests our setting of our post type option and retrieval afterwards.
35
+ */
36
+ public function test_CPTUI_set_post_type_option() {
37
+ $this->assertTrue( is_array( $this->post_type_array ), 'Option returned false' );
38
+ $this->assertArrayHasKey( 'movie', $this->post_type_array, 'Movie was not found in returned option value' );
39
+ }
40
+
41
+ /**
42
+ * Tests that we have our needed post type functions
43
+ */
44
+ public function test_CPTUI_post_type_registration_function_exists() {
45
+ $this->assertTrue( function_exists( 'cptui_register_single_post_type' ) );
46
+ }
47
+
48
+ /**
49
+ * Tests for successful registering of post types with our own custom functions.
50
+ */
51
+ public function test_CPTUI_registered_post_type() {
52
+ $this->register_post_type();
53
+
54
+ $registered = get_post_types();
55
+ $this->assertArrayHasKey( 'movie', $registered );
56
+ }
57
+
58
+ /**
59
+ * Tests for our registered labels for the post type.
60
+ */
61
+ public function test_CPTUI_registered_post_type_labels_names() {
62
+ $this->register_post_type();
63
+
64
+ $movie = get_post_type_object( 'movie' );
65
+ $this->assertTrue( is_object( $movie ) );
66
+ $this->assertTrue( is_object( $movie->labels ) );
67
+ $this->assertNotEmpty( $movie->labels, 'No labels available' );
68
+
69
+ $this->assertEquals( 'Movies', $movie->labels->name );
70
+ $this->assertEquals( 'Movie', $movie->labels->singular_name );
71
+ $this->assertEquals( 'My Movies', $movie->labels->menu_name );
72
+ $this->assertEquals( 'All Movies', $movie->labels->all_items );
73
+ $this->assertEquals( 'Add New', $movie->labels->add_new );
74
+ $this->assertEquals( 'Add New Movie', $movie->labels->add_new_item );
75
+ $this->assertEquals( 'Edit', $movie->labels->edit );
76
+ $this->assertEquals( 'Edit Movie', $movie->labels->edit_item );
77
+ $this->assertEquals( 'New Movie', $movie->labels->new_item );
78
+ $this->assertEquals( 'View', $movie->labels->view );
79
+ $this->assertEquals( 'View Movie', $movie->labels->view_item );
80
+ $this->assertEquals( 'Search Movies', $movie->labels->search_items );
81
+ $this->assertEquals( 'No Movies Found', $movie->labels->not_found );
82
+ $this->assertEquals( 'No Movies found in trash', $movie->labels->not_found_in_trash );
83
+ $this->assertEquals( 'Parent Movie', $movie->labels->parent );
84
+ }
85
+
86
+ /**
87
+ * Tests our setting of our taxonomy option and retrieval afterwards.
88
+ */
89
+ public function test_CPTUI_set_taxonomy_option() {
90
+ $this->assertTrue( is_array( $this->taxonomy_array ), 'Option returned false' );
91
+ $this->assertArrayHasKey( 'actors', $this->taxonomy_array, 'Actors was not found in returned option value' );
92
+ }
93
+
94
+ /**
95
+ * Tests that we have our needed taxonomy functions
96
+ */
97
+ public function test_CPTUI_taxonomy_registration_function_exists() {
98
+ $this->assertTrue( function_exists( 'cptui_register_single_taxonomy' ) );
99
+ }
100
+
101
+ /**
102
+ * Tests for successful registering of taxonomies with our own custom functions.
103
+ */
104
+ public function test_CPTUI_registered_taxonomy() {
105
+ $this->register_post_type();
106
+ $this->register_taxonomy();
107
+
108
+ $registered = get_taxonomies();
109
+ $this->assertArrayHasKey( 'actors', $registered );
110
+ }
111
+
112
+ /**
113
+ * Tests for our registered labels for the taxonomy.
114
+ */
115
+ public function test_CPTUI_registered_taxonomy_labels_names() {
116
+ $this->register_post_type();
117
+ $this->register_taxonomy();
118
+
119
+ $actor = get_taxonomy( 'actors' );
120
+ $this->assertTrue( is_object( $actor ) );
121
+ $this->assertTrue( is_object( $actor->labels ) );
122
+ $this->assertNotEmpty( $actor->labels, 'No labels available' );
123
+
124
+ }
125
+
126
+ public function test_get_disp_boolean() {
127
+
128
+ $this->assertFalse( get_disp_boolean( 0 ) );
129
+ $this->assertFalse( get_disp_boolean( '0' ) );
130
+ $this->assertFalse( get_disp_boolean( false ) );
131
+ $this->assertFalse( get_disp_boolean( 'false' ) );
132
+ $this->assertFalse( get_disp_boolean( '' ) );
133
+ $this->assertFalse( get_disp_boolean( null ) );
134
+
135
+ $this->assertTrue( get_disp_boolean( 1 ) );
136
+ $this->assertTrue( get_disp_boolean( '1' ) );
137
+ $this->assertTrue( get_disp_boolean( true ) );
138
+ $this->assertTrue( get_disp_boolean( 'true' ) );
139
+ $this->assertTrue( get_disp_boolean( 'abcd' ) );
140
+ $this->assertTrue( get_disp_boolean( 1235 ) );
141
+ }
142
+
143
+ public function test_disp_boolean() {
144
+
145
+ $this->assertEquals( 'false', disp_boolean( 0 ) );
146
+ $this->assertEquals( 'false', disp_boolean( '0' ) );
147
+ $this->assertEquals( 'false', disp_boolean( false ) );
148
+ $this->assertEquals( 'false', disp_boolean( 'false' ) );
149
+ $this->assertEquals( 'false', disp_boolean( '' ) );
150
+ $this->assertEquals( 'false', disp_boolean( null ) );
151
+
152
+ $this->assertEquals( 'true', disp_boolean( 1 ) );
153
+ $this->assertEquals( 'true', disp_boolean( '1' ) );
154
+ $this->assertEquals( 'true', disp_boolean( true ) );
155
+ $this->assertEquals( 'true', disp_boolean( 'true' ) );
156
+ $this->assertEquals( 'true', disp_boolean( 'abcd' ) );
157
+ $this->assertEquals( 'true', disp_boolean( 1235 ) );
158
+
159
+ }
160
+
161
+ /**
162
+ * Create our base post type to test.
163
+ * @return mixed|void
164
+ */
165
+ public function setup_cpt_option() {
166
+
167
+ $custom = 'a:1:{s:5:"movie";a:21:{s:4:"name";s:5:"movie";s:5:"label";s:6:"Movies";s:14:"singular_label";s:5:"Movie";s:11:"description";s:0:"";s:6:"public";s:4:"true";s:7:"show_ui";s:4:"true";s:11:"has_archive";s:5:"false";s:19:"exclude_from_search";s:5:"false";s:15:"capability_type";s:4:"post";s:12:"hierarchical";s:5:"false";s:7:"rewrite";s:4:"true";s:12:"rewrite_slug";s:0:"";s:17:"rewrite_withfront";s:4:"true";s:9:"query_var";s:4:"true";s:13:"menu_position";s:0:"";s:12:"show_in_menu";s:4:"true";s:19:"show_in_menu_string";s:0:"";s:9:"menu_icon";N;s:8:"supports";a:0:{}s:10:"taxonomies";a:0:{}s:6:"labels";a:13:{s:9:"menu_name";s:9:"My Movies";s:9:"all_items";s:10:"All Movies";s:7:"add_new";s:7:"Add New";s:12:"add_new_item";s:13:"Add New Movie";s:4:"edit";s:4:"Edit";s:9:"edit_item";s:10:"Edit Movie";s:8:"new_item";s:9:"New Movie";s:4:"view";s:4:"View";s:9:"view_item";s:10:"View Movie";s:12:"search_items";s:13:"Search Movies";s:9:"not_found";s:15:"No Movies Found";s:18:"not_found_in_trash";s:24:"No Movies found in trash";s:6:"parent";s:12:"Parent Movie";}}}';
168
+ update_option( 'cptui_post_types', maybe_unserialize( $custom ) );
169
+
170
+ return get_option( 'cptui_post_types' );
171
+ }
172
+
173
+ /**
174
+ * Create our base taxonomy to test
175
+ * @return mixed|void
176
+ */
177
+ public function setup_tax_option() {
178
+
179
+ $custom = 'a:1:{s:6:"actors";a:14:{s:4:"name";s:6:"actors";s:5:"label";s:6:"Actors";s:14:"singular_label";s:5:"Actor";s:12:"hierarchical";s:5:"false";s:7:"show_ui";s:4:"true";s:9:"query_var";s:4:"true";s:14:"query_var_slug";s:0:"";s:7:"rewrite";s:4:"true";s:12:"rewrite_slug";s:0:"";s:17:"rewrite_withfront";s:1:"1";s:20:"rewrite_hierarchical";s:1:"0";s:17:"show_admin_column";s:5:"false";s:6:"labels";a:0:{}s:11:"object_type";a:1:{i:0;s:5:"movie";}}}';
180
+ update_option( 'cptui_taxonomies', maybe_unserialize( $custom ) );
181
+
182
+ return get_option( 'cptui_taxonomies' );
183
+ }
184
+
185
+ public function register_post_type() {
186
+ cptui_register_single_post_type( $this->post_type_array['movie'] );
187
+ }
188
+
189
+ public function register_taxonomy() {
190
+ cptui_register_single_taxonomy( $this->taxonomy_array['actors'] );
191
+ }
192
+
193
+ }
tests/bootstrap.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ini_set('display_errors','on');
4
+ error_reporting(E_ALL);
5
+
6
+ /**
7
+ * Set `WP_TESTS_DIR` to the base directory of WordPress:
8
+ * `svn export http://develop.svn.wordpress.org/trunk/ /tmp/wordpress-tests`
9
+ *
10
+ * Then add this to your bash environment:
11
+ *
12
+ * export WP_TESTS_DIR=/tmp/wordpress/tests
13
+ */
14
+ if ( ! $wp_test_dir = getenv('WP_TESTS_DIR') ) {
15
+
16
+ $wp_test_dir = '/tmp/wordpress-tests-lib';
17
+
18
+ if ( ! file_exists( $wp_test_dir . '/includes' ) ) {
19
+ die( "Fatal Error: Could not find the WordPress tests directory.\n" );
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Loads WP utility functions like `tests_add_filter` and `_delete_all_posts`.
25
+ */
26
+ require_once $wp_test_dir . '/includes/functions.php';
27
+
28
+ /**
29
+ * Preset wp_options before loading the WordPress stack.
30
+ *
31
+ * Used to activate themes, plugins, as well as other settings in `wp_options`.
32
+ *
33
+ * @see wp_tests_options
34
+ */
35
+ $GLOBALS['wp_tests_options'] = array(
36
+ 'active_plugins' => array(
37
+ 'hello.php',
38
+ ),
39
+ );
40
+
41
+ /**
42
+ * Run custom functionality after mu-plugins are loaded.
43
+ */
44
+ function _tests_load_cptui() {
45
+ define( 'CPTUI_DIRECTORY_PATH', trailingslashit( dirname( dirname( __FILE__ ) ) ) );
46
+ require CPTUI_DIRECTORY_PATH . 'custom-post-type-ui.php';
47
+ }
48
+ tests_add_filter( 'muplugins_loaded', '_tests_load_cptui' );
49
+
50
+ /**
51
+ * Bootstraps the WordPress stack.
52
+ */
53
+ require $wp_test_dir . '/includes/bootstrap.php';