diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 9d08e574..3de87730 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -794,4 +794,96 @@ public function entries_can_be_ordered_by_an_date_json_field() $this->assertCount(3, $entries); $this->assertEquals(['Post 2', 'Post 1', 'Post 3'], $entries->map->title->all()); } + + /** @test */ + public function filtering_using_where_status_column_writes_deprecation_log() + { + $this->withoutDeprecationHandling(); + $this->expectException(\ErrorException::class); + $this->expectExceptionMessage('Filtering by status is deprecated. Use whereStatus() instead.'); + + $this->createDummyCollectionAndEntries(); + + Entry::query()->where('collection', 'posts')->where('status', 'published')->get(); + } + + /** @test */ + public function filtering_using_whereIn_status_column_writes_deprecation_log() + { + $this->withoutDeprecationHandling(); + $this->expectException(\ErrorException::class); + $this->expectExceptionMessage('Filtering by status is deprecated. Use whereStatus() instead.'); + + $this->createDummyCollectionAndEntries(); + + Entry::query()->where('collection', 'posts')->whereIn('status', ['published'])->get(); + } + + /** @test */ + public function filtering_by_unexpected_status_throws_exception() + { + $this->expectExceptionMessage('Invalid status [foo]'); + + Entry::query()->whereStatus('foo')->get(); + } + + /** + * @test + * + * @dataProvider filterByStatusProvider + */ + public function it_filters_by_status($status, $expected) + { + Collection::make('pages')->dated(false)->save(); + EntryFactory::collection('pages')->slug('page')->published(true)->create(); + EntryFactory::collection('pages')->slug('page-draft')->published(false)->create(); + + Collection::make('blog')->dated(true)->futureDateBehavior('private')->pastDateBehavior('public')->save(); + EntryFactory::collection('blog')->slug('blog-future')->published(true)->date(now()->addDay())->create(); + EntryFactory::collection('blog')->slug('blog-future-draft')->published(false)->date(now()->addDay())->create(); + EntryFactory::collection('blog')->slug('blog-past')->published(true)->date(now()->subDay())->create(); + EntryFactory::collection('blog')->slug('blog-past-draft')->published(false)->date(now()->subDay())->create(); + + Collection::make('events')->dated(true)->futureDateBehavior('public')->pastDateBehavior('private')->save(); + EntryFactory::collection('events')->slug('event-future')->published(true)->date(now()->addDay())->create(); + EntryFactory::collection('events')->slug('event-future-draft')->published(false)->date(now()->addDay())->create(); + EntryFactory::collection('events')->slug('event-past')->published(true)->date(now()->subDay())->create(); + EntryFactory::collection('events')->slug('event-past-draft')->published(false)->date(now()->subDay())->create(); + + Collection::make('calendar')->dated(true)->futureDateBehavior('public')->pastDateBehavior('public')->save(); + EntryFactory::collection('calendar')->slug('calendar-future')->published(true)->date(now()->addDay())->create(); + EntryFactory::collection('calendar')->slug('calendar-future-draft')->published(false)->date(now()->addDay())->create(); + EntryFactory::collection('calendar')->slug('calendar-past')->published(true)->date(now()->subDay())->create(); + EntryFactory::collection('calendar')->slug('calendar-past-draft')->published(false)->date(now()->subDay())->create(); + + $this->assertEquals($expected, Entry::query()->whereStatus($status)->get()->map->slug()->all()); + } + + public static function filterByStatusProvider() + { + return [ + 'draft' => ['draft', [ + 'page-draft', + 'blog-future-draft', + 'blog-past-draft', + 'event-future-draft', + 'event-past-draft', + 'calendar-future-draft', + 'calendar-past-draft', + ]], + 'published' => ['published', [ + 'page', + 'blog-past', + 'event-future', + 'calendar-future', + 'calendar-past', + ]], + 'scheduled' => ['scheduled', [ + 'blog-future', + ]], + 'expired' => ['expired', [ + 'event-past', + ]], + ]; + } }