IconCollectionTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 'attributes' => [
  36. 'data-custom' => 'some-custom',
  37. ],
  38. ],
  39. ],
  40. 'separator' => ':',
  41. 'attributes' => [
  42. 'data-default' => 'some-default',
  43. ],
  44. ];
  45. $result = (new IconCollection($config))->render('material:foo');
  46. $this->assertSame('<span class="material-symbols" title="Foo" data-custom="some-custom" data-default="some-default">foo</span>', $result);
  47. }
  48. /**
  49. * @return void
  50. */
  51. public function testNames(): void {
  52. $config = [
  53. 'sets' => [
  54. 'feather' => [
  55. 'class' => FeatherIcon::class,
  56. 'path' => TEST_FILES . 'font_icon/feather/icons.json',
  57. ],
  58. 'material' => [
  59. 'class' => MaterialIcon::class,
  60. 'path' => TEST_FILES . 'font_icon/material/index.d.ts',
  61. ],
  62. ],
  63. ];
  64. $result = (new IconCollection($config))->names();
  65. $this->assertTrue(count($result['material']) > 1740, 'count of ' . count($result['material']));
  66. $this->assertTrue(in_array('zoom_out', $result['material'], true));
  67. }
  68. }