diff --git a/app/Import/Logging/CommandHandler.php b/app/Import/Logging/CommandHandler.php index c35663e53e..eb1d9c1b7a 100644 --- a/app/Import/Logging/CommandHandler.php +++ b/app/Import/Logging/CommandHandler.php @@ -26,6 +26,7 @@ use Illuminate\Console\Command; use Monolog\Handler\AbstractProcessingHandler; /** + * @codeCoverageIgnore * Class CommandHandler. */ class CommandHandler extends AbstractProcessingHandler diff --git a/app/Import/MapperPreProcess/TagsComma.php b/app/Import/MapperPreProcess/TagsComma.php index d3d2e4165a..43d628c577 100644 --- a/app/Import/MapperPreProcess/TagsComma.php +++ b/app/Import/MapperPreProcess/TagsComma.php @@ -34,6 +34,11 @@ class TagsComma implements PreProcessorInterface */ public function run(string $value): array { - return explode(',', $value); + $set = explode(',', $value); + $set = array_map('trim', $set); + $set = array_filter($set, 'strlen'); + $return = array_values($set); + + return $return; } } diff --git a/app/Import/MapperPreProcess/TagsSpace.php b/app/Import/MapperPreProcess/TagsSpace.php index cd897e7c67..d8967ee9fb 100644 --- a/app/Import/MapperPreProcess/TagsSpace.php +++ b/app/Import/MapperPreProcess/TagsSpace.php @@ -34,6 +34,11 @@ class TagsSpace implements PreProcessorInterface */ public function run(string $value): array { - return explode(' ', $value); + $set = explode(' ', $value); + $set = array_map('trim', $set); + $set = array_filter($set, 'strlen'); + $return = array_values($set); + + return $return; } } diff --git a/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php b/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php new file mode 100644 index 0000000000..c3deeb1516 --- /dev/null +++ b/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php @@ -0,0 +1,49 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Unit\Import\MapperPreProcess; + +use FireflyIII\Import\MapperPreProcess\TagsComma; +use Tests\TestCase; + +/** + * Class TagsCommaTest + */ +class TagsCommaTest extends TestCase +{ + + /** + * \FireflyIII\Import\MapperPreProcess\TagsComma::run + */ + public function testBasic() + { + $input = 'some,tags, with, spaces ,and,without,,'; + $output = ['some', 'tags', 'with', 'spaces', 'and', 'without']; + $mapper = new TagsComma(); + $result = $mapper->run($input); + + $this->assertEquals($output, $result); + + } + +} \ No newline at end of file diff --git a/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php b/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php new file mode 100644 index 0000000000..207b5151cb --- /dev/null +++ b/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php @@ -0,0 +1,49 @@ +. + */ + +declare(strict_types=1); + +namespace Tests\Unit\Import\MapperPreProcess; + +use FireflyIII\Import\MapperPreProcess\TagsComma; +use FireflyIII\Import\MapperPreProcess\TagsSpace; +use Tests\TestCase; + +/** + * Class TagsSpaceTest + */ +class TagsSpaceTest extends TestCase +{ + + /** + * \FireflyIII\Import\MapperPreProcess\TagsSpace::run + */ + public function testBasic() + { + $input = 'some tags with spaces,and without '; + $output = ['some', 'tags', 'with', 'spaces,and', 'without']; + $mapper = new TagsSpace(); + $result = $mapper->run($input); + + $this->assertEquals($output, $result); + } + +} \ No newline at end of file