Add from-disk rebuild for font manifest
This commit is contained in:
@@ -305,4 +305,50 @@ class SyncGoogleFontsTest extends TestCase
|
||||
|
||||
File::deleteDirectory($targetPath);
|
||||
}
|
||||
|
||||
public function test_it_rebuilds_manifest_from_disk_without_downloading(): void
|
||||
{
|
||||
$targetPath = storage_path('app/test-fonts');
|
||||
File::deleteDirectory($targetPath);
|
||||
|
||||
File::ensureDirectoryExists($targetPath.'/alpha-sans');
|
||||
File::put($targetPath.'/alpha-sans/AlphaSans-400-normal.ttf', 'font-binary');
|
||||
File::put($targetPath.'/alpha-sans/AlphaSans-700-italic.woff2', 'font-binary');
|
||||
|
||||
File::ensureDirectoryExists($targetPath.'/beta-serif');
|
||||
File::put($targetPath.'/beta-serif/BetaSerif-Regular.ttf', 'font-binary');
|
||||
|
||||
File::ensureDirectoryExists($targetPath.'/ibm-plex-sans');
|
||||
File::put($targetPath.'/ibm-plex-sans/IBMPlexSans-Bold.ttf', 'font-binary');
|
||||
|
||||
Http::fake();
|
||||
|
||||
Artisan::call('fonts:sync-google', [
|
||||
'--from-disk' => true,
|
||||
'--path' => 'storage/app/test-fonts',
|
||||
]);
|
||||
|
||||
Http::assertNothingSent();
|
||||
|
||||
$manifestPath = $targetPath.'/manifest.json';
|
||||
$cssPath = $targetPath.'/fonts.css';
|
||||
|
||||
$this->assertFileExists($manifestPath);
|
||||
$this->assertFileExists($cssPath);
|
||||
|
||||
$manifest = json_decode(File::get($manifestPath), true);
|
||||
$this->assertSame(3, $manifest['count']);
|
||||
$this->assertTrue(collect($manifest['fonts'])->pluck('family')->contains('Alpha Sans'));
|
||||
$this->assertTrue(collect($manifest['fonts'])->pluck('family')->contains('Beta Serif'));
|
||||
$this->assertTrue(collect($manifest['fonts'])->pluck('family')->contains('IBM Plex Sans'));
|
||||
|
||||
$this->assertTrue(str_contains(File::get($cssPath), "font-family: 'IBM Plex Sans';"));
|
||||
|
||||
$alpha = collect($manifest['fonts'])->firstWhere('family', 'Alpha Sans');
|
||||
$alphaVariants = collect($alpha['variants'] ?? [])->pluck('variant')->all();
|
||||
$this->assertContains('regular', $alphaVariants);
|
||||
$this->assertContains('700italic', $alphaVariants);
|
||||
|
||||
File::deleteDirectory($targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user