Skip to content

Commit

Permalink
adds special characters compatibility (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
grpaiva authored and William committed Sep 19, 2019
1 parent 3e896b5 commit 91b4cc2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Filters/Capitalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Capitalize implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? ucwords(strtolower($value)) : $value;
return is_string($value) ? mb_convert_case(mb_strtolower($value, 'UTF-8'), MB_CASE_TITLE) : $value;
}
}
2 changes: 1 addition & 1 deletion src/Filters/Lowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Lowercase implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? strtolower($value) : $value;
return is_string($value) ? mb_strtolower($value, 'UTF-8') : $value;
}
}
2 changes: 1 addition & 1 deletion src/Filters/Uppercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Uppercase implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? strtoupper($value) : $value;
return is_string($value) ? mb_strtoupper($value) : $value;
}
}
9 changes: 9 additions & 0 deletions tests/Filters/CapitalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public function it_capitalizes_strings()
$result = $this->sanitize(['name' => ' jon snow 145'], ['name' => 'capitalize']);
$this->assertEquals(' Jon Snow 145', $result['name']);
}

/**
* @test
*/
public function it_capitalizes_special_characters()
{
$result = $this->sanitize(['name' => 'Τάχιστη αλώπηξ'], ['name' => 'capitalize']);
$this->assertEquals('Τάχιστη Αλώπηξ', $result['name']);
}
}
15 changes: 15 additions & 0 deletions tests/Filters/LowercaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public function it_lowercases_strings()
$data = $this->sanitize($data, $rules);
$this->assertEquals('hello everybody', $data['name']);
}

/**
* @test
*/
public function it_lowercases_special_characters_strings()
{
$data = [
'name' => 'Τάχιστη αλώπηξ',
];
$rules = [
'name' => 'lowercase',
];
$data = $this->sanitize($data, $rules);
$this->assertEquals('τάχιστη αλώπηξ', $data['name']);
}
}
15 changes: 15 additions & 0 deletions tests/Filters/UppercaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public function it_uppercases_strings()
$data = $this->sanitize($data, $rules);
$this->assertEquals('HELLO EVERYBODY', $data['name']);
}

/**
* @test
*/
public function it_uppercases_special_characters_strings()
{
$data = [
'name' => 'Τάχιστη αλώπηξ',
];
$rules = [
'name' => 'uppercase',
];
$data = $this->sanitize($data, $rules);
$this->assertEquals('ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ', $data['name']);
}
}

0 comments on commit 91b4cc2

Please sign in to comment.