fix: tb-assign reattaches only templates no Theme Builder post lists (audit L4)
"Detached" now means for lit/tb-assign what lit/tb-list shows as detached: DiviThemeBuilder::isListedAnywhere() looks for any _et_template row (live, draft or Theme Builder library post). A template another Theme Builder post lists is refused with or without reattach; nothing is written. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -128,6 +128,9 @@ final class ThemeBuilderFixtures
|
||||
$store->allows('templateIds')->andReturn(array_map(static fn (Template $t): int => $t->id, $templates));
|
||||
$store->allows('template')->andReturnUsing(static fn (int $id): ?Template => $byId[$id] ?? null)->byDefault();
|
||||
$store->allows('detachedIds')->andReturn(array_map(static fn (Template $t): int => $t->id, $detached));
|
||||
$store->allows('isListedAnywhere')->andReturnUsing(
|
||||
static fn (int $id): bool => in_array($id, array_map(static fn (Template $t): int => $t->id, $templates), true)
|
||||
)->byDefault();
|
||||
$store->allows('flatConditions')->andReturn(self::conditions());
|
||||
|
||||
return $store;
|
||||
|
||||
@@ -26,6 +26,38 @@ final class DiviThemeBuilderTest extends TestCase
|
||||
self::assertNull(DiviThemeBuilder::areaOf('page'));
|
||||
}
|
||||
|
||||
/** Review M-3: one list of every Theme Builder post type. */
|
||||
public function testPostTypesNameEveryThemeBuilderType(): void
|
||||
{
|
||||
self::assertSame(
|
||||
['et_theme_builder', 'et_template', 'et_header_layout', 'et_body_layout', 'et_footer_layout'],
|
||||
DiviThemeBuilder::postTypes()
|
||||
);
|
||||
}
|
||||
|
||||
/** Audit L4: a template is listed when any Theme Builder post's _et_template row names it. */
|
||||
public function testIsListedAnywhereAsksEveryThemeBuilderPost(): void
|
||||
{
|
||||
$db = Mockery::mock(\wpdb::class)->makePartial();
|
||||
$db->postmeta = 'wp_postmeta';
|
||||
$sql = [];
|
||||
$db->allows('get_var')->andReturnUsing(static function (string $query) use (&$sql): ?string {
|
||||
$sql[] = $query;
|
||||
|
||||
return str_contains($query, "'1066'") ? '1' : null;
|
||||
});
|
||||
$GLOBALS['wpdb'] = $db;
|
||||
|
||||
try {
|
||||
self::assertTrue((new DiviThemeBuilder())->isListedAnywhere(1066));
|
||||
self::assertFalse((new DiviThemeBuilder())->isListedAnywhere(2394));
|
||||
} finally {
|
||||
unset($GLOBALS['wpdb']);
|
||||
}
|
||||
self::assertStringContainsString("meta_key = '_et_template'", $sql[0]);
|
||||
self::assertStringContainsString('LIMIT 1', $sql[0]);
|
||||
}
|
||||
|
||||
/** F17/F18: Divi wp_die()s without edit_others_posts – the adapter never gets there. */
|
||||
public function testWithoutEditOthersPostsDiviIsNeverCalled(): void
|
||||
{
|
||||
|
||||
@@ -180,6 +180,27 @@ final class TbAssignAbilityTest extends TestCase
|
||||
self::assertTrue($result['previous']['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit L4: reattach takes only templates no Theme Builder post lists (tb-list's detached) – not one that a
|
||||
* Theme Builder library item or draft lists; nothing is written.
|
||||
*/
|
||||
public function testReattachRefusesATemplateAnotherThemeBuilderPostLists(): void
|
||||
{
|
||||
$listedElsewhere = ThemeBuilderFixtures::template(1066, ['attached' => false]);
|
||||
$store = ThemeBuilderFixtures::store([], 0, [], [$listedElsewhere]);
|
||||
$store->allows('isListedAnywhere')->with(1066)->andReturn(true);
|
||||
foreach (['setEnabled', 'attach', 'unmarkUnused', 'setConditions'] as $method) {
|
||||
$store->shouldReceive($method)->never();
|
||||
}
|
||||
|
||||
foreach ([['reattach' => true], []] as $extra) {
|
||||
$refused = self::ability($store, FakeChangeLog::forbidden())->execute(self::input($listedElsewhere, $extra));
|
||||
self::assertToolError($refused, 'validation_failed');
|
||||
self::assertStringContainsString('keine entfernte Vorlage', self::clientError($refused)['message']);
|
||||
self::assertArrayHasKey('template_id', self::errorFields($refused));
|
||||
}
|
||||
}
|
||||
|
||||
/** Ruling Q8/B10: a layout Divi trashed meanwhile blocks the reattach; nothing is written. */
|
||||
public function testReattachNeedsPublishedLayouts(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user