From 6089ac31ba4e7d09fd454f7c43accf50a6532ba0 Mon Sep 17 00:00:00 2001 From: Matt Sparks Date: Tue, 27 Aug 2019 21:22:31 -0400 Subject: [PATCH] Adding plus and sharp conversion to slug method --- src/Manipulator.php | 2 ++ tests/FunctionsTest.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Manipulator.php b/src/Manipulator.php index a5460be..792b414 100644 --- a/src/Manipulator.php +++ b/src/Manipulator.php @@ -467,6 +467,8 @@ public function toSlug() : Manipulator { $modifiedString = $this->toLower() ->replace(' ', '-') + ->replace('+', '-plus') + ->replace('#', '-sharp') ->removeSpecialCharacters(['-']) ->toString(); diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 1e89076..e589902 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -178,6 +178,15 @@ public function test_that_a_string_is_converted_to_a_slug() $this->assertEquals($string, 'this-is-a-slug'); } + public function test_that_a_string_with_plus_and_sharp_is_slugged() + { + $string = Manipulator::make('C++')->toSlug(); + $this->assertEquals($string, 'c-plus-plus'); + + $string = Manipulator::make('C#')->toSlug(); + $this->assertEquals($string, 'c-sharp'); + } + public function test_that_a_string_is_truncated_and_appended_to() { $string = Manipulator::make('This is a sentence and will be truncated.')->truncate(10); @@ -296,7 +305,7 @@ public function test_that_nth_word_is_modified() public function test_that_custom_accepts_callable_which_can_do_custom_manipulation_on_string() { $string = Manipulator::make('Oh hello there!'); - + $this->assertEquals($string->custom(function ($string) { return strtolower($string); }), 'oh hello there!');