Skip to content

Commit

Permalink
Adding plus and sharp conversion to slug method
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Sparks authored and Matt Sparks committed Aug 28, 2019
1 parent bc11319 commit 6089ac3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Manipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ public function toSlug() : Manipulator
{
$modifiedString = $this->toLower()
->replace(' ', '-')
->replace('+', '-plus')
->replace('#', '-sharp')
->removeSpecialCharacters(['-'])
->toString();

Expand Down
11 changes: 10 additions & 1 deletion tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!');
Expand Down

0 comments on commit 6089ac3

Please sign in to comment.