fix: move config directives before definition finalization and use Mockery for CdnPurgeService stub
- Move URI config calls before maybeGetRawHTMLDefinition() which finalizes the config and prevents further set() calls - Use Mockery::mock()->shouldIgnoreMissing() for CdnPurgeService stub to satisfy type hint in ContentItemObserver Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ddf01c05b5
commit
a332148056
2 changed files with 17 additions and 36 deletions
|
|
@ -97,20 +97,6 @@ class HtmlSanitiser
|
|||
$config->set('HTML.Nofollow', true);
|
||||
$config->set('HTML.TargetNoopener', true);
|
||||
|
||||
// Disable cache and set definition ID for custom HTML definitions
|
||||
$config->set('Cache.DefinitionImpl', null);
|
||||
$config->set('HTML.DefinitionID', 'core-content-html5');
|
||||
$config->set('HTML.DefinitionRev', 1);
|
||||
|
||||
// Register HTML5 elements that HTMLPurifier doesn't know about
|
||||
if ($def = $config->maybeGetRawHTMLDefinition()) {
|
||||
$def->addElement('section', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('article', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('figure', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
|
||||
$def->addElement('mark', 'Inline', 'Inline', 'Common');
|
||||
}
|
||||
|
||||
// Safe URI schemes only
|
||||
$config->set('URI.AllowedSchemes', [
|
||||
'http' => true,
|
||||
|
|
@ -123,6 +109,22 @@ class HtmlSanitiser
|
|||
$config->set('URI.DisableExternalResources', false);
|
||||
$config->set('URI.DisableResources', false);
|
||||
|
||||
// Disable cache and set definition ID for custom HTML definitions
|
||||
$config->set('Cache.DefinitionImpl', null);
|
||||
$config->set('HTML.DefinitionID', 'core-content-html5');
|
||||
$config->set('HTML.DefinitionRev', 1);
|
||||
|
||||
// Register HTML5 elements that HTMLPurifier doesn't know about
|
||||
// NOTE: maybeGetRawHTMLDefinition() finalizes the config — all
|
||||
// $config->set() calls must come before this point.
|
||||
if ($def = $config->maybeGetRawHTMLDefinition()) {
|
||||
$def->addElement('section', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('article', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('figure', 'Block', 'Flow', 'Common');
|
||||
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
|
||||
$def->addElement('mark', 'Inline', 'Inline', 'Common');
|
||||
}
|
||||
|
||||
$this->purifier = new HTMLPurifier($config);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,28 +30,7 @@ abstract class TestCase extends BaseTestCase
|
|||
|
||||
// Stub external dependencies not available in test environment
|
||||
if (! class_exists(\Plug\Cdn\CdnManager::class)) {
|
||||
$app->bind(\Core\Mod\Content\Services\CdnPurgeService::class, fn () => new class
|
||||
{
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function purgeContent($content)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function purgeUrls(array $urls)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function purgeWorkspace(string $uuid)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
$app->bind(\Core\Mod\Content\Services\CdnPurgeService::class, fn () => \Mockery::mock(\Core\Mod\Content\Services\CdnPurgeService::class)->shouldIgnoreMissing());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue