Browse Source

Merge remote-tracking branch 'origin/2.5' into 3.0

Conflicts:
	VERSION.txt
	lib/Cake/Model/Datasource/Database/Sqlserver.php
	lib/Cake/Model/Datasource/DboSource.php
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
	lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
mark_story 12 years ago
parent
commit
02baf1b11a
3 changed files with 43 additions and 4 deletions
  1. 7 1
      src/Utility/Hash.php
  2. 3 3
      src/Utility/String.php
  3. 33 0
      tests/TestCase/Utility/HashTest.php

+ 7 - 1
src/Utility/Hash.php

@@ -201,7 +201,13 @@ class Hash {
 				return false;
 			}
 
-			$prop = isset($data[$attr]) ? $data[$attr] : null;
+			$prop = null;
+			if (isset($data[$attr])) {
+				$prop = $data[$attr];
+			}
+			if ($prop === true || $prop === false) {
+				$prop = $prop ? 'true' : 'false';
+			}
 
 			// Pattern matches and other operators.
 			if ($op === '=' && $val && $val[0] === '/') {

+ 3 - 3
src/Utility/String.php

@@ -406,8 +406,8 @@ class String {
  * - `html` If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
  * - `regex` a custom regex rule that is used to match words, default is '|$tag|iu'
  *
- * @param string $text Text to search the phrase in
- * @param string $phrase The phrase that will be searched
+ * @param string $text Text to search the phrase in.
+ * @param string|array $phrase The phrase or phrases that will be searched.
  * @param array $options An array of html attributes and options.
  * @return string The highlighted text
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight
@@ -451,7 +451,7 @@ class String {
 	}
 
 /**
- * Strips given text of all links (<a href=....)
+ * Strips given text of all links (<a href=....).
  *
  * @param string $text Text
  * @return string The text without links

+ 33 - 0
tests/TestCase/Utility/HashTest.php

@@ -836,6 +836,39 @@ class HashTest extends TestCase {
 	}
 
 /**
+ * Test extracting based on attributes with boolean values.
+ *
+ * @return void
+ */
+	public function testExtractAttributeBoolean() {
+		$users = array(
+			array(
+				'id' => 2,
+				'username' => 'johndoe',
+				'active' => true
+			),
+			array(
+				'id' => 5,
+				'username' => 'kevin',
+				'active' => true
+			),
+			array(
+				'id' => 9,
+				'username' => 'samantha',
+				'active' => false
+			),
+		);
+		$result = Hash::extract($users, '{n}[active=false]');
+		$this->assertCount(1, $result);
+		$this->assertEquals($users[2], $result[0]);
+
+		$result = Hash::extract($users, '{n}[active=true]');
+		$this->assertCount(2, $result);
+		$this->assertEquals($users[0], $result[0]);
+		$this->assertEquals($users[1], $result[1]);
+	}
+
+/**
  * Test that attribute matchers don't cause errors on scalar data.
  *
  * @return void