IconCollectionTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Tools\Test\TestCase\View\Icon;
  3. use Cake\TestSuite\TestCase;
  4. use Tools\View\Icon\FeatherIcon;
  5. use Tools\View\Icon\IconCollection;
  6. use Tools\View\Icon\MaterialIcon;
  7. class IconCollectionTest extends TestCase {
  8. /**
  9. * @return void
  10. */
  11. public function testRender(): void {
  12. $config = [
  13. 'sets' => [
  14. 'feather' => [
  15. 'class' => FeatherIcon::class,
  16. ],
  17. ],
  18. 'separator' => ':',
  19. ];
  20. $result = (new IconCollection($config))->render('foo');
  21. $this->assertSame('<span data-feather="foo" title="Foo"></span>', $result);
  22. }
  23. /**
  24. * @return void
  25. */
  26. public function testRenderNamespaced(): void {
  27. $config = [
  28. 'sets' => [
  29. 'feather' => [
  30. 'class' => FeatherIcon::class,
  31. ],
  32. 'material' => [
  33. 'class' => MaterialIcon::class,
  34. 'namespace' => 'material-symbols',
  35. ],
  36. ],
  37. 'separator' => ':',
  38. 'attributes' => [
  39. 'data-default' => 'some-default',
  40. ],
  41. ];
  42. $result = (new IconCollection($config))->render('material:foo');
  43. $this->assertSame('<span class="material-symbols" title="Foo" data-default="some-default">foo</span>', $result);
  44. }
  45. /**
  46. * @return void
  47. */
  48. public function testNames(): void {
  49. $config = [
  50. 'sets' => [
  51. 'feather' => [
  52. 'class' => FeatherIcon::class,
  53. 'path' => TEST_FILES . 'font_icon/feather/icons.json',
  54. ],
  55. 'material' => [
  56. 'class' => MaterialIcon::class,
  57. 'path' => TEST_FILES . 'font_icon/material/index.d.ts',
  58. ],
  59. ],
  60. ];
  61. $result = (new IconCollection($config))->names();
  62. $this->assertTrue(count($result['material']) > 1740, 'count of ' . count($result['material']));
  63. $this->assertTrue(in_array('zoom_out', $result['material'], true));
  64. }
  65. }