Skip to content

Commit

Permalink
Correct kebab case and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Marty Friedel <[email protected]>
  • Loading branch information
martyf committed Nov 15, 2022
1 parent 5bcecf0 commit 8334d12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
21 changes: 7 additions & 14 deletions src/Support/Iconamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MityDigital\Iconamic\Support;

use Illuminate\Support\Str;
use MityDigital\Iconamic\Exceptions\IconamicException;

class Iconamic
Expand Down Expand Up @@ -32,32 +31,26 @@ public function cleanSvg(string $svg, int $index, array $attributes = []): strin
$dom->loadXML($svg, LIBXML_NOERROR);

// if we have classReplace, do this first because it may be appended to by "class"
if (array_key_exists('classReplace', $attributes))
{
if (array_key_exists('classReplace', $attributes)) {
// set the class from classReplace
$dom->documentElement->setAttribute('class', $attributes['classReplace']);

unset($attributes['classReplace']);
}

foreach($attributes as $attribute => $value)
{
if ($attribute === 'class')
{
if ($dom->documentElement->hasAttribute('class'))
{
foreach ($attributes as $attribute => $value) {
if ($attribute === 'class') {
if ($dom->documentElement->hasAttribute('class')) {
// append to the class
$existing = $dom->documentElement->getAttribute('class');
$dom->documentElement->setAttribute($attribute, $existing.' '.$value);
}
else {
} else {
// add the class
$dom->documentElement->setAttribute($attribute, $value);
}
}
else {
} else {
// overwrite attribute - simply add it
$dom->documentElement->setAttribute(Str::kebab($attribute), $value);
$dom->documentElement->setAttribute($attribute, $value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Fieldtypes/IconamicFieldtypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function preload_gets_list_of_icons_using_defaults()
$icons = $this->fieldtype->preload();

$this->assertArrayHasKey('icons', $icons);
$this->assertCount(4, $icons['icons']);
$this->assertCount(5, $icons['icons']);
}

/** @test */
Expand All @@ -72,6 +72,6 @@ public function preload_gets_list_of_icons_using_field_overrides()
$icons = $this->fieldtype->preload();

$this->assertArrayHasKey('icons', $icons);
$this->assertCount(2, $icons['icons']);
$this->assertCount(3, $icons['icons']);
}
}
14 changes: 0 additions & 14 deletions tests/Support/IconamicSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,6 @@ public function clean_svg_can_apply_additional_attributes()
'monkey' => 'tail'
]));

// ensure attribute is converted to kebab case
$this->assertEquals(
'<svg class="w-4 h-4" stroke-width="2"/>',
Iconamic::cleanSvg('<svg class="w-4 h-4"></svg>', 2, [
'strokeWidth' => '2'
]));

// ensure kebab case remains as is
$this->assertEquals(
'<svg class="w-4 h-4" stroke-width="2"/>',
Iconamic::cleanSvg('<svg class="w-4 h-4"></svg>', 2, [
'stroke-width' => '2'
]));

// id is updated accordingly by the cleaner, and left as is
$this->assertEquals(
'<svg id="iconamic-2-svg" class="w-4 h-4"/>',
Expand Down

0 comments on commit 8334d12

Please sign in to comment.