Files
WP-LIT-MCP/tests/Unit/Integrations/Divi/Design/FontCheckTest.php
T

58 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
use LIT\MCP\Integrations\Divi\Design\FontCatalog;
use LIT\MCP\Integrations\Divi\Design\FontCheck;
use LIT\MCP\Integrations\Divi\Design\FontSuggest;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
use Mockery\MockInterface;
final class FontCheckTest extends TestCase
{
/** The names FontCatalog::names() delivers in these tests. */
public const NAMES = ['Lato', 'Open Sans', 'Roboto', 'Roboto Mono', 'Roboto Slab'];
/** A FontCatalog over NAMES: has() is exact, like Divi's sanitizer (ruling W5). */
public static function catalog(): FontCatalog&MockInterface
{
$fonts = Mockery::mock(FontCatalog::class);
$fonts->allows('names')->andReturn(self::NAMES);
$fonts->allows('has')->andReturnUsing(static fn (string $name): bool => in_array($name, self::NAMES, true));
return $fonts;
}
public function testAKnownFontIsFine(): void
{
$fonts = self::catalog();
$fonts->shouldNotReceive('names');
self::assertNull(FontCheck::problem($fonts, 'Roboto Mono'));
}
/** Ruling W5: the name is exact – "roboto" is unknown, but gets "Roboto" as suggestion. */
public function testAnUnknownFontGetsSimilarNames(): void
{
self::assertSame(
sprintf(
'unbekannte Schrift „roboto“; ähnlich: %s',
implode(', ', FontSuggest::similar('roboto', self::NAMES))
),
FontCheck::problem(self::catalog(), 'roboto')
);
self::assertStringContainsString('Roboto', (string) FontCheck::problem(self::catalog(), 'roboto'));
}
public function testWithoutSimilarNamesTheUploadToolIsNamed(): void
{
self::assertSame(
'unbekannte Schrift „Xyzzy Grotesk“; eigene Schriften lädt lit/divi-fonts-upload hoch',
FontCheck::problem(self::catalog(), 'Xyzzy Grotesk')
);
}
}