Admin Post Navigation - Version 2.0

Version Description

Recommended update: added RTL support, moved CSS & JS into enqueueable files, enabled navigation for media files, adjustments to utilize language packs, minor unit test tweaks, noted compatibility through WP 4.4+, and updated copyright date

Download this release

Release Info

Developer coffee2code
Plugin Icon 128x128 Admin Post Navigation
Version 2.0
Comparing to
See all releases

Code changes from version 1.9.2 to 2.0

admin-post-navigation.php CHANGED
@@ -1,17 +1,16 @@
1
  <?php
2
  /**
3
  * Plugin Name: Admin Post Navigation
4
- * Version: 1.9.2
5
  * Plugin URI: http://coffee2code.com/wp-plugins/admin-post-navigation/
6
  * Author: Scott Reilly
7
  * Author URI: http://coffee2code.com/
8
  * Text Domain: admin-post-navigation
9
- * Domain Path: /lang/
10
  * License: GPLv2 or later
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
  * Description: Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
13
  *
14
- * Compatible with WordPress 3.0 through 4.3+.
15
  *
16
  * =>> Read the accompanying readme.txt file for instructions and documentation.
17
  * =>> Also, visit the plugin's homepage for additional information and updates.
@@ -19,23 +18,21 @@
19
  *
20
  * @package Admin_Post_Navigation
21
  * @author Scott Reilly
22
- * @version 1.9.2
23
  */
24
 
25
  /*
26
  * TODO:
27
- * - Drop pre-WP3.6 support and pass post to the_title_attribute() in add_meta_box()
28
  * - Hide screen option checkbox for metabox if metabox is being hidden
29
  * - Add screen option allowing user selection of post navigation order
30
  * - Add more unit tests
31
- * - Put CSS into enqueuable .css file
32
- * - Put JS into enqueueable .js file
33
  * - Add dropdown to post nav links to allow selecting different types of things
34
  * to navigate to (e.g. next draft (if looking at a draft), next in category X)
35
  */
36
 
37
  /*
38
- Copyright (c) 2008-2015 by Scott Reilly (aka coffee2code)
39
 
40
  This program is free software; you can redistribute it and/or
41
  modify it under the terms of the GNU General Public License
@@ -58,9 +55,42 @@ if ( ! class_exists( 'c2c_AdminPostNavigation' ) ) :
58
 
59
  class c2c_AdminPostNavigation {
60
 
 
 
 
 
 
 
 
61
  private static $prev_text = '';
 
 
 
 
 
 
 
 
62
  private static $next_text = '';
63
- private static $post_statuses = array( 'draft', 'future', 'pending', 'private', 'publish' ); // Filterable later
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  private static $post_statuses_sql = '';
65
 
66
  /**
@@ -69,7 +99,7 @@ class c2c_AdminPostNavigation {
69
  * @since 1.7
70
  */
71
  public static function version() {
72
- return '1.9.2';
73
  }
74
 
75
  /**
@@ -87,18 +117,34 @@ class c2c_AdminPostNavigation {
87
  public static function register_post_page_hooks() {
88
 
89
  // Load textdomain.
90
- load_plugin_textdomain( 'admin-post-navigation', false, basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'lang' );
91
 
92
  // Set translatable strings.
93
  self::$prev_text = apply_filters( 'c2c_admin_post_navigation_prev_text', __( '&larr; Previous', 'admin-post-navigation' ) );
94
  self::$next_text = apply_filters( 'c2c_admin_post_navigation_next_text', __( 'Next &rarr;', 'admin-post-navigation' ) );
95
 
96
  // Register hooks.
97
- add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_css' ) );
98
- add_action( 'admin_print_footer_scripts', array( __CLASS__, 'add_js' ) );
99
  add_action( 'do_meta_boxes', array( __CLASS__, 'do_meta_box' ), 10, 3 );
100
  }
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  /**
103
  * Register meta box.
104
  *
@@ -146,7 +192,7 @@ class c2c_AdminPostNavigation {
146
 
147
  $prev = self::previous_post();
148
  if ( $prev ) {
149
- $post_title = strip_tags( get_the_title( $prev->ID ) ); /* TODO: Drop pre-WP3.6 support and pass post to the_title_attribute() instead */
150
  $display .= '<a href="' . get_edit_post_link( $prev->ID ) . '" id="admin-post-nav-prev" title="' .
151
  esc_attr( sprintf( __( 'Previous %1$s: %2$s', 'admin-post-navigation' ), $context, $post_title ) ) .
152
  '" class="admin-post-nav-prev add-new-h2">' . self::$prev_text . '</a>';
@@ -154,10 +200,10 @@ class c2c_AdminPostNavigation {
154
 
155
  $next = self::next_post();
156
  if ( $next ) {
157
- if ( ! empty( $display ) ) {
158
  $display .= ' ';
159
  }
160
- $post_title = strip_tags( get_the_title( $next->ID ) ); /* TODO: Drop pre-WP3.6 support and pass post to the_title_attribute() instead */
161
  $display .= '<a href="' . get_edit_post_link( $next->ID ) .
162
  '" id="admin-post-nav-next" title="' .
163
  esc_attr( sprintf( __( 'Next %1$s: %2$s', 'admin-post-navigation' ), $context, $post_title ) ).
@@ -187,43 +233,6 @@ class c2c_AdminPostNavigation {
187
  return strtolower( $label );
188
  }
189
 
190
- /**
191
- * Outputs CSS within style tags.
192
- */
193
- public static function add_css() {
194
- echo <<<HTML
195
- <style type="text/css">
196
- #admin-post-nav {margin-left:20px;}
197
- #adminpostnav #admin-post-nav {margin-left:0;}
198
- h2 #admin-post-nav {font-size:0.6em;}
199
- .inside #admin-post-nav a {top:0;margin-top:4px;display:inline-block;}
200
- </style>
201
-
202
- HTML;
203
- }
204
-
205
- /**
206
- * Outputs the JavaScript used by the plugin.
207
- *
208
- * For those with JS enabled, the navigation links are moved next to the
209
- * "Edit Post" header and the plugin's meta_box is hidden. The fallback
210
- * for non-JS people is that the plugin's meta_box is shown and the
211
- * navigation links can be found there.
212
- */
213
- public static function add_js() {
214
- $tag = version_compare( $GLOBALS['wp_version'], '4.3', '>=' ) ? 'h1' : 'h2';
215
-
216
- echo <<<JS
217
- <script type="text/javascript">
218
- jQuery(document).ready(function($) {
219
- $('#admin-post-nav').appendTo($('#wpbody-content .wrap:first {$tag}:first'));
220
- $('#adminpostnav, label[for="adminpostnav-hide"]').hide();
221
- });
222
- </script>
223
-
224
- JS;
225
- }
226
-
227
  /**
228
  * Returns the previous or next post relative to the current post.
229
  *
@@ -259,10 +268,10 @@ JS;
259
  $sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = '$post_type' AND post_status IN (" . self::$post_statuses_sql . ') ';
260
 
261
  // Determine order.
262
- if ( function_exists( 'is_post_type_hierarchical' ) && is_post_type_hierarchical( $post_type ) ) {
263
  $orderby = 'post_title';
264
  } else {
265
- $orderby = 'ID';
266
  }
267
  $default_orderby = $orderby;
268
  // Restrict orderby to actual post fields.
1
  <?php
2
  /**
3
  * Plugin Name: Admin Post Navigation
4
+ * Version: 2.0
5
  * Plugin URI: http://coffee2code.com/wp-plugins/admin-post-navigation/
6
  * Author: Scott Reilly
7
  * Author URI: http://coffee2code.com/
8
  * Text Domain: admin-post-navigation
 
9
  * License: GPLv2 or later
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  * Description: Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
12
  *
13
+ * Compatible with WordPress 3.0 through 4.5+.
14
  *
15
  * =>> Read the accompanying readme.txt file for instructions and documentation.
16
  * =>> Also, visit the plugin's homepage for additional information and updates.
18
  *
19
  * @package Admin_Post_Navigation
20
  * @author Scott Reilly
21
+ * @version 2.0
22
  */
23
 
24
  /*
25
  * TODO:
26
+ * - Add ability for navigation to save current post before navigating away.
27
  * - Hide screen option checkbox for metabox if metabox is being hidden
28
  * - Add screen option allowing user selection of post navigation order
29
  * - Add more unit tests
 
 
30
  * - Add dropdown to post nav links to allow selecting different types of things
31
  * to navigate to (e.g. next draft (if looking at a draft), next in category X)
32
  */
33
 
34
  /*
35
+ Copyright (c) 2008-2016 by Scott Reilly (aka coffee2code)
36
 
37
  This program is free software; you can redistribute it and/or
38
  modify it under the terms of the GNU General Public License
55
 
56
  class c2c_AdminPostNavigation {
57
 
58
+ /**
59
+ * Translated text for previous link.
60
+ *
61
+ * @access private
62
+ *
63
+ * @var string
64
+ */
65
  private static $prev_text = '';
66
+
67
+ /**
68
+ * Translated text for next link.
69
+ *
70
+ * @access private
71
+ *
72
+ * @var string
73
+ */
74
  private static $next_text = '';
75
+
76
+ /**
77
+ * Default post statuses for navigation.
78
+ *
79
+ * Filterable later.
80
+ *
81
+ * @access private
82
+ *
83
+ * @var array
84
+ */
85
+ private static $post_statuses = array( 'draft', 'future', 'pending', 'private', 'publish', 'inherit' );
86
+
87
+ /**
88
+ * Post status query fragment.
89
+ *
90
+ * @access private
91
+ *
92
+ * @var string
93
+ */
94
  private static $post_statuses_sql = '';
95
 
96
  /**
99
  * @since 1.7
100
  */
101
  public static function version() {
102
+ return '2.0';
103
  }
104
 
105
  /**
117
  public static function register_post_page_hooks() {
118
 
119
  // Load textdomain.
120
+ load_plugin_textdomain( 'admin-post-navigation' );
121
 
122
  // Set translatable strings.
123
  self::$prev_text = apply_filters( 'c2c_admin_post_navigation_prev_text', __( '&larr; Previous', 'admin-post-navigation' ) );
124
  self::$next_text = apply_filters( 'c2c_admin_post_navigation_next_text', __( 'Next &rarr;', 'admin-post-navigation' ) );
125
 
126
  // Register hooks.
127
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts_and_styles' ) );
 
128
  add_action( 'do_meta_boxes', array( __CLASS__, 'do_meta_box' ), 10, 3 );
129
  }
130
 
131
+ /**
132
+ * Enqueues scripts and stylesheets on post edit admin pages.
133
+ *
134
+ * @since 2.0
135
+ */
136
+ public static function admin_enqueue_scripts_and_styles() {
137
+ wp_register_style( 'admin-post-navigation-admin', plugins_url( 'assets/admin-post-navigation.css', __FILE__ ), array(), self::version() );
138
+ wp_enqueue_style( 'admin-post-navigation-admin' );
139
+
140
+ wp_register_script( 'admin-post-navigation-admin', plugins_url( 'assets/admin-post-navigation.js', __FILE__ ), array( 'jquery' ), self::version(), true );
141
+ // Localize script.
142
+ wp_localize_script( 'admin-post-navigation-admin', 'c2c_apn', array(
143
+ 'tag' => version_compare( $GLOBALS['wp_version'], '4.3', '>=' ) ? 'h1' : 'h2',
144
+ ) );
145
+ wp_enqueue_script( 'admin-post-navigation-admin' );
146
+ }
147
+
148
  /**
149
  * Register meta box.
150
  *
192
 
193
  $prev = self::previous_post();
194
  if ( $prev ) {
195
+ $post_title = the_title_attribute( array( 'echo' => false, 'post' => $prev->ID ) );
196
  $display .= '<a href="' . get_edit_post_link( $prev->ID ) . '" id="admin-post-nav-prev" title="' .
197
  esc_attr( sprintf( __( 'Previous %1$s: %2$s', 'admin-post-navigation' ), $context, $post_title ) ) .
198
  '" class="admin-post-nav-prev add-new-h2">' . self::$prev_text . '</a>';
200
 
201
  $next = self::next_post();
202
  if ( $next ) {
203
+ if ( $display ) {
204
  $display .= ' ';
205
  }
206
+ $post_title = the_title_attribute( array( 'echo' => false, 'post' => $next->ID ) );
207
  $display .= '<a href="' . get_edit_post_link( $next->ID ) .
208
  '" id="admin-post-nav-next" title="' .
209
  esc_attr( sprintf( __( 'Next %1$s: %2$s', 'admin-post-navigation' ), $context, $post_title ) ).
233
  return strtolower( $label );
234
  }
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  /**
237
  * Returns the previous or next post relative to the current post.
238
  *
268
  $sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = '$post_type' AND post_status IN (" . self::$post_statuses_sql . ') ';
269
 
270
  // Determine order.
271
+ if ( is_post_type_hierarchical( $post_type ) ) {
272
  $orderby = 'post_title';
273
  } else {
274
+ $orderby = 'post_date';
275
  }
276
  $default_orderby = $orderby;
277
  // Restrict orderby to actual post fields.
assets/admin-post-navigation.css ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #admin-post-nav {
2
+ margin-left: 20px;
3
+ display: inline-block;
4
+ }
5
+ .rtl #admin-post-nav {
6
+ margin-right:20px;
7
+ }
8
+ #adminpostnav #admin-post-nav {
9
+ margin-left: 0;
10
+ }
11
+ .rtl #adminpostnav #admin-post-nav {
12
+ margin-right: 0;
13
+ }
14
+ .rtl #admin-post-nav a {
15
+ display: inline-block;
16
+ line-height: initial;
17
+ }
18
+ h2 #admin-post-nav {
19
+ font-size: 0.6em;
20
+ }
21
+ .inside #admin-post-nav a {
22
+ top: 0;
23
+ margin-top: 4px;
24
+ display: inline-block;
25
+ }
assets/admin-post-navigation.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ $('#admin-post-nav').appendTo($('#wpbody-content .wrap:first ' + c2c_apn.tag + ':first'));
3
+ $('#adminpostnav, label[for="adminpostnav-hide"]').hide();
4
+ });
index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
lang/admin-post-navigation.pot DELETED
@@ -1,57 +0,0 @@
1
- # Translation of the WordPress plugin Admin Post Navigation v1.9 by Scott Reilly.
2
- # Copyright (C) 2015 Scott Reilly
3
- # This file is distributed under the same license as the Admin Post Navigation plugin.
4
- msgid ""
5
- msgstr ""
6
- "Project-Id-Version: Admin Post Navigation 1.9\n"
7
- "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/admin-post-"
8
- "navigation\n"
9
- "POT-Creation-Date: 2015-03-14 08:03:14+00:00\n"
10
- "MIME-Version: 1.0\n"
11
- "Content-Type: text/plain; charset=UTF-8\n"
12
- "Content-Transfer-Encoding: 8bit\n"
13
- "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
14
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
- "Language-Team: LANGUAGE <LL@li.org>\n"
16
-
17
- #: admin-post-navigation.php:93
18
- msgid "&larr; Previous"
19
- msgstr ""
20
-
21
- #: admin-post-navigation.php:94
22
- msgid "Next &rarr;"
23
- msgstr ""
24
-
25
- #: admin-post-navigation.php:128
26
- msgid "%s Navigation"
27
- msgstr ""
28
-
29
- #: admin-post-navigation.php:152
30
- msgid "Previous %1$s: %2$s"
31
- msgstr ""
32
-
33
- #: admin-post-navigation.php:164
34
- msgid "Next %1$s: %2$s"
35
- msgstr ""
36
-
37
- #. Plugin Name of the plugin/theme
38
- msgid "Admin Post Navigation"
39
- msgstr ""
40
-
41
- #. Plugin URI of the plugin/theme
42
- msgid "http://coffee2code.com/wp-plugins/admin-post-navigation/"
43
- msgstr ""
44
-
45
- #. Description of the plugin/theme
46
- msgid ""
47
- "Adds links to navigate to the next and previous posts when editing a post in "
48
- "the WordPress admin."
49
- msgstr ""
50
-
51
- #. Author of the plugin/theme
52
- msgid "Scott Reilly"
53
- msgstr ""
54
-
55
- #. Author URI of the plugin/theme
56
- msgid "http://coffee2code.com/"
57
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,9 +4,9 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: admin, navigation, post, next, previous, edit, post types, coffee2code
5
  License: GPLv2 or later
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
- Requires at least: 3.0
8
- Tested up to: 4.3
9
- Stable tag: 1.9.2
10
 
11
  Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
12
 
@@ -227,6 +227,24 @@ add_filter( 'c2c_admin_post_navigation_display', 'override_apn_display' );
227
 
228
  == Changelog ==
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  = 1.9.2 (2015-08-19) =
231
  * Bugfix: Fix so navigation links appear in WordPress 4.3 (by targeting h1 instead of h2). Backwards compatibility maintained.
232
  * Update: Note compatibility through WP 4.3+
@@ -368,6 +386,9 @@ add_filter( 'c2c_admin_post_navigation_display', 'override_apn_display' );
368
 
369
  == Upgrade Notice ==
370
 
 
 
 
371
  = 1.9.2 =
372
  Bugfix: fix to display navigation links in WordPress 4.3; noted compatibility through WP 4.3+
373
 
4
  Tags: admin, navigation, post, next, previous, edit, post types, coffee2code
5
  License: GPLv2 or later
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
+ Requires at least: 4.0
8
+ Tested up to: 4.5
9
+ Stable tag: 2.0
10
 
11
  Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
12
 
227
 
228
  == Changelog ==
229
 
230
+ = 2.0 (2016-01-14) =
231
+ * New: Add support for RTL display.
232
+ * New: Enable post navigation for media when viewed/edited from list mode.
233
+ * New: Move CSS into enqueuable .css file.
234
+ * New: Move JS into enqueueable .js file.
235
+ * Bugfix: Navigate non-hierarchical posts by post_date by default for more expected ordering.
236
+ * Change: Use `the_title_attribute()` to get post title for use in attribute.
237
+ * Remove: Delete `add_css()` and `add_js()`.
238
+ * Change: Add support for language packs:
239
+ * Don't load plugin translations from file.
240
+ * Remove .pot file and /lang subdirectory.
241
+ * Change: Note compatibility through WP 4.4+.
242
+ * Change: Remove support for WordPress older than 4.0.
243
+ * Change: Explicitly declare methods in unit tests as public.
244
+ * Change: Update copyright date (2016).
245
+ * New: Add inline documentation for class variables.
246
+ * New: Create empty index.php to prevent files from being listed if web server has enabled directory listings.
247
+
248
  = 1.9.2 (2015-08-19) =
249
  * Bugfix: Fix so navigation links appear in WordPress 4.3 (by targeting h1 instead of h2). Backwards compatibility maintained.
250
  * Update: Note compatibility through WP 4.3+
386
 
387
  == Upgrade Notice ==
388
 
389
+ = 2.0 =
390
+ Recommended update: added RTL support, moved CSS & JS into enqueueable files, enabled navigation for media files, adjustments to utilize language packs, minor unit test tweaks, noted compatibility through WP 4.4+, and updated copyright date
391
+
392
  = 1.9.2 =
393
  Bugfix: fix to display navigation links in WordPress 4.3; noted compatibility through WP 4.3+
394
 
tests/test-admin-post-navigation.php CHANGED
@@ -1,14 +1,18 @@
1
  <?php
2
 
 
 
3
  class Admin_Post_Navigation_Test extends WP_UnitTestCase {
4
 
5
- function setUp() {
 
 
6
  parent::setUp();
7
 
8
  c2c_AdminPostNavigation::register_post_page_hooks();
9
  }
10
 
11
- function tearDown() {
12
  parent::tearDown();
13
 
14
  unset( $GLOBALS['post_ID'] );
@@ -20,19 +24,19 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
20
  }
21
 
22
 
23
- /*
24
- *
25
- * DATA PROVIDERS
26
- *
27
- */
28
 
29
 
30
 
31
- /*
32
- *
33
- * HELPER FUNCTIONS
34
- *
35
- */
36
 
37
 
38
  private function create_user( $role, $set_as_current = true ) {
@@ -55,6 +59,13 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
55
 
56
  $posts = $this->factory->post->create_many( $number, array( 'post_author' => $user_id ) );
57
 
 
 
 
 
 
 
 
58
  $GLOBALS['post_ID'] = $posts[ $current_post_index ];
59
  $current_post = get_post( $posts[ $current_post_index ] );
60
 
@@ -91,26 +102,26 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
91
  }
92
 
93
 
94
- /*
95
- *
96
- * TESTS
97
- *
98
- */
99
 
100
 
101
- function test_class_exists() {
102
  $this->assertTrue( class_exists( 'c2c_AdminPostNavigation' ) );
103
  }
104
 
105
- function test_version() {
106
- $this->assertEquals( '1.9.2', c2c_AdminPostNavigation::version() );
107
  }
108
 
109
  /*
110
  * c2c_AdminPostNavigation::next_post()
111
  */
112
 
113
- function test_navigate_next_to_post() {
114
  $posts = $this->create_posts();
115
 
116
  $next_post = c2c_AdminPostNavigation::next_post();
@@ -118,7 +129,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
118
  $this->assertEquals( $posts[3], $next_post->ID );
119
  }
120
 
121
- function test_navigate_next_at_end() {
122
  $posts = $this->create_posts( 5, 4 );
123
 
124
  $next_post = c2c_AdminPostNavigation::next_post();
@@ -126,7 +137,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
126
  $this->assertEmpty( $next_post );
127
  }
128
 
129
- function test_navigate_next_skips_unwhitelisted_post_status() {
130
  $posts = $this->create_posts();
131
 
132
  $post = get_post( $posts[3] );
@@ -138,7 +149,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
138
  $this->assertEquals( $posts[4], $next_post->ID );
139
  }
140
 
141
- function test_navigate_next_when_no_editable_next() {
142
  $posts = $this->create_posts();
143
  $user_id = $this->create_user( 'author' );
144
 
@@ -155,7 +166,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
155
  * c2c_AdminPostNavigation::previous_post()
156
  */
157
 
158
- function test_navigate_previous_to_post() {
159
  $posts = $this->create_posts();
160
 
161
  $previous_post = c2c_AdminPostNavigation::previous_post();
@@ -163,7 +174,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
163
  $this->assertEquals( $posts[1], $previous_post->ID );
164
  }
165
 
166
- function test_navigate_previous_at_beginning() {
167
  $posts = $this->create_posts( 5, 0 );
168
 
169
  $previous_post = c2c_AdminPostNavigation::previous_post();
@@ -171,7 +182,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
171
  $this->assertEmpty( $previous_post );
172
  }
173
 
174
- function test_navigate_previous_skips_unwhitelisted_post_status() {
175
  $posts = $this->create_posts();
176
 
177
  $post = get_post( $posts[1] );
@@ -183,7 +194,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
183
  $this->assertEquals( $posts[0], $previous_post->ID );
184
  }
185
 
186
- function test_navigate_previous_when_no_editable_previous() {
187
  $posts = $this->create_posts();
188
  $user_id = $this->create_user( 'author' );
189
 
@@ -202,23 +213,19 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
202
  */
203
 
204
 
205
- function test_hooks_action_load_post_php() {
206
  $this->assertEquals( 10, has_action( 'load-post.php', array( 'c2c_AdminPostNavigation', 'register_post_page_hooks' ) ) );
207
  }
208
 
209
- function test_hooks_action_admin_enqueue_scripts() {
210
- $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', array( 'c2c_AdminPostNavigation', 'add_css' ) ) );
211
- }
212
-
213
- function test_hooks_action_admin_print_footer_scripts() {
214
- $this->assertEquals( 10, has_action( 'admin_print_footer_scripts', array( 'c2c_AdminPostNavigation', 'add_js' ) ) );
215
  }
216
 
217
- function test_hooks_action_do_meta_boxes() {
218
  $this->assertEquals( 10, has_action( 'do_meta_boxes', array( 'c2c_AdminPostNavigation', 'do_meta_box' ) ) );
219
  }
220
 
221
- function test_filter_c2c_admin_post_navigation_post_statuses_when_adding_post_status() {
222
  add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
223
 
224
  $posts = $this->create_posts();
@@ -232,7 +239,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
232
  $this->assertEquals( $posts[3], $next_post->ID );
233
  }
234
 
235
- function test_filter_c2c_admin_post_navigation_post_statuses_when_removing_post_status() {
236
  add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
237
 
238
  $posts = $this->create_posts();
@@ -246,7 +253,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
246
  $this->assertEquals( $posts[4], $next_post->ID );
247
  }
248
 
249
- function test_filter_c2c_admin_post_navigation_orderby() {
250
  add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby' ), 10, 2 );
251
 
252
  $posts = $this->create_posts();
@@ -274,7 +281,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
274
  $this->assertEquals( $posts[4], $previous_post->ID );
275
  }
276
 
277
- function test_filter_c2c_admin_post_navigation_orderby_with_bad_value() {
278
  add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby_bad_value' ), 10, 2 );
279
 
280
  // Should function as if never hooked.
1
  <?php
2
 
3
+ defined( 'ABSPATH' ) or die();
4
+
5
  class Admin_Post_Navigation_Test extends WP_UnitTestCase {
6
 
7
+ private $run_number = 1;
8
+
9
+ public function setUp() {
10
  parent::setUp();
11
 
12
  c2c_AdminPostNavigation::register_post_page_hooks();
13
  }
14
 
15
+ public function tearDown() {
16
  parent::tearDown();
17
 
18
  unset( $GLOBALS['post_ID'] );
24
  }
25
 
26
 
27
+ //
28
+ //
29
+ // DATA PROVIDERS
30
+ //
31
+ //
32
 
33
 
34
 
35
+ //
36
+ //
37
+ // HELPER FUNCTIONS
38
+ //
39
+ //
40
 
41
 
42
  private function create_user( $role, $set_as_current = true ) {
59
 
60
  $posts = $this->factory->post->create_many( $number, array( 'post_author' => $user_id ) );
61
 
62
+ // Set publish_date to be different days. The default is now(), which the
63
+ // script runs fast enough that all posts appear published at same second.
64
+ foreach ( $posts as $i => $post ) {
65
+ $new_date = '2' . str_pad( $this->run_number++, 3, '0', STR_PAD_LEFT ) . '-01-' . str_pad( $i+1, 2, '0', STR_PAD_LEFT ) . ' 13:01:00';
66
+ wp_update_post( array( 'ID' => $post, 'edit_date' => true, 'post_date' => $new_date, 'post_date_gmt' => $new_date ), true );
67
+ }
68
+
69
  $GLOBALS['post_ID'] = $posts[ $current_post_index ];
70
  $current_post = get_post( $posts[ $current_post_index ] );
71
 
102
  }
103
 
104
 
105
+ //
106
+ //
107
+ // TESTS
108
+ //
109
+ //
110
 
111
 
112
+ public function test_class_exists() {
113
  $this->assertTrue( class_exists( 'c2c_AdminPostNavigation' ) );
114
  }
115
 
116
+ public function test_version() {
117
+ $this->assertEquals( '2.0', c2c_AdminPostNavigation::version() );
118
  }
119
 
120
  /*
121
  * c2c_AdminPostNavigation::next_post()
122
  */
123
 
124
+ public function test_navigate_next_to_post() {
125
  $posts = $this->create_posts();
126
 
127
  $next_post = c2c_AdminPostNavigation::next_post();
129
  $this->assertEquals( $posts[3], $next_post->ID );
130
  }
131
 
132
+ public function test_navigate_next_at_end() {
133
  $posts = $this->create_posts( 5, 4 );
134
 
135
  $next_post = c2c_AdminPostNavigation::next_post();
137
  $this->assertEmpty( $next_post );
138
  }
139
 
140
+ public function test_navigate_next_skips_unwhitelisted_post_status() {
141
  $posts = $this->create_posts();
142
 
143
  $post = get_post( $posts[3] );
149
  $this->assertEquals( $posts[4], $next_post->ID );
150
  }
151
 
152
+ public function test_navigate_next_when_no_editable_next() {
153
  $posts = $this->create_posts();
154
  $user_id = $this->create_user( 'author' );
155
 
166
  * c2c_AdminPostNavigation::previous_post()
167
  */
168
 
169
+ public function test_navigate_previous_to_post() {
170
  $posts = $this->create_posts();
171
 
172
  $previous_post = c2c_AdminPostNavigation::previous_post();
174
  $this->assertEquals( $posts[1], $previous_post->ID );
175
  }
176
 
177
+ public function test_navigate_previous_at_beginning() {
178
  $posts = $this->create_posts( 5, 0 );
179
 
180
  $previous_post = c2c_AdminPostNavigation::previous_post();
182
  $this->assertEmpty( $previous_post );
183
  }
184
 
185
+ public function test_navigate_previous_skips_unwhitelisted_post_status() {
186
  $posts = $this->create_posts();
187
 
188
  $post = get_post( $posts[1] );
194
  $this->assertEquals( $posts[0], $previous_post->ID );
195
  }
196
 
197
+ public function test_navigate_previous_when_no_editable_previous() {
198
  $posts = $this->create_posts();
199
  $user_id = $this->create_user( 'author' );
200
 
213
  */
214
 
215
 
216
+ public function test_hooks_action_load_post_php() {
217
  $this->assertEquals( 10, has_action( 'load-post.php', array( 'c2c_AdminPostNavigation', 'register_post_page_hooks' ) ) );
218
  }
219
 
220
+ public function test_hooks_action_admin_enqueue_scripts() {
221
+ $this->assertEquals( 10, has_action( 'admin_enqueue_scripts', array( 'c2c_AdminPostNavigation', 'admin_enqueue_scripts_and_styles' ) ) );
 
 
 
 
222
  }
223
 
224
+ public function test_hooks_action_do_meta_boxes() {
225
  $this->assertEquals( 10, has_action( 'do_meta_boxes', array( 'c2c_AdminPostNavigation', 'do_meta_box' ) ) );
226
  }
227
 
228
+ public function test_filter_c2c_admin_post_navigation_post_statuses_when_adding_post_status() {
229
  add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
230
 
231
  $posts = $this->create_posts();
239
  $this->assertEquals( $posts[3], $next_post->ID );
240
  }
241
 
242
+ public function test_filter_c2c_admin_post_navigation_post_statuses_when_removing_post_status() {
243
  add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
244
 
245
  $posts = $this->create_posts();
253
  $this->assertEquals( $posts[4], $next_post->ID );
254
  }
255
 
256
+ public function test_filter_c2c_admin_post_navigation_orderby() {
257
  add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby' ), 10, 2 );
258
 
259
  $posts = $this->create_posts();
281
  $this->assertEquals( $posts[4], $previous_post->ID );
282
  }
283
 
284
+ public function test_filter_c2c_admin_post_navigation_orderby_with_bad_value() {
285
  add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby_bad_value' ), 10, 2 );
286
 
287
  // Should function as if never hooked.