Skip to content

Commit

Permalink
Merge pull request #57 from alleyinteractive/fix/post-statuses
Browse files Browse the repository at this point in the history
Change visibility of post stati in query
  • Loading branch information
kevinfodness authored Apr 20, 2023
2 parents 9914b0e + 5a4b8d2 commit bd86603
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
wordpress: ${{ matrix.wordpress }}
6 changes: 5 additions & 1 deletion archiveless.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion inc/class-archiveless.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function get_default_post_statuses( $query ) {
array_keys(
get_post_stati(
[
'exclude_from_search' => false,
'public' => true,
]
)
)
Expand Down
5 changes: 3 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
25 changes: 20 additions & 5 deletions tests/test-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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.
];
}

Expand Down

0 comments on commit bd86603

Please sign in to comment.