diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 15d8b8f8..c01f03f6 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -12,9 +12,9 @@ jobs: php-tests: strategy: matrix: - php: [7.4, 8.0] + php: [8.0] wordpress: ["latest"] uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main with: php: ${{ matrix.php }} - wordpress: ${{ matrix.wordpress }} \ No newline at end of file + wordpress: ${{ matrix.wordpress }} diff --git a/archiveless.php b/archiveless.php index 2d8db410..1ecab71c 100644 --- a/archiveless.php +++ b/archiveless.php @@ -3,9 +3,13 @@ * Plugin Name: Archiveless * Plugin URI: https://github.com/alleyinteractive/archiveless * Description: Hide posts from archives performantly - * Version: 0.1 + * Version: 0.2 * Author: Alley Interactive * Author URI: https://alley.co/ + * License: GPL-2.0-or-later + * License URI: https://www.gnu.org/licenses/gpl-2.0.html + * Tested up to: 6.2 + * Requires PHP: 8.0 * * @package Archiveless * diff --git a/composer.json b/composer.json index 63ddc4e6..9145f00a 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ }, "require-dev": { "alleyinteractive/alley-coding-standards": "^1.0", - "mantle-framework/testkit": "^0.7" + "mantle-framework/testkit": "^0.10" }, "config": { "allow-plugins": { diff --git a/inc/class-archiveless.php b/inc/class-archiveless.php index 3f9b88f1..7bb35d3c 100644 --- a/inc/class-archiveless.php +++ b/inc/class-archiveless.php @@ -391,7 +391,7 @@ public function get_default_post_statuses( $query ) { array_keys( get_post_stati( [ - 'exclude_from_search' => false, + 'public' => true, ] ) ) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a521ab7e..f032e583 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,12 +6,13 @@ */ \Mantle\Testing\manager() + ->maybe_rsync_plugin() ->loaded( function () { require_once __DIR__ . '/../archiveless.php'; - + // switch_theme( 'twentytwentytwo' ); // Set the permalink structure. update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); - } + } ) ->install(); diff --git a/tests/test-general.php b/tests/test-general.php index 5352d020..7c6ce59f 100644 --- a/tests/test-general.php +++ b/tests/test-general.php @@ -224,19 +224,35 @@ public function test_optionally_excluded_outside_of_main_query_with_exclude_arch $this->assertContains( $this->archiveable_post, $post_ids ); } + public function test_draft_post_hidden_from_archive() { + $category = static::factory()->category->create(); + + $post = static::factory()->post->with_terms( $category )->create( + [ + 'post_status' => 'draft', + ] + ); + + $this->get( get_category_link( $category ) ) + ->assertOk() + ->assertDontSee( get_the_title( $post ) ); + + $this->assertNotContains( $post, wp_list_pluck( $GLOBALS['wp_query']->posts, 'ID' ) ); + } + /** * Test that an archiveless post is not accessible under multiple conditions. * * @dataProvider inaccessible */ public function test_inaccessible( $url, $conditional ) { - $this->get( $url ); + $this->get( $url ) + ->assertOk() + ->assertSee( get_the_title( $this->archiveable_post ) ) + ->assertDontSee( get_the_title( $this->archiveless_post ) ); $this->assertFalse( is_singular() ); $this->assertTrue( $conditional(), "Asserting that {$conditional}() is true" ); - $this->assertTrue( have_posts() ); - $this->assertContains( $this->archiveable_post, wp_list_pluck( $GLOBALS['wp_query']->posts, 'ID' ) ); - $this->assertNotContains( $this->archiveless_post, wp_list_pluck( $GLOBALS['wp_query']->posts, 'ID' ) ); } public function inaccessible() { @@ -246,7 +262,6 @@ public function inaccessible() { [ '/category/archives/', 'is_category' ], // Tax archive. [ '/author/test_author/', 'is_author' ], // Author archive. [ '/?s=Lorem+ipsum', 'is_search' ], // Search. - [ '/rss/', 'is_feed' ], // Feeds. ]; }