area); self::assertSame( [ 'et_builder_get_fonts()', 'et_builder_get_custom_fonts()', 'et_builder_get_google_fonts()', 'et_builder_get_websafe_fonts()', 'et_pb_is_allowed()', ], array_map(static fn (Call $call): string => $call->label(), $manifest->calls) ); self::assertSame([0, 0, 0, 0, 1], array_map(static fn (Call $call): ?int => $call->args, $manifest->calls)); self::assertSame(['et_uploaded_fonts', 'et_google_fonts_cache', 'et_google_api_settings'], $manifest->keys); // Plan 4d W1: a broken font list locks every tool that checks font names against it. self::assertSame( [DiviFeature::ThemeOptionWrite, DiviFeature::FontUpload, DiviFeature::VariableWrite], $manifest->features ); self::assertSame([DiviFeature::FontUpload], $manifest->featuresOf($manifest->calls[4])); } /** @runInSeparateProcess */ public function testNamesAreTheExactFamiliesOfDivisSanitizerLoadedOnce(): void { Functions\expect('et_builder_get_custom_fonts')->once()->andReturn(['Hausschrift' => [], '1942' => []]); Functions\expect('et_builder_get_fonts')->once() ->andReturn(['Arial' => [], 'Open Sans' => [], 'Roboto' => []]); $catalog = new FontCatalog(); self::assertSame(['Hausschrift', '1942', 'Arial', 'Open Sans', 'Roboto'], $catalog->names()); self::assertTrue($catalog->has('Roboto')); self::assertTrue($catalog->has('1942'), 'a numeric family name stays a string'); self::assertFalse($catalog->has('roboto'), 'exact, like Divi'); self::assertFalse($catalog->has('none'), 'Divi stores the default font as false, never as a name'); self::assertSame($catalog->names(), $catalog->names()); } /** @runInSeparateProcess */ public function testUploadedAndReservedAreReadFreshEachTime(): void { Functions\expect('et_builder_get_custom_fonts')->twice() ->andReturn(['Hausschrift' => []], ['Hausschrift' => [], 'Neu' => []]); Functions\when('et_builder_get_google_fonts')->justReturn(['Roboto' => []]); Functions\when('et_builder_get_websafe_fonts')->justReturn(['Arial' => [], 'Roboto' => []]); $catalog = new FontCatalog(); self::assertSame(['Hausschrift'], $catalog->uploaded()); self::assertSame(['Roboto', 'Arial', 'Hausschrift', 'Neu'], $catalog->reserved(), 'after an upload'); } /** @runInSeparateProcess */ public function testABrokenListCountsAsEmpty(): void { // A filter of et_builder_google_fonts that returns no array (Divi passes it on unchecked). Functions\when('et_builder_get_google_fonts')->justReturn(null); Functions\when('et_builder_get_websafe_fonts')->justReturn(['Arial' => []]); Functions\when('et_builder_get_custom_fonts')->justReturn([]); self::assertSame(['Arial'], (new FontCatalog())->reserved()); } public function testWithoutDiviNobodyManagesFonts(): void { // Unit tests have no et_pb_is_allowed(): a missing Divi function never means "allowed". self::assertFalse((new FontCatalog())->canManage()); } /** @runInSeparateProcess */ public function testCanManageAsksTheCustomFontsRight(): void { Functions\when('et_pb_is_allowed')->alias(static fn (string $cap): bool => $cap === 'custom_fonts_management'); self::assertTrue((new FontCatalog())->canManage()); } }