Skip to content

Commit

Permalink
Fix svg icon font with class prefix and suffix (#37)
Browse files Browse the repository at this point in the history
* Fix svg icon font with class prefix

* Adjust tests

* Fix suffix
  • Loading branch information
alexander-schranz authored Sep 20, 2021
1 parent b54e6cc commit 65e5200
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/IconExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getIcon(string $icon, $attributes = [], string $iconSetName = 'd
'<svg%s><use xlink:href="%s#%s"></use></svg>',
$this->renderAttributes($attributes),
$iconSet['path'],
$icon
$iconSet['classPrefix'] . $icon . $iconSet['classSuffix']
);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/IconExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testSvgIcon(): void
]);

$this->assertSame(
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#icon-test"></use></svg>',
$iconExtension->getIcon('test')
);
}
Expand All @@ -127,7 +127,7 @@ public function testSvgIconAttributes(): void
]);

$this->assertSame(
'<svg role="none" class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg role="none" class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#icon-test"></use></svg>',
$iconExtension->getIcon('test', ['role' => 'none'])
);
}
Expand All @@ -147,7 +147,7 @@ public function testSvgIconDefaultAttributes(): void
);

$this->assertSame(
'<svg role="none" class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg role="none" class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#icon-test"></use></svg>',
$iconExtension->getIcon('test')
);
}
Expand All @@ -167,7 +167,7 @@ public function testSvgIconRemoveDefaultAttributes(): void
);

$this->assertSame(
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#icon-test"></use></svg>',
$iconExtension->getIcon('test', ['role' => null])
);
}
Expand All @@ -185,7 +185,7 @@ public function testSvgIconCustomSettings(): void
]);

$this->assertSame(
'<svg class="add-class my-icon my-icon-test-new"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg class="add-class my-icon my-icon-test-new"><use xlink:href="/path/to/symbol-defs.svg#my-icon-test-new"></use></svg>',
$iconExtension->getIcon('test', 'add-class', 'other')
);
}
Expand All @@ -200,7 +200,7 @@ public function testSvgIconOtherGroup(): void
]);

$this->assertSame(
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#test"></use></svg>',
'<svg class="icon icon-test"><use xlink:href="/path/to/symbol-defs.svg#icon-test"></use></svg>',
$iconExtension->getIcon('test', null, 'other')
);
}
Expand Down

0 comments on commit 65e5200

Please sign in to comment.