|
4 | 4 |
|
5 | 5 | namespace n5s\PageForCustomPostType\Tests\Integration\Integration; |
6 | 6 |
|
| 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; |
7 | 11 | use n5s\PageForCustomPostType\Tests\Fixtures\TestCase; |
8 | 12 | use PHPUnit\Framework\Attributes\RequiresFunction; |
9 | 13 | use PHPUnit\Framework\Attributes\WithoutErrorHandler; |
@@ -195,6 +199,60 @@ public function testPostTypeWithoutPfcptPageHasNoBreadcrumbChange(): void |
195 | 199 | } |
196 | 200 | } |
197 | 201 |
|
| 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 | + |
198 | 256 | /** |
199 | 257 | * Clear TSF's internal memoization cache between tests. |
200 | 258 | * |
|
0 commit comments