Add basic unit test for FontRepoCompiler
Change-Id: I9b56c1c732a12f79eb2ba6667b7d8c06564ff90f
This commit is contained in:
committed by
jenkins-bot
parent
e93e1bc845
commit
1961ec1766
82
tests/phpunit/FontRepoCompilerTest.php
Normal file
82
tests/phpunit/FontRepoCompilerTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace UniversalLanguageSelector\Tests;
|
||||
|
||||
use \FontRepoCompiler;
|
||||
|
||||
/**
|
||||
* @covers \FontRepoCompiler
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
* @author Thiemo Kreuz
|
||||
*/
|
||||
class FontRepoCompilerTest extends \PHPUnit\Framework\TestCase {
|
||||
use \PHPUnit4And6Compat;
|
||||
|
||||
public function testGetLanguages() {
|
||||
$instance = new FontRepoCompiler( '', '' );
|
||||
|
||||
$result = $instance->getLanguages( [ 'languages' => 'de, en' ] );
|
||||
$this->assertSame( [ 'de', 'en' ], $result );
|
||||
}
|
||||
|
||||
public function testAppendLanguages() {
|
||||
$instance = new FontRepoCompiler( '', '' );
|
||||
|
||||
$languages = [ 'de' => [] ];
|
||||
$fontLanguages = [ 'de', 'en', 'fr*' ];
|
||||
|
||||
$instance->appendLanguages( $languages, $fontLanguages, 'dummyFontName' );
|
||||
$this->assertSame( [
|
||||
'de' => [ 'dummyFontName' ],
|
||||
'en' => [ 'system', 'dummyFontName' ],
|
||||
'fr' => [ 'dummyFontName' ],
|
||||
], $languages );
|
||||
}
|
||||
|
||||
public function testGetAllBasicFontInfo() {
|
||||
$instance = new FontRepoCompiler( '', '' );
|
||||
|
||||
$givenInfo = [
|
||||
'fontweight' => 'dummyFontWeight',
|
||||
'fontstyle' => 'dummyFontStyle',
|
||||
'woff' => 'Alef-Regular.woff',
|
||||
'bold' => 'dummyBold',
|
||||
'bolditalic' => 'dummyBoldItalic',
|
||||
'italic' => 'dummyItalic',
|
||||
];
|
||||
|
||||
$result = $instance->getFontInfo( $givenInfo, __DIR__ . '/../../data/fontrepo/fonts/Alef' );
|
||||
$this->assertSame( [
|
||||
'fontweight' => 'dummyFontWeight',
|
||||
'fontstyle' => 'dummyFontStyle',
|
||||
'woff' => 'Alef/Alef-Regular.woff?2b430',
|
||||
'variants' => [
|
||||
'bold' => 'dummyBold',
|
||||
'bolditalic' => 'dummyBoldItalic',
|
||||
'italic' => 'dummyItalic',
|
||||
],
|
||||
], $result );
|
||||
}
|
||||
|
||||
public function testScanForWoffFiles() {
|
||||
$instance = new FontRepoCompiler( '', '' );
|
||||
|
||||
$result = $instance->getFontInfo( [], __DIR__ . '/../../data/fontrepo/fonts/Alef' );
|
||||
$this->assertSame( [
|
||||
'woff' => 'Alef/Alef-Regular.woff?2b430',
|
||||
'woff2' => 'Alef/Alef-Regular.woff2?a2499',
|
||||
], $result );
|
||||
}
|
||||
|
||||
public function testGetRepository() {
|
||||
$path = __DIR__ . '/../../data/fontrepo/fonts';
|
||||
$instance = new FontRepoCompiler( $path, 'dummyPath' );
|
||||
|
||||
$result = $instance->getRepository();
|
||||
$this->assertSame( 'dummyPath', $result['base'], 'base' );
|
||||
$this->assertContainsOnly( 'array', $result['languages'], 'languages' );
|
||||
$this->assertContainsOnly( 'array', $result['fonts'], 'fonts' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user