| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Tools\Test\TestCase\View\Helper;
- use Cake\View\View;
- use Shim\TestSuite\TestCase;
- use Tools\View\Helper\IconHelper;
- use Tools\View\Icon\FeatherIcon;
- use Tools\View\Icon\MaterialIcon;
- class IconHelperTest extends TestCase {
- /**
- * @var \Tools\View\Helper\IconHelper
- */
- protected $Icon;
- /**
- * @return void
- */
- public function setUp(): void {
- parent::setUp();
- $config = [
- 'sets' => [
- 'feather' => FeatherIcon::class,
- 'm' => MaterialIcon::class,
- ],
- ];
- $this->Icon = new IconHelper(new View(null), $config);
- }
- /**
- * @return void
- */
- public function testIconDefault() {
- $result = $this->Icon->render('edit');
- $expected = '<span data-feather="edit" title="Edit"></span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function testIconPrefixed() {
- $result = $this->Icon->render('feather:edit');
- $expected = '<span data-feather="edit" title="Edit"></span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function testIconWithCustomAttributes() {
- $result = $this->Icon->render('m:save', [], ['data-x' => 'y']);
- $expected = '<span class="material-icons" data-x="y" title="Save">save</span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function testIconWithCustomClassAttributes() {
- $result = $this->Icon->render('m:save', [], ['class' => 'my-extra']);
- $expected = '<span class="material-icons my-extra" title="Save">save</span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function testIconWithCustomTitleField() {
- $result = $this->Icon->render('m:save', ['title' => 'data-title'], ['class' => 'my-extra']);
- $expected = '<span class="material-icons my-extra" data-title="Save">save</span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function testIconWithCustomFontIcon() {
- $config = [
- 'sets' => [
- 'feather' => FeatherIcon::class,
- 'm' => MaterialIcon::class,
- ],
- 'map' => [
- 'edit' => 'm:save',
- ],
- ];
- $this->Icon = new IconHelper(new View(null), $config);
- $result = $this->Icon->render('edit');
- $expected = '<span class="material-icons" title="Edit">save</span>';
- $this->assertSame($expected, $result);
- }
- /**
- * @return void
- */
- public function tearDown(): void {
- parent::tearDown();
- unset($this->Icon);
- }
- }
|