From 667784ab4c41dcddeeccdb262df1c0da20fcc362 Mon Sep 17 00:00:00 2001 From: John Watkins Date: Thu, 6 Sep 2018 18:18:44 -0400 Subject: [PATCH 1/7] 1360 Admin amp_invalid_url table - replace 'trash' text --- .../class-amp-invalid-url-post-type.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 0e57e8ac97a..0b69d768fbe 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -142,6 +142,8 @@ public static function add_admin_hooks() { add_action( 'admin_action_' . self::VALIDATE_ACTION, array( __CLASS__, 'handle_validate_request' ) ); add_action( 'post_action_' . self::UPDATE_POST_TERM_STATUS_ACTION, array( __CLASS__, 'handle_validation_error_status_update' ) ); add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu_new_invalid_url_count' ) ); + add_filter( 'post_row_actions', array( __CLASS__, 'filter_post_row_actions' ), 10, 2 ); + add_filter( sprintf( 'views_edit-%s', self::POST_TYPE_SLUG ), array( __CLASS__, 'filter_table_views' ) ); // Hide irrelevant "published" label in the invalid URL post list. add_filter( 'post_date_column_status', function( $status, $post ) { @@ -1493,4 +1495,42 @@ public static function print_dashboard_glance_styles() { %s', + get_delete_post_link( $post->ID ), + /* translators: %s: post title */ + esc_attr( sprintf( __( 'Forget “%s”', 'amp' ), $post->post_title ) ), + __( 'Forget', 'amp' ) + ); + } + + return $actions; + } + + /** + * Filters table views for the post type. + * + * @param array $views Array of table view links keyed by status slug. + * @return array Filtered views. + */ + public static function filter_table_views( $views ) { + // Replace 'Trash' text with 'Forgotten'. + if ( isset( $views['trash'] ) ) { + $status = get_post_status_object( 'trash' ); + + $views['trash'] = str_replace( $status->label, __( 'Forgotten', 'amp' ), $views['trash'] ); + } + return $views; + } + } From 81a03f147ca33fe68b1611a84b85d616d76b3eeb Mon Sep 17 00:00:00 2001 From: John Watkins Date: Thu, 6 Sep 2018 18:49:08 -0400 Subject: [PATCH 2/7] amp_invalid_url post type 'Trash' text updates --- .../validation/class-amp-invalid-url-post-type.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 0b69d768fbe..92cd4523816 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -89,7 +89,7 @@ public static function register() { 'menu_name' => __( 'Invalid Pages', 'amp' ), 'singular_name' => __( 'Invalid AMP Page (URL)', 'amp' ), 'not_found' => __( 'No invalid AMP pages found', 'amp' ), - 'not_found_in_trash' => __( 'No invalid AMP pages in trash', 'amp' ), + 'not_found_in_trash' => __( 'No forgotten AMP pages', 'amp' ), 'search_items' => __( 'Search invalid AMP pages', 'amp' ), 'edit_item' => __( 'Invalid AMP Page (URL)', 'amp' ), ), @@ -136,7 +136,7 @@ public static function add_admin_hooks() { add_filter( 'manage_' . self::POST_TYPE_SLUG . '_posts_columns', array( __CLASS__, 'add_post_columns' ) ); add_action( 'manage_posts_custom_column', array( __CLASS__, 'output_custom_column' ), 10, 2 ); add_filter( 'post_row_actions', array( __CLASS__, 'filter_row_actions' ), 10, 2 ); - add_filter( 'bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'add_bulk_action' ), 10, 2 ); + add_filter( 'bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'filter_bulk_actions' ), 10, 2 ); add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'handle_bulk_action' ), 10, 3 ); add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) ); add_action( 'admin_action_' . self::VALIDATE_ACTION, array( __CLASS__, 'handle_validate_request' ) ); @@ -637,12 +637,14 @@ public static function filter_row_actions( $actions, $post ) { } /** - * Adds a 'Recheck' bulk action to the edit.php page. + * Adds a 'Recheck' bulk action to the edit.php page and modifies the 'Move to Trash' text. * * @param array $actions The bulk actions in the edit.php page. * @return array $actions The filtered bulk actions. */ - public static function add_bulk_action( $actions ) { + public static function filter_bulk_actions( $actions ) { + $actions['trash'] = esc_html__( 'Forget', 'amp' ); + unset( $actions['edit'] ); $actions[ self::BULK_VALIDATE_ACTION ] = esc_html__( 'Recheck', 'amp' ); return $actions; @@ -1510,7 +1512,7 @@ public static function filter_post_row_actions( $actions, $post ) { get_delete_post_link( $post->ID ), /* translators: %s: post title */ esc_attr( sprintf( __( 'Forget “%s”', 'amp' ), $post->post_title ) ), - __( 'Forget', 'amp' ) + esc_html__( 'Forget', 'amp' ) ); } @@ -1528,7 +1530,7 @@ public static function filter_table_views( $views ) { if ( isset( $views['trash'] ) ) { $status = get_post_status_object( 'trash' ); - $views['trash'] = str_replace( $status->label, __( 'Forgotten', 'amp' ), $views['trash'] ); + $views['trash'] = str_replace( $status->label, esc_html__( 'Forgotten', 'amp' ), $views['trash'] ); } return $views; } From 636b20dc6cc25a6b94a27809c4dec56cde290d59 Mon Sep 17 00:00:00 2001 From: John Watkins Date: Thu, 6 Sep 2018 18:54:17 -0400 Subject: [PATCH 3/7] Update amp_invalid_url not_found_in_trash text --- includes/validation/class-amp-invalid-url-post-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 92cd4523816..71da3fd824f 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -89,7 +89,7 @@ public static function register() { 'menu_name' => __( 'Invalid Pages', 'amp' ), 'singular_name' => __( 'Invalid AMP Page (URL)', 'amp' ), 'not_found' => __( 'No invalid AMP pages found', 'amp' ), - 'not_found_in_trash' => __( 'No forgotten AMP pages', 'amp' ), + 'not_found_in_trash' => __( 'No forgotten invalid AMP pages', 'amp' ), 'search_items' => __( 'Search invalid AMP pages', 'amp' ), 'edit_item' => __( 'Invalid AMP Page (URL)', 'amp' ), ), From da599883fa8757095d69c35bd0b753b095dcc89e Mon Sep 17 00:00:00 2001 From: John Watkins Date: Thu, 6 Sep 2018 21:42:54 -0400 Subject: [PATCH 4/7] Resolve failing test --- .../test-class-amp-invalid-url-post-type.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index c66df64b74b..f7023b79b26 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -91,7 +91,7 @@ public function test_add_admin_hooks() { $this->assertEquals( 10, has_filter( 'manage_' . AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG . '_posts_columns', array( self::TESTED_CLASS, 'add_post_columns' ) ) ); $this->assertEquals( 10, has_action( 'manage_posts_custom_column', array( self::TESTED_CLASS, 'output_custom_column' ) ) ); $this->assertEquals( 10, has_filter( 'post_row_actions', array( self::TESTED_CLASS, 'filter_row_actions' ) ) ); - $this->assertEquals( 10, has_filter( 'bulk_actions-edit-' . AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, array( self::TESTED_CLASS, 'add_bulk_action' ) ) ); + $this->assertEquals( 10, has_filter( 'bulk_actions-edit-' . AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, array( self::TESTED_CLASS, 'filter_bulk_actions' ) ) ); $this->assertEquals( 10, has_filter( 'handle_bulk_actions-edit-' . AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, array( self::TESTED_CLASS, 'handle_bulk_action' ) ) ); $this->assertEquals( 10, has_action( 'admin_notices', array( self::TESTED_CLASS, 'print_admin_notice' ) ) ); $this->assertEquals( 10, has_action( 'admin_action_' . AMP_Invalid_URL_Post_Type::VALIDATE_ACTION, array( self::TESTED_CLASS, 'handle_validate_request' ) ) ); @@ -549,17 +549,18 @@ public function test_filter_row_actions() { } /** - * Test for add_bulk_action() + * Test for filter_bulk_actions() * - * @covers \AMP_Invalid_URL_Post_Type::add_bulk_action() + * @covers \AMP_Invalid_URL_Post_Type::filter_bulk_actions() */ - public function test_add_bulk_action() { + public function test_filter_bulk_actions() { $initial_action = array( 'edit' => 'Edit', ); - $actions = AMP_Invalid_URL_Post_Type::add_bulk_action( $initial_action ); + $actions = AMP_Invalid_URL_Post_Type::filter_bulk_actions( $initial_action ); $this->assertFalse( isset( $action['edit'] ) ); $this->assertEquals( 'Recheck', $actions[ AMP_Invalid_URL_Post_Type::BULK_VALIDATE_ACTION ] ); + $this->assertEquals( 'Forget', $actions['trash'] ); } /** From e4c4f4b064ae72091016f6d10ce0d137e187502d Mon Sep 17 00:00:00 2001 From: John Watkins Date: Fri, 7 Sep 2018 10:38:12 -0400 Subject: [PATCH 5/7] amp_invalid_url edit table text updates --- .../class-amp-invalid-url-post-type.php | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 71da3fd824f..7ebd28a3582 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -144,6 +144,7 @@ public static function add_admin_hooks() { add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu_new_invalid_url_count' ) ); add_filter( 'post_row_actions', array( __CLASS__, 'filter_post_row_actions' ), 10, 2 ); add_filter( sprintf( 'views_edit-%s', self::POST_TYPE_SLUG ), array( __CLASS__, 'filter_table_views' ) ); + add_filter( 'bulk_post_updated_messages', array( __CLASS__, 'filter_bulk_post_updated_messages' ), 10, 2 ); // Hide irrelevant "published" label in the invalid URL post list. add_filter( 'post_date_column_status', function( $status, $post ) { @@ -627,7 +628,7 @@ public static function filter_row_actions( $actions, $post ) { $actions[ self::VALIDATE_ACTION ] = sprintf( '%s', esc_url( self::get_recheck_url( $post ) ), - esc_html__( 'Re-check', 'amp' ) + esc_html__( 'Recheck', 'amp' ) ); if ( self::get_post_staleness( $post ) ) { $actions[ self::VALIDATE_ACTION ] = sprintf( '%s', $actions[ self::VALIDATE_ACTION ] ); @@ -643,7 +644,13 @@ public static function filter_row_actions( $actions, $post ) { * @return array $actions The filtered bulk actions. */ public static function filter_bulk_actions( $actions ) { - $actions['trash'] = esc_html__( 'Forget', 'amp' ); + if ( isset( $actions['trash'] ) ) { + $actions['trash'] = esc_html__( 'Forget', 'amp' ); + } + + if ( isset( $actions['delete'] ) ) { + $actions['delete'] = esc_html__( 'Forget permanently', 'amp' ); + } unset( $actions['edit'] ); $actions[ self::BULK_VALIDATE_ACTION ] = esc_html__( 'Recheck', 'amp' ); @@ -1045,7 +1052,7 @@ public static function print_status_meta_box( $post ) {
@@ -1516,6 +1523,16 @@ public static function filter_post_row_actions( $actions, $post ) { ); } + if ( isset( $actions['delete'] ) ) { + $actions['delete'] = sprintf( + '%s', + get_delete_post_link( $post->ID, '', true ), + /* translators: %s: post title */ + esc_attr( sprintf( __( 'Forget “%s” permanently', 'amp' ), $post->post_title ) ), + esc_html__( 'Forget Permanently', 'amp' ) + ); + } + return $actions; } @@ -1532,7 +1549,49 @@ public static function filter_table_views( $views ) { $views['trash'] = str_replace( $status->label, esc_html__( 'Forgotten', 'amp' ), $views['trash'] ); } + return $views; } + + /** + * Filters messages displayed after bulk updates. + * + * @param array $messages Bulk message text. + * @param array $bulk_counts Post numbers for the current message. + * @return array Filtered messages. + */ + public static function filter_bulk_post_updated_messages( $messages, $bulk_counts ) { + if ( get_current_screen()->id === sprintf( 'edit-%s', self::POST_TYPE_SLUG ) ) { + $messages['post'] = array_merge( + $messages['post'], + array( + /* translators: %s is the number of posts permanently forgotten */ + 'deleted' => _n( + '%s invalid AMP page permanently forgotten.', + '%s invalid AMP post permanently forgotten.', + $bulk_counts['deleted'], + 'amp' + ), + /* translators: %s is the number of posts forgotten */ + 'trashed' => _n( + '%s invalid AMP page forgotten.', + '%s invalid AMP pages fogotten.', + $bulk_counts['trashed'], + 'amp' + ), + /* translators: %s is the number of posts restored from trash. */ + 'untrashed' => _n( + '%s invalid AMP page unforgotten.', + '%s invalid AMP pages unforgotten.', + $bulk_counts['untrashed'], + 'amp' + ), + ) + ); + } + + return $messages; + } + } From fde8df21bd79e7a772d222d4c802a6a221b25678 Mon Sep 17 00:00:00 2001 From: John Watkins Date: Fri, 7 Sep 2018 13:15:12 -0400 Subject: [PATCH 6/7] amp_invalid_url post type text updates -- unit tests. --- .../class-amp-invalid-url-post-type.php | 2 +- .../test-class-amp-invalid-url-post-type.php | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 7ebd28a3582..2c0bdd74b35 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -1576,7 +1576,7 @@ public static function filter_bulk_post_updated_messages( $messages, $bulk_count /* translators: %s is the number of posts forgotten */ 'trashed' => _n( '%s invalid AMP page forgotten.', - '%s invalid AMP pages fogotten.', + '%s invalid AMP pages forgotten.', $bulk_counts['trashed'], 'amp' ), diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index f7023b79b26..983d5d20e46 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -556,11 +556,14 @@ public function test_filter_row_actions() { public function test_filter_bulk_actions() { $initial_action = array( 'edit' => 'Edit', + 'trash' => 'Trash', + 'delete' => 'Trash permanently' ); $actions = AMP_Invalid_URL_Post_Type::filter_bulk_actions( $initial_action ); $this->assertFalse( isset( $action['edit'] ) ); $this->assertEquals( 'Recheck', $actions[ AMP_Invalid_URL_Post_Type::BULK_VALIDATE_ACTION ] ); $this->assertEquals( 'Forget', $actions['trash'] ); + $this->assertEquals( 'Forget permanently', $actions['delete'] ); } /** @@ -1168,6 +1171,74 @@ public function test_filter_dashboard_glance_items() { $this->assertContains( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR, $items[0] ); } + /** + * Test for filter_post_row_actions() + * + * @covers \AMP_Invalid_URL_Post_Type::filter_post_row_actions() + */ + public function test_filter_post_row_actions() { + $this->assertEquals( array(), AMP_Invalid_URL_Post_Type::filter_post_row_actions( array(), null ) ); + + $actions = array( + 'trash' => '', + 'delete' => '', + ); + + $post = $post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, 'title' => 'My Post' ) ); + + $filtered_actions = AMP_Invalid_URL_Post_Type::filter_post_row_actions( $actions, $post ); + + $this->assertContains( 'Forget', $filtered_actions['trash'] ); + $this->assertContains( 'Forget Permanently', $filtered_actions['delete'] ); + + } + + /** + * Test for filter_table_views() + * + * @covers \AMP_Invalid_URL_Post_Type::filter_table_views() + */ + public function test_filter_table_views() { + $this->assertEquals( array(), AMP_Invalid_URL_Post_Type::filter_table_views( array() ) ); + + $views = array( + 'trash' => 'Trash', + ); + + $filtered_views = AMP_Invalid_URL_Post_Type::filter_table_views( $views ); + + $this->assertEquals( 'Forgotten', $filtered_views['trash'] ); + } + + /** + * Test for filter_bulk_post_updated_messages() + * + * @covers \AMP_Invalid_URL_Post_Type::filter_bulk_post_updated_messages() + */ + public function test_filter_bulk_post_updated_messages() { + set_current_screen( 'index.php' ); + + $this->assertEquals( array(), AMP_Invalid_URL_Post_Type::filter_bulk_post_updated_messages( array(), array() ) ); + + set_current_screen( 'edit.php' ); + get_current_screen()->id = sprintf( 'edit-%s', AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG ); + + $messages = array( + 'post' => array(), + ); + + $filtered_messages = AMP_Invalid_URL_Post_Type::filter_bulk_post_updated_messages( $messages, array( + 'deleted' => 1, + 'trashed' => 99, + 'untrashed' => 99, + ) ); + + $this->assertEquals( '%s invalid AMP page permanently forgotten.', $filtered_messages['post']['deleted'] ); + $this->assertEquals( '%s invalid AMP pages forgotten.', $filtered_messages['post']['trashed'] ); + $this->assertEquals( '%s invalid AMP pages unforgotten.', $filtered_messages['post']['untrashed'] ); + } + + /** * Gets mock errors for tests. * From 4bf6713fb9eb5ed06a18dae793d734eaf1f4fa65 Mon Sep 17 00:00:00 2001 From: John Watkins Date: Fri, 7 Sep 2018 13:30:59 -0400 Subject: [PATCH 7/7] amp_invalid_url post type text updates -- PHPCS. --- .../test-class-amp-invalid-url-post-type.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index 983d5d20e46..ddfc7f357f2 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -555,9 +555,9 @@ public function test_filter_row_actions() { */ public function test_filter_bulk_actions() { $initial_action = array( - 'edit' => 'Edit', - 'trash' => 'Trash', - 'delete' => 'Trash permanently' + 'edit' => 'Edit', + 'trash' => 'Trash', + 'delete' => 'Trash permanently', ); $actions = AMP_Invalid_URL_Post_Type::filter_bulk_actions( $initial_action ); $this->assertFalse( isset( $action['edit'] ) ); @@ -1180,11 +1180,14 @@ public function test_filter_post_row_actions() { $this->assertEquals( array(), AMP_Invalid_URL_Post_Type::filter_post_row_actions( array(), null ) ); $actions = array( - 'trash' => '', + 'trash' => '', 'delete' => '', ); - $post = $post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, 'title' => 'My Post' ) ); + $post = $this->factory()->post->create_and_get( array( + 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG, + 'title' => 'My Post', + ) ); $filtered_actions = AMP_Invalid_URL_Post_Type::filter_post_row_actions( $actions, $post );