IconHelperTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Tools\Test\TestCase\View\Helper;
  3. use Cake\View\View;
  4. use Shim\TestSuite\TestCase;
  5. use Tools\View\Helper\IconHelper;
  6. use Tools\View\Icon\FeatherIcon;
  7. use Tools\View\Icon\MaterialIcon;
  8. class IconHelperTest extends TestCase {
  9. /**
  10. * @var \Tools\View\Helper\IconHelper
  11. */
  12. protected $Icon;
  13. /**
  14. * @return void
  15. */
  16. public function setUp(): void {
  17. parent::setUp();
  18. $config = [
  19. 'sets' => [
  20. 'feather' => FeatherIcon::class,
  21. 'm' => MaterialIcon::class,
  22. ],
  23. ];
  24. $this->Icon = new IconHelper(new View(null), $config);
  25. }
  26. /**
  27. * @return void
  28. */
  29. public function testIconDefault() {
  30. $result = $this->Icon->render('edit');
  31. $expected = '<span data-feather="edit" title="Edit"></span>';
  32. $this->assertSame($expected, $result);
  33. }
  34. /**
  35. * @return void
  36. */
  37. public function testIconPrefixed() {
  38. $result = $this->Icon->render('feather:edit');
  39. $expected = '<span data-feather="edit" title="Edit"></span>';
  40. $this->assertSame($expected, $result);
  41. }
  42. /**
  43. * @return void
  44. */
  45. public function testIconWithCustomAttributes() {
  46. $result = $this->Icon->render('m:save', [], ['data-x' => 'y']);
  47. $expected = '<span class="material-icons-outlined" data-x="y" title="Save">save</span>';
  48. $this->assertSame($expected, $result);
  49. }
  50. /**
  51. * @return void
  52. */
  53. public function testIconWithCustomClassAttributes() {
  54. $result = $this->Icon->render('m:save', [], ['class' => 'my-extra']);
  55. $expected = '<span class="material-icons-outlined my-extra" title="Save">save</span>';
  56. $this->assertSame($expected, $result);
  57. }
  58. /**
  59. * @return void
  60. */
  61. public function testIconWithCustomFontIcon() {
  62. $config = [
  63. 'sets' => [
  64. 'feather' => FeatherIcon::class,
  65. 'm' => MaterialIcon::class,
  66. ],
  67. 'map' => [
  68. 'edit' => 'm:save',
  69. ],
  70. ];
  71. $this->Icon = new IconHelper(new View(null), $config);
  72. $result = $this->Icon->render('edit');
  73. $expected = '<span class="material-icons-outlined" title="Save">save</span>';
  74. $this->assertSame($expected, $result);
  75. }
  76. /**
  77. * @return void
  78. */
  79. public function tearDown(): void {
  80. parent::tearDown();
  81. unset($this->Icon);
  82. }
  83. }