Skip to content

Commit 3a8c8a9

Browse files
committed
test(autodescription): cover composite boot, query type and breadcrumb guards
Exercises the public integration methods directly: the Autodescription composite isSupported()/registerHooks() (0% -> 100%); QueryType::markPfcptAsSingularArchive — the already-archive short-circuit and explicit-id resolution (40% -> 100%); and Breadcrumbs::addPfcptPageCrumb argument-resolution guards (78% -> 92.5%).
1 parent 7e45b27 commit 3a8c8a9

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

tests/Integration/Integration/AutodescriptionTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace n5s\PageForCustomPostType\Tests\Integration\Integration;
66

7+
use n5s\PageForCustomPostType\Core\Api;
8+
use n5s\PageForCustomPostType\Integration\Autodescription\Autodescription;
9+
use n5s\PageForCustomPostType\Integration\Autodescription\Breadcrumbs;
10+
use n5s\PageForCustomPostType\Integration\Autodescription\QueryType;
711
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;
812
use PHPUnit\Framework\Attributes\RequiresFunction;
913
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
@@ -195,6 +199,60 @@ public function testPostTypeWithoutPfcptPageHasNoBreadcrumbChange(): void
195199
}
196200
}
197201

202+
public function testIsSupported(): void
203+
{
204+
$autodescription = new Autodescription(new QueryType(new Api()), new Breadcrumbs(new Api()));
205+
206+
$this->assertTrue($autodescription->isSupported());
207+
}
208+
209+
public function testRegisterHooksRegistersSubIntegrations(): void
210+
{
211+
$queryType = new QueryType(new Api());
212+
$breadcrumbs = new Breadcrumbs(new Api());
213+
214+
(new Autodescription($queryType, $breadcrumbs))->registerHooks();
215+
216+
$this->assertNotFalse(has_filter('the_seo_framework_is_singular_archive', [$queryType, 'markPfcptAsSingularArchive']));
217+
$this->assertNotFalse(has_filter('the_seo_framework_breadcrumb_list', [$breadcrumbs, 'addPfcptPageCrumb']));
218+
}
219+
220+
public function testSingularArchiveShortCircuitsWhenAlreadyTrue(): void
221+
{
222+
$queryType = new QueryType(new Api());
223+
224+
$this->assertTrue($queryType->markPfcptAsSingularArchive(true, null));
225+
}
226+
227+
public function testSingularArchiveResolvedFromExplicitPageId(): void
228+
{
229+
$queryType = new QueryType(new Api());
230+
231+
$this->assertTrue($queryType->markPfcptAsSingularArchive(false, $this->homeForBookId));
232+
233+
$regularId = self::factory()->post->create(['post_type' => 'post']);
234+
$this->assertFalse($queryType->markPfcptAsSingularArchive(false, $regularId));
235+
}
236+
237+
public function testBreadcrumbCrumbSkippedForUnresolvableArgs(): void
238+
{
239+
$breadcrumbs = new Breadcrumbs(new Api());
240+
$list = [['url' => home_url('/'), 'name' => 'Home']];
241+
242+
// id is neither int nor WP_Post
243+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 'not-an-id']));
244+
// id points to a non-existent post
245+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 999999]));
246+
// taxonomy is not a string
247+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 123]));
248+
// neither a single post nor a taxonomy archive
249+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['uid' => 7]));
250+
// unknown taxonomy
251+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 'does_not_exist']));
252+
// real taxonomy with no PFCPT-bound post type
253+
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 'category']));
254+
}
255+
198256
/**
199257
* Clear TSF's internal memoization cache between tests.
200258
*

0 commit comments

Comments
 (0)