|
4 | 4 |
|
5 | 5 | namespace n5s\PageForCustomPostType\Tests\Integration\Integration; |
6 | 6 |
|
| 7 | +use n5s\PageForCustomPostType\Core\Api; |
| 8 | +use n5s\PageForCustomPostType\Integration\WordPressSeo\Breadcrumbs; |
| 9 | +use n5s\PageForCustomPostType\Integration\WordPressSeo\Indexables; |
| 10 | +use n5s\PageForCustomPostType\Integration\WordPressSeo\Schema; |
| 11 | +use n5s\PageForCustomPostType\Integration\WordPressSeo\WordPressSeo; |
7 | 12 | use n5s\PageForCustomPostType\Tests\Fixtures\TestCase; |
8 | 13 | use PHPUnit\Framework\Attributes\RequiresFunction; |
9 | 14 | use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer; |
@@ -169,4 +174,78 @@ public function testSchemaWebpageTypeUnchangedOnRegularPage(): void |
169 | 174 |
|
170 | 175 | $this->assertEquals('WebPage', $type); |
171 | 176 | } |
| 177 | + |
| 178 | + public function testSchemaWebpageTypeDoesNotDuplicateCollectionPage(): void |
| 179 | + { |
| 180 | + $this->get($this->getBookHomeUrl()); |
| 181 | + |
| 182 | + // CollectionPage already present: the filter must return it unchanged. |
| 183 | + $type = apply_filters('wpseo_schema_webpage_type', ['WebPage', 'CollectionPage']); |
| 184 | + |
| 185 | + $this->assertSame(['WebPage', 'CollectionPage'], $type); |
| 186 | + } |
| 187 | + |
| 188 | + public function testIsSupported(): void |
| 189 | + { |
| 190 | + $seo = new WordPressSeo(new Schema(new Api()), new Breadcrumbs(new Api()), new Indexables(new Api())); |
| 191 | + |
| 192 | + $this->assertTrue($seo->isSupported()); |
| 193 | + } |
| 194 | + |
| 195 | + public function testRegisterHooksRegistersAllSubIntegrations(): void |
| 196 | + { |
| 197 | + $schema = new Schema(new Api()); |
| 198 | + $breadcrumbs = new Breadcrumbs(new Api()); |
| 199 | + $indexables = new Indexables(new Api()); |
| 200 | + |
| 201 | + (new WordPressSeo($schema, $breadcrumbs, $indexables))->registerHooks(); |
| 202 | + |
| 203 | + $this->assertNotFalse(has_filter('wpseo_schema_webpage_type', [$schema, 'addCollectionPageType'])); |
| 204 | + $this->assertNotFalse(has_filter('wpseo_breadcrumb_indexables', [$breadcrumbs, 'fixPostBreadcrumbs'])); |
| 205 | + $this->assertNotFalse(has_filter('wpseo_breadcrumb_indexables', [$breadcrumbs, 'fixTaxonomyBreadcrumbs'])); |
| 206 | + $this->assertNotFalse(has_action('wp', [$indexables, 'configurePageDetection'])); |
| 207 | + } |
| 208 | + |
| 209 | + public function testPageDetectionResolvesPfcptPageWithStaticFrontPage(): void |
| 210 | + { |
| 211 | + // With a static front page, Yoast's Current_Page_Helper would resolve the |
| 212 | + // posts page instead of the PFCPT page. Indexables::configurePageDetection |
| 213 | + // intercepts show_on_front (only for that helper) so detection falls through |
| 214 | + // to the PFCPT page id. |
| 215 | + $this->configureStaticFrontPage(); |
| 216 | + |
| 217 | + $memoizer = \YoastSEO()->classes->get(Meta_Tags_Context_Memoizer::class); |
| 218 | + $memoizer->clear(); |
| 219 | + |
| 220 | + $this->get($this->getBookHomeUrl()); |
| 221 | + |
| 222 | + $meta = \YoastSEO()->meta->for_current_page(); |
| 223 | + |
| 224 | + $this->assertSame($this->getBookHomeUrl(), $meta->canonical); |
| 225 | + } |
| 226 | + |
| 227 | + public function testTaxonomyBreadcrumbsSkippedForNonMainTaxonomy(): void |
| 228 | + { |
| 229 | + // The breadcrumb fix only applies when the current taxonomy is the post |
| 230 | + // type's configured main taxonomy. Point books' main taxonomy elsewhere |
| 231 | + // and confirm the genre archive is left untouched (no PFCPT crumb). |
| 232 | + \YoastSEO()->helpers->options->set('post_types-' . self::BOOK_POST_TYPE . '-maintax', 'category'); |
| 233 | + |
| 234 | + $genreId = $this->getOrCreateTerm(self::GENRE_TAXONOMY, 'Fantasy'); |
| 235 | + foreach ($this->bookIds as $bookId) { |
| 236 | + wp_set_object_terms($bookId, $genreId, self::GENRE_TAXONOMY); |
| 237 | + } |
| 238 | + |
| 239 | + $memoizer = \YoastSEO()->classes->get(Meta_Tags_Context_Memoizer::class); |
| 240 | + $memoizer->clear(); |
| 241 | + |
| 242 | + $genre = get_term($genreId, self::GENRE_TAXONOMY); |
| 243 | + $this->get(get_term_link($genre)); |
| 244 | + |
| 245 | + $meta = \YoastSEO()->meta->for_current_page(); |
| 246 | + |
| 247 | + foreach ($meta->breadcrumbs as $crumb) { |
| 248 | + $this->assertNotSame($this->homeForBookId, \is_array($crumb) ? ($crumb['id'] ?? null) : null); |
| 249 | + } |
| 250 | + } |
172 | 251 | } |
0 commit comments