Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from josegonzalez/master

Added method to override Sluggable::multibyteSlug()
  • Loading branch information...
commit 5845ea98f3c83008928cb378a619298389cc12ea 2 parents 2a703f3 + a736d0f
@burzum burzum authored
View
6 models/behaviors/sluggable.php
@@ -91,7 +91,11 @@ public function beforeSave(Model $Model) {
}
$settings = $this->settings[$Model->alias];
- $slug = $this->multibyteSlug($Model, $slug, $settings['separator']);
+ if (method_exists($Model, 'multibyteSlug')) {
+ $slug = $Model->multibyteSlug($slug, $settings['separator']);
+ } else {
+ $slug = $this->multibyteSlug($Model, $slug);
+ }
if ($settings['unique'] === true || is_array($settings['unique'])) {
$slug = $this->makeUniqueSlug($Model, $slug);
View
26 tests/cases/behaviors/sluggable.test.php
@@ -16,6 +16,18 @@ class SluggedArticle extends CakeTestModel {
}
/**
+ * Slugged Article
+ */
+class SluggedCustomArticle extends CakeTestModel {
+ public $useTable = 'articles';
+ public $actsAs = array('SluggableTest');
+
+ function multibyteSlug($string = null, $separator = '_') {
+ return 'slug';
+ }
+}
+
+/**
* Sluggable Test case
*/
class SluggableTest extends CakeTestCase {
@@ -34,6 +46,7 @@ class SluggableTest extends CakeTestCase {
*/
public function startTest() {
$this->Model = new SluggedArticle();
+ $this->ModelTwo = new SluggedCustomArticle();
$this->Behavior = new SluggableTestBehavior();
}
@@ -78,6 +91,19 @@ public function testSave() {
}
/**
+ * Test saving a item
+ *
+ * @return void
+ */
+ public function testCustomMultibyteSlug() {
+ $this->ModelTwo->create(array('title' => 'Fifth Article'));
+ $this->ModelTwo->save();
+
+ $result = $this->ModelTwo->read();
+ $this->assertEqual($result['SluggedCustomArticle']['slug'], 'slug');
+ }
+
+/**
* Test save unique
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.