Skip to content

Commit

Permalink
Change default replacement for Inflector::slug().
Browse files Browse the repository at this point in the history
Use dash instead of underscore.
  • Loading branch information
ADmad committed Sep 28, 2014
1 parent 3f1a3d8 commit f8ba7da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Utility/Inflector.php
Expand Up @@ -679,15 +679,15 @@ public static function variable($string) {
}

/**
* Returns a string with all spaces converted to underscores (by default), accented
* Returns a string with all spaces converted to dashes (by default), accented
* characters converted to non-accented characters, and non word characters removed.
*
* @param string $string the string you want to slug
* @param string $replacement will replace keys in map
* @return string
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::slug
*/
public static function slug($string, $replacement = '_') {
public static function slug($string, $replacement = '-') {
$quotedReplacement = preg_quote($replacement, '/');

$map = array(
Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Utility/InflectorTest.php
Expand Up @@ -249,18 +249,18 @@ public function testInflectingPlurals() {
*/
public function testInflectorSlug() {
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more');
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
$this->assertEquals($expected, $result);

$result = Inflector::slug('this/is/a/path');
$expected = 'this_is_a_path';
$expected = 'this-is-a-path';
$this->assertEquals($expected, $result);

$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "-");
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', '_');
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
$this->assertEquals($expected, $result);

$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "+");
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', '+');
$expected = 'Foo+Bar+Not+just+for+breakfast+any+more';
$this->assertEquals($expected, $result);

Expand Down Expand Up @@ -293,19 +293,19 @@ public function testInflectorSlug() {
$this->assertEquals($expected, $result);

$result = Inflector::slug('controller/action/りんご/1');
$expected = 'controller_action_りんご_1';
$expected = 'controller-action-りんご-1';
$this->assertEquals($expected, $result);

$result = Inflector::slug('の話が出たので大丈夫かなあと');
$expected = 'の話が出たので大丈夫かなあと';
$this->assertEquals($expected, $result);

$result = Inflector::slug('posts/view/한국어/page:1/sort:asc');
$expected = 'posts_view_한국어_page_1_sort_asc';
$expected = 'posts-view-한국어-page-1-sort-asc';
$this->assertEquals($expected, $result);

$result = Inflector::slug("non\xc2\xa0breaking\xc2\xa0space");
$this->assertEquals('non_breaking_space', $result);
$this->assertEquals('non-breaking-space', $result);
}

/**
Expand All @@ -330,7 +330,7 @@ public function testInflectorSlugCharList() {
public function testInflectorSlugWithMap() {
Inflector::rules('transliteration', array('r' => '1'));
$result = Inflector::slug('replace every r');
$expected = '1eplace_eve1y_1';
$expected = '1eplace-eve1y-1';
$this->assertEquals($expected, $result);

$result = Inflector::slug('replace every r', '_');
Expand Down Expand Up @@ -490,13 +490,13 @@ public function testCustomSingularRule() {
* @return void
*/
public function testCustomTransliterationRule() {
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_o_a');
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing-ae-o-a');

Inflector::rules('transliteration', array('å' => 'aa', 'ø' => 'oe'));
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_oe_aa');
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing-ae-oe-aa');

Inflector::rules('transliteration', array('æ' => 'ae', 'å' => 'aa'), true);
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_ø_aa');
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing-ae-ø-aa');
}

/**
Expand Down

0 comments on commit f8ba7da

Please sign in to comment.