From 22c6e16f371e04474b36f8520f155371c22c91d6 Mon Sep 17 00:00:00 2001
From: Ryan Kienstra
Date: Thu, 27 Aug 2020 17:10:47 -0500
Subject: [PATCH 1/2] Ensure the "Let's get started" link appears
Before, edit_post_link() didn't echo
anything because in
get_edit_post_link(),
current_user_can( 'edit_post', ->ID )
was false.
But this only seemed to happen the very
first time the plugin was activated in WP.
---
php/Admin/Onboarding.php | 39 +++++++++++++----
tests/php/Unit/Admin/TestOnboarding.php | 56 +++++++++++++++++++++++++
2 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/php/Admin/Onboarding.php b/php/Admin/Onboarding.php
index 25a43938f..a2a4f123c 100644
--- a/php/Admin/Onboarding.php
+++ b/php/Admin/Onboarding.php
@@ -149,15 +149,11 @@ public function show_welcome_notice() {
👋
- ',
- '
',
- $example_post_id,
- 'button button--white button_cta'
- );
- ?>
+
+
+
+
+
post_type );
+ if ( empty( $post_type_object->_edit_link ) ) {
+ return null;
+ }
+
+ $link = admin_url( sprintf( $post_type_object->_edit_link . '&action=edit', $post->ID ) );
+
+ /** This filter is documented in wp-includes/link-template.php */
+ return apply_filters( 'get_edit_post_link', $link, $post->ID, 'display' );
+ }
+
/**
* Render the Edit Your First Block message.
*/
diff --git a/tests/php/Unit/Admin/TestOnboarding.php b/tests/php/Unit/Admin/TestOnboarding.php
index 97354f0b1..b7c192020 100644
--- a/tests/php/Unit/Admin/TestOnboarding.php
+++ b/tests/php/Unit/Admin/TestOnboarding.php
@@ -40,6 +40,62 @@ public function test_register_hooks() {
$this->assertEquals( 10, has_action( 'current_screen', [ $this->instance, 'admin_notices' ] ) );
}
+ /**
+ * Test show_welcome_notice when it should not display.
+ *
+ * @covers \Genesis\CustomBlocks\Admin\Onboarding::show_welcome_notice()
+ */
+ public function test_show_welcome_notice_does_not_display() {
+ ob_start();
+ $this->instance->show_welcome_notice();
+ $this->assertEmpty( ob_get_clean() );
+ }
+
+ /**
+ * Test show_welcome_notice when it should display.
+ *
+ * @covers \Genesis\CustomBlocks\Admin\Onboarding::show_welcome_notice()
+ */
+ public function test_show_welcome_notice_should_display() {
+ $post_id = $this->factory()->post->create( [ 'post_type' => 'genesis_custom_block' ] );
+ update_option(
+ Onboarding::OPTION_NAME,
+ $post_id
+ );
+
+ ob_start();
+ $this->instance->show_welcome_notice();
+ $output = ob_get_clean();
+
+ $this->assertContains(
+ '
',
+ $output
+ );
+ $this->assertContains( "post.php?post={$post_id}&action=edit", $output );
+ }
+
+ /**
+ * Test get_edit_link when the post ID is not for a post.
+ *
+ * @covers \Genesis\CustomBlocks\Admin\Onboarding::get_edit_link()
+ */
+ public function test_get_edit_link_no_post() {
+ $this->assertEmpty( $this->instance->get_edit_link( 123456789 ) );
+ }
+
+ /**
+ * Test get_edit_link when there is a valid post.
+ *
+ * @covers \Genesis\CustomBlocks\Admin\Onboarding::get_edit_link()
+ */
+ public function test_get_edit_link_with_post() {
+ $post_id = $this->factory()->post->create( [ 'post_type' => 'genesis_custom_block' ] );
+ $this->assertContains(
+ "post.php?post={$post_id}&action=edit",
+ $this->instance->get_edit_link( $post_id )
+ );
+ }
+
/**
* Test plugin_activation.
*
From d879a9c3be620be207c9e49fd14c1669abad895a Mon Sep 17 00:00:00 2001
From: Ryan Kienstra
Date: Thu, 27 Aug 2020 17:33:23 -0500
Subject: [PATCH 2/2] Fix a failed unit test
---
tests/php/Unit/Admin/TestOnboarding.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/php/Unit/Admin/TestOnboarding.php b/tests/php/Unit/Admin/TestOnboarding.php
index b7c192020..33b7a8d84 100644
--- a/tests/php/Unit/Admin/TestOnboarding.php
+++ b/tests/php/Unit/Admin/TestOnboarding.php
@@ -71,7 +71,7 @@ public function test_show_welcome_notice_should_display() {
'',
$output
);
- $this->assertContains( "post.php?post={$post_id}&action=edit", $output );
+ $this->assertContains( strval( $post_id ), $output );
}
/**