[ 'scope' => [new WP_Term(['slug' => 'global', 'name' => 'global'])], 'layout_type' => [new WP_Term(['slug' => 'section', 'name' => 'section'])], 'layout_category' => [new WP_Term(['slug' => 'kopf', 'name' => 'Kopfbereiche'])], ], 1055 => [ 'scope' => [new WP_Term(['slug' => 'non_global', 'name' => 'non_global'])], 'layout_type' => [new WP_Term(['slug' => 'section', 'name' => 'section'])], ], 1057 => [], ]; Functions\when('get_the_terms')->alias( static fn (int $id, string $taxonomy): array|false => $terms[$id][$taxonomy] ?? false ); Functions\when('get_post_meta')->alias( static fn (int $id, string $key): string => $id === 1057 && $key === '_et_pb_module_type' ? 'divi/blurb' : '' ); } public function testGlobalScopeAndLayoutTypeFromTheTerms(): void { $store = new DiviLibraryStore(); self::assertTrue($store->isGlobal(1058)); self::assertFalse($store->isGlobal(1055)); self::assertSame('section', $store->layoutType(1058)); self::assertNull($store->layoutType(1057)); self::assertSame(['Kopfbereiche'], $store->termNames(1058, 'layout_category')); } public function testDescribesAnEntry(): void { $post = new WP_Post([ 'ID' => 1057, 'post_type' => 'et_pb_layout', 'post_title' => '[Fixture] Library-Modul', 'post_modified_gmt' => '2026-09-26 20:56:29', ]); self::assertSame( [ 'id' => 1057, 'title' => '[Fixture] Library-Modul', 'layout_type' => null, 'scope' => 'normal', 'module_type' => 'divi/blurb', 'categories' => [], 'tags' => [], 'modified' => '2026-09-26 20:56:29', ], (new DiviLibraryStore())->describe($post) ); } public function testFindQueriesPublishedEntriesWithFilters(): void { $captured = []; Functions\when('get_posts')->alias(static function (array $args) use (&$captured): array { $captured = $args; return []; }); (new DiviLibraryStore())->find( ['layout_type' => 'section', 'scope' => 'normal', 'search' => 'Kopf', 'category' => 'Kopfbereiche'], 20, 40 ); self::assertSame('et_pb_layout', $captured['post_type']); self::assertSame('publish', $captured['post_status']); self::assertSame(21, $captured['posts_per_page']); self::assertSame(40, $captured['offset']); self::assertSame('Kopf', $captured['s']); self::assertSame( [ 'relation' => 'AND', ['taxonomy' => 'layout_type', 'field' => 'slug', 'terms' => ['section']], ['taxonomy' => 'scope', 'field' => 'slug', 'terms' => ['global'], 'operator' => 'NOT IN'], ['taxonomy' => 'layout_category', 'field' => 'name', 'terms' => ['Kopfbereiche']], ], $captured['tax_query'] ); } public function testReportsMissingTaxonomies(): void { Functions\when('taxonomy_exists')->alias(static fn (string $taxonomy): bool => $taxonomy !== 'scope'); self::assertSame(['scope'], (new DiviLibraryStore())->missingTaxonomies()); } }