浏览代码

Clarify exposed methods.

mscherer 7 年之前
父节点
当前提交
b54bb9c115
共有 2 个文件被更改,包括 22 次插入3 次删除
  1. 11 3
      src/Model/Behavior/SluggedBehavior.php
  2. 11 0
      tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

+ 11 - 3
src/Model/Behavior/SluggedBehavior.php

@@ -84,8 +84,15 @@ class SluggedBehavior extends Behavior {
 		'on' => 'beforeRules',
 		'scope' => [],
 		'tidy' => true,
-		'implementedFinders' => ['slugged' => 'findSlugged'],
-		//'implementedMethods' => ['slug' => 'slug']
+		'implementedFinders' => [
+			'slugged' => 'findSlugged',
+		],
+		'implementedMethods' => [
+			'slug' => 'slug',
+			'generateSlug' => 'generateSlug',
+			'resetSlugs' => 'resetSlugs',
+			'needsSlugUpdate' => 'needsSlugUpdate',
+		],
 	];
 
 	/**
@@ -118,6 +125,7 @@ class SluggedBehavior extends Behavior {
 	 *
 	 * @param array $config The configuration array this behavior is using.
 	 * @return void
+	 * @throws \RuntimeException
 	 */
 	public function initialize(array $config) {
 		if ($this->_config['length'] === null) {
@@ -139,7 +147,7 @@ class SluggedBehavior extends Behavior {
 						throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->$alias->getAlias() . ' is missing the field ' . $field .
 							' (specified in the setup for model ' . $this->_table->getAlias() . ') ');
 					}
-				} elseif (!$this->_table->hasField($field) && !method_exists($this->_table->entityClass(), '_get' . Inflector::classify($field))) {
+				} elseif (!$this->_table->hasField($field) && !method_exists($this->_table->getEntityClass(), '_get' . Inflector::classify($field))) {
 					throw new RuntimeException('(SluggedBehavior::setup) model ' . $this->_table->getAlias() . ' is missing the field ' . $field . ' specified in the setup.');
 				}
 			}

+ 11 - 0
tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

@@ -391,6 +391,17 @@ class SluggedBehaviorTest extends TestCase {
 	}
 
 	/**
+	 * @return void
+	 */
+	public function testSlugManually() {
+		$article = new Entity();
+		$article->title = 'Foo Bar';
+		$this->articles->slug($article);
+
+		$this->assertSame('Foo-Bar', $article->slug);
+	}
+
+	/**
 	 * Test Url method
 	 *
 	 * @return void