ソースを参照

misc fixes in BitmaskedBehavior

Val Bancer 9 年 前
コミット
6dd86b0da1

+ 5 - 4
Model/Behavior/BitmaskedBehavior.php

@@ -163,9 +163,10 @@ class BitmaskedBehavior extends ModelBehavior {
 	/**
 	 * Gets the name of the first field name.
 	 *
+	 * @param Model $Model
 	 * @return string
 	 */
-	protected function _getFieldName() {
+	protected function _getFieldName(Model $Model) {
 		$firstField = reset($this->settings[$Model->alias]);
 		return key($firstField);
 	}
@@ -178,7 +179,7 @@ class BitmaskedBehavior extends ModelBehavior {
 	 */
 	public function decodeBitmask(Model $Model, $value, $fieldName = null) {
 		if (empty($fieldName)) {
-			$fieldName = $this->_getFieldName();
+			$fieldName = $this->_getFieldName($Model);
 		}
 		$res = [];
 		$value = (int)$value;
@@ -283,7 +284,7 @@ class BitmaskedBehavior extends ModelBehavior {
 	 */
 	public function isBit(Model $Model, $bits, $fieldName = null) {
 		if (empty($fieldName)) {
-			$fieldName = $this->_getFieldName();
+			$fieldName = $this->_getFieldName($Model);
 		}
 		$bits = (array)$bits;
 		$bitmask = $this->encodeBitmask($Model, $bits);
@@ -329,7 +330,7 @@ class BitmaskedBehavior extends ModelBehavior {
 	 */
 	protected function _containsBit(Model $Model, $bits, $fieldName = null, $contain = true) {
 		if (empty($fieldName)) {
-			$fieldName = $this->_getFieldName();
+			$fieldName = $this->_getFieldName($Model);
 		}
 		$bits = (array)$bits;
 		$bitmask = $this->encodeBitmask($Model, $bits);

+ 1 - 1
Test/Case/Model/Behavior/BitmaskedBehaviorTest.php

@@ -110,7 +110,7 @@ class BitmaskedBehaviorTest extends MyCakeTestCase {
 	 * Assert that you can manually trigger "notEmpty" rule with null instead of 0 for "not null" db fields
 	 */
 	public function testSaveWithDefaultValue() {
-		$this->Comment->Behaviors->unload('Tools.Bitmasked');
+		$this->Comment->Behaviors->unload('Bitmasked');
 		$this->Comment->Behaviors->load('Tools.Bitmasked', ['mappedField' => 'statuses', 'defaultValue' => '']);
 		$data = [
 			'comment' => 'test save',