Part-DB.Part-DB-server/tests/Services/Misc/FAIconGeneratorTest.php

113 lines
4 KiB
PHP
Raw Normal View History

<?php
2020-02-22 18:14:36 +01:00
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-01-05 15:55:16 +01:00
declare(strict_types=1);
2022-12-18 17:28:42 +01:00
namespace App\Tests\Services\Misc;
2022-12-18 17:28:42 +01:00
use App\Services\Misc\FAIconGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FAIconGeneratorTest extends WebTestCase
{
/**
2022-12-18 19:45:04 +01:00
* @var FAIconGenerator
*/
protected $service;
2020-01-05 15:55:16 +01:00
protected function setUp(): void
{
2023-06-11 14:18:53 +02:00
// TODO: Change the autogenerated stub
2023-04-15 23:14:53 +02:00
//Get a service instance.
self::bootKernel();
2022-12-18 19:45:04 +01:00
$this->service = self::getContainer()->get(FAIconGenerator::class);
}
2024-06-22 00:31:43 +02:00
public function fileExtensionDataProvider(): \Iterator
{
2024-06-22 00:31:43 +02:00
yield ['pdf', 'fa-file-pdf'];
yield ['jpeg','fa-file-image'];
yield ['txt', 'fa-file-lines'];
yield ['doc', 'fa-file-word'];
yield ['zip', 'fa-file-zipper'];
yield ['png', 'fa-file-image'];
yield ['jpg', 'fa-file-image'];
yield ['gif', 'fa-file-image'];
yield ['svg', 'fa-file-image'];
yield ['xls', 'fa-file-excel'];
yield ['xlsx', 'fa-file-excel'];
yield ['ppt', 'fa-file-powerpoint'];
yield ['pptx', 'fa-file-powerpoint'];
yield ['docx', 'fa-file-word'];
yield ['odt', 'fa-file-word'];
yield ['ods', 'fa-file-excel'];
yield ['odp', 'fa-file-powerpoint'];
yield ['py', 'fa-file-code'];
yield ['js', 'fa-file-code'];
yield ['html', 'fa-file-code'];
yield ['css', 'fa-file-code'];
yield ['xml', 'fa-file-code'];
yield ['json', 'fa-file-code'];
yield ['yml', 'fa-file-code'];
yield ['yaml', 'fa-file-code'];
yield ['csv', 'fa-file-csv'];
yield ['sql', 'fa-file-code'];
yield ['sh', 'fa-file-code'];
yield ['bat', 'fa-file-code'];
yield ['exe', 'fa-file-code'];
yield ['dll', 'fa-file-code'];
yield ['lib', 'fa-file-code'];
yield ['so', 'fa-file-code'];
yield ['a', 'fa-file-code'];
yield ['o', 'fa-file-code'];
yield ['class', 'fa-file-code'];
yield ['jar', 'fa-file-code'];
yield ['rar', 'fa-file-zipper'];
yield ['7z', 'fa-file-zipper'];
yield ['tar', 'fa-file-zipper'];
yield ['gz', 'fa-file-zipper'];
yield ['tgz', 'fa-file-zipper'];
yield ['bz2', 'fa-file-zipper'];
yield ['tbz', 'fa-file-zipper'];
yield ['xz', 'fa-file-zipper'];
yield ['txz', 'fa-file-zipper'];
yield ['zip', 'fa-file-zipper'];
yield ['php', 'fa-file-code'];
yield ['tmp', 'fa-file'];
yield ['fgd', 'fa-file'];
}
/**
* @dataProvider fileExtensionDataProvider
*/
2020-01-05 15:55:16 +01:00
public function testFileExtensionToFAType(string $ext, string $expected): void
{
2023-03-06 00:12:46 +01:00
$this->assertSame($expected, $this->service->fileExtensionToFAType($ext), 'Failed for extension .'.$ext);
}
2020-01-05 15:55:16 +01:00
public function testGenerateIconHTML(): void
{
2022-09-18 18:03:06 +02:00
$this->assertSame('<i class="fa-solid fa-file "></i>', $this->service->generateIconHTML('fa-file'));
2020-01-05 15:55:16 +01:00
$this->assertSame('<i class="far fa-file "></i>', $this->service->generateIconHTML('fa-file', 'far'));
$this->assertSame('<i class="far fa-file fa-2x"></i>', $this->service->generateIconHTML('fa-file', 'far', 'fa-2x'));
}
2020-01-04 20:24:09 +01:00
}