Browse Source

Adding a line to the docs of Hash and a test case.

Florian Krämer 10 years ago
parent
commit
138927a613
2 changed files with 16 additions and 0 deletions
  1. 1 0
      src/Utility/Hash.php
  2. 15 0
      tests/TestCase/Utility/HashTest.php

+ 1 - 0
src/Utility/Hash.php

@@ -113,6 +113,7 @@ class Hash
      * - `{n}.User[id]` Get the name of every user with an id key.
      * - `{n}.User[id>=2]` Get the name of every user with an id key greater than or equal to 2.
      * - `{n}.User[username=/^paul/]` Get User elements with username matching `^paul`.
+     * - `{n}.User[id=1].name` Get the Users name with id matching `1`.
      *
      * @param array|\ArrayAccess $data The data to extract from.
      * @param string $path The path to extract.

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

@@ -893,6 +893,21 @@ class HashTest extends TestCase
     }
 
     /**
+     * Test the extraction of a single value filtered by another field.
+     *
+     * @dataProvider articleDataSets
+     * @return void
+     */
+    public function testExtractSingleValueWithFilteringByAnotherField($data)
+    {
+        $result = Hash::extract($data, '{*}.Article[id=1].title');
+        $this->assertEquals([0 => 'First Article'], $result);
+
+        $result = Hash::extract($data, '{*}.Article[id=2].title');
+        $this->assertEquals([0 => 'Second Article'], $result);
+    }
+
+    /**
      * Test simple paths.
      *
      * @dataProvider articleDataSets