Skip to content

Commit 46c4bb8

Browse files
committed
test(acf): cover integration boot and match-rule edge cases
isSupported(), registerHooks() and the constructor otherwise run during the test bootstrap, before coverage collection starts, so they never register as covered. Instantiate the integration directly to exercise them, mirroring PolylangTest and WpmlTest. Also cover the two remaining match_rule branches: a screen pointing at a non-existent post, and a rule value that matches no bound post type. This brings AdvancedCustomFields to full line coverage.
1 parent b293aff commit 46c4bb8

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/Integration/Integration/AdvancedCustomFieldsTest.php

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

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

7+
use n5s\PageForCustomPostType\Core\Api;
8+
use n5s\PageForCustomPostType\Integration\AdvancedCustomFields\AdvancedCustomFields;
79
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;
810
use PHPUnit\Framework\Attributes\RequiresFunction;
911

@@ -30,6 +32,22 @@ protected function setUp(): void
3032
$this->configureStaticFrontPage();
3133
}
3234

35+
public function testIsSupported(): void
36+
{
37+
$acf = new AdvancedCustomFields(new Api());
38+
39+
$this->assertTrue($acf->isSupported());
40+
}
41+
42+
public function testRegisterHooksAttachesLocationFilters(): void
43+
{
44+
$acf = new AdvancedCustomFields(new Api());
45+
$acf->registerHooks();
46+
47+
$this->assertNotFalse(has_filter('acf/location/rule_values/type=page_type', [$acf, 'addPageTypeValues']));
48+
$this->assertNotFalse(has_filter('acf/location/match_rule/type=page_type', [$acf, 'matchPageType']));
49+
}
50+
3351
public function testPageTypeValuesIncludeCustomPostTypePages(): void
3452
{
3553
$values = $this->applyValuesFilter();
@@ -90,6 +108,21 @@ public function testMatchRuleReturnsFalseWhenPostIdMissing(): void
90108
$this->assertFalse($matched);
91109
}
92110

111+
public function testMatchRuleReturnsFalseWhenPostDoesNotExist(): void
112+
{
113+
// get_post() returns null for a non-existent ID.
114+
$matched = $this->applyMatchFilter('==', 'book_page', 999999);
115+
116+
$this->assertFalse($matched);
117+
}
118+
119+
public function testMatchRuleReturnsFalseForUnknownPostTypeValue(): void
120+
{
121+
$matched = $this->applyMatchFilter('==', 'movie_page', $this->homeForBookId);
122+
123+
$this->assertFalse($matched);
124+
}
125+
93126
/**
94127
* @return array<string, string>
95128
*/

0 commit comments

Comments
 (0)