From 8334d1261c27f7505c810c34ee95d6a2aa4c4c28 Mon Sep 17 00:00:00 2001
From: Marty Friedel <1491079+martyf@users.noreply.github.com>
Date: Wed, 16 Nov 2022 08:52:20 +1100
Subject: [PATCH] Correct kebab case and tests
Signed-off-by: Marty Friedel <1491079+martyf@users.noreply.github.com>
---
src/Support/Iconamic.php | 21 +++++++--------------
tests/Fieldtypes/IconamicFieldtypeTest.php | 4 ++--
tests/Support/IconamicSupportTest.php | 14 --------------
3 files changed, 9 insertions(+), 30 deletions(-)
diff --git a/src/Support/Iconamic.php b/src/Support/Iconamic.php
index ea1db76..41da2d0 100644
--- a/src/Support/Iconamic.php
+++ b/src/Support/Iconamic.php
@@ -2,7 +2,6 @@
namespace MityDigital\Iconamic\Support;
-use Illuminate\Support\Str;
use MityDigital\Iconamic\Exceptions\IconamicException;
class Iconamic
@@ -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);
}
}
diff --git a/tests/Fieldtypes/IconamicFieldtypeTest.php b/tests/Fieldtypes/IconamicFieldtypeTest.php
index d0242d1..51b1055 100644
--- a/tests/Fieldtypes/IconamicFieldtypeTest.php
+++ b/tests/Fieldtypes/IconamicFieldtypeTest.php
@@ -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 */
@@ -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']);
}
}
diff --git a/tests/Support/IconamicSupportTest.php b/tests/Support/IconamicSupportTest.php
index acf4c7d..e14a17f 100644
--- a/tests/Support/IconamicSupportTest.php
+++ b/tests/Support/IconamicSupportTest.php
@@ -122,20 +122,6 @@ public function clean_svg_can_apply_additional_attributes()
'monkey' => 'tail'
]));
- // ensure attribute is converted to kebab case
- $this->assertEquals(
- '',
- Iconamic::cleanSvg('', 2, [
- 'strokeWidth' => '2'
- ]));
-
- // ensure kebab case remains as is
- $this->assertEquals(
- '',
- Iconamic::cleanSvg('', 2, [
- 'stroke-width' => '2'
- ]));
-
// id is updated accordingly by the cleaner, and left as is
$this->assertEquals(
'',