AssetsExtensionTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Tests\Unit\Service\Twig;
  3. use App\Entity\Core\File;
  4. use App\Service\File\FileManager;
  5. use App\Service\Twig\AssetsExtension;
  6. use App\Service\Utils\Path;
  7. use PHPUnit\Framework\TestCase;
  8. class AssetsExtensionTest extends TestCase
  9. {
  10. private FileManager $fileManager;
  11. public function setUp(): void {
  12. $this->fileManager = $this->getMockBuilder(FileManager::class)->disableOriginalConstructor()->getMock();
  13. }
  14. public function testGetFunctions(): void {
  15. $assetsExtension = $this
  16. ->getMockBuilder(AssetsExtension::class)
  17. ->setConstructorArgs([$this->fileManager])
  18. ->setMethodsExcept(['getFunctions'])
  19. ->getMock();
  20. $functions = $assetsExtension->getFunctions();
  21. $this->assertCount(2, $functions);
  22. $this->assertEquals('absPath', $functions[0]->getName());
  23. $this->assertEquals('fileImagePath', $functions[1]->getName());
  24. }
  25. public function testAbsPath(): void {
  26. $assetsExtension = $this
  27. ->getMockBuilder(AssetsExtension::class)
  28. ->setConstructorArgs([$this->fileManager])
  29. ->setMethodsExcept(['absPath'])
  30. ->getMock();
  31. $publicDir = Path::getProjectDir();
  32. $this->assertEquals(
  33. $publicDir . '/public/foo',
  34. $assetsExtension->absPath('foo')
  35. );
  36. $this->assertEquals(
  37. $publicDir . '/public/foo/bar',
  38. $assetsExtension->absPath('foo/bar')
  39. );
  40. $this->assertEquals(
  41. $publicDir . '/public',
  42. $assetsExtension->absPath('')
  43. );
  44. }
  45. }