Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/Integration/Integration/AutodescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace n5s\PageForCustomPostType\Tests\Integration\Integration;

use n5s\PageForCustomPostType\Core\Api;
use n5s\PageForCustomPostType\Integration\Autodescription\Autodescription;
use n5s\PageForCustomPostType\Integration\Autodescription\Breadcrumbs;
use n5s\PageForCustomPostType\Integration\Autodescription\QueryType;
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;
use PHPUnit\Framework\Attributes\RequiresFunction;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
Expand Down Expand Up @@ -195,6 +199,60 @@ public function testPostTypeWithoutPfcptPageHasNoBreadcrumbChange(): void
}
}

public function testIsSupported(): void
{
$autodescription = new Autodescription(new QueryType(new Api()), new Breadcrumbs(new Api()));

$this->assertTrue($autodescription->isSupported());
}

public function testRegisterHooksRegistersSubIntegrations(): void
{
$queryType = new QueryType(new Api());
$breadcrumbs = new Breadcrumbs(new Api());

(new Autodescription($queryType, $breadcrumbs))->registerHooks();

$this->assertNotFalse(has_filter('the_seo_framework_is_singular_archive', [$queryType, 'markPfcptAsSingularArchive']));
$this->assertNotFalse(has_filter('the_seo_framework_breadcrumb_list', [$breadcrumbs, 'addPfcptPageCrumb']));
}

public function testSingularArchiveShortCircuitsWhenAlreadyTrue(): void
{
$queryType = new QueryType(new Api());

$this->assertTrue($queryType->markPfcptAsSingularArchive(true, null));
}

public function testSingularArchiveResolvedFromExplicitPageId(): void
{
$queryType = new QueryType(new Api());

$this->assertTrue($queryType->markPfcptAsSingularArchive(false, $this->homeForBookId));

$regularId = self::factory()->post->create(['post_type' => 'post']);
$this->assertFalse($queryType->markPfcptAsSingularArchive(false, $regularId));
}

public function testBreadcrumbCrumbSkippedForUnresolvableArgs(): void
{
$breadcrumbs = new Breadcrumbs(new Api());
$list = [['url' => home_url('/'), 'name' => 'Home']];

// id is neither int nor WP_Post
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 'not-an-id']));
// id points to a non-existent post
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 999999]));
// taxonomy is not a string
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 123]));
// neither a single post nor a taxonomy archive
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['uid' => 7]));
// unknown taxonomy
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 'does_not_exist']));
// real taxonomy with no PFCPT-bound post type
$this->assertSame($list, $breadcrumbs->addPfcptPageCrumb($list, ['id' => 1, 'tax' => 'category']));
}

/**
* Clear TSF's internal memoization cache between tests.
*
Expand Down
Loading