IconHelperTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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" 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 my-extra" title="Save">save</span>';
  56. $this->assertSame($expected, $result);
  57. }
  58. /**
  59. * @return void
  60. */
  61. public function testIconWithCustomTitleField() {
  62. $result = $this->Icon->render('m:save', ['title' => 'data-title'], ['class' => 'my-extra']);
  63. $expected = '<span class="material-icons my-extra" data-title="Save">save</span>';
  64. $this->assertSame($expected, $result);
  65. }
  66. /**
  67. * @return void
  68. */
  69. public function testIconWithCustomFontIcon() {
  70. $config = [
  71. 'sets' => [
  72. 'feather' => FeatherIcon::class,
  73. 'm' => MaterialIcon::class,
  74. ],
  75. 'map' => [
  76. 'edit' => 'm:save',
  77. ],
  78. ];
  79. $this->Icon = new IconHelper(new View(null), $config);
  80. $result = $this->Icon->render('edit');
  81. $expected = '<span class="material-icons" title="Edit">save</span>';
  82. $this->assertSame($expected, $result);
  83. }
  84. /**
  85. * @return void
  86. */
  87. public function tearDown(): void {
  88. parent::tearDown();
  89. unset($this->Icon);
  90. }
  91. }