makeResult($this->simpleItems); $nestedResult = new NestedResult($result); $root = $nestedResult->getRoot(0); $this->assertCount(0, $root->getChildren(), 'no children expected'); $this->assertCount(12, $root->getResultRows(), '12 result rows expected'); } /** * Nest by the first level, no multi values */ public function testSimpleOneLevel() { $result = $this->makeResult($this->simpleItems); $nestedResult = new NestedResult($result); $tree = $nestedResult->getRoot(1)->getChildren(); $this->assertCount(2, $tree, '2 root nodes expected'); $this->assertEquals('car', $tree[0]->getValueObject()->getValue()); $this->assertEquals('laptop', $tree[1]->getValueObject()->getValue()); $this->assertCount(0, $tree[0]->getChildren(), 'no children expected'); $this->assertCount(0, $tree[1]->getChildren(), 'no children expected'); $this->assertCount(6, $tree[0]->getResultRows(), 'result rows'); $this->assertCount(6, $tree[1]->getResultRows(), 'result rows'); $this->assertEquals('a80', $tree[0]->getResultRows()[0][1]->getValue(), 'Audi 80 expected'); $this->assertEquals('pro 16', $tree[1]->getResultRows()[0][1]->getValue(), 'Mac Pro 16 expected'); } /** * Nest by two levels, no multi values */ public function testSimpleTwoLevels() { $result = $this->makeResult($this->simpleItems); $nestedResult = new NestedResult($result); $tree = $nestedResult->getRoot(2)->getChildren(); $this->assertCount(2, $tree, '2 root nodes expected'); $this->assertEquals('car', $tree[0]->getValueObject()->getValue()); $this->assertEquals('laptop', $tree[1]->getValueObject()->getValue()); $this->assertCount(2, $tree[0]->getChildren(), '2 second level nodes expected'); $this->assertCount(2, $tree[1]->getChildren(), '2 second level nodes expected'); $this->assertCount(3, $tree[0]->getChildren()[0]->getResultRows(), 'result rows'); $this->assertCount(3, $tree[0]->getChildren()[1]->getResultRows(), 'result rows'); $this->assertCount(3, $tree[1]->getChildren()[0]->getResultRows(), 'result rows'); $this->assertCount(3, $tree[1]->getChildren()[1]->getResultRows(), 'result rows'); $this->assertEquals('a80', $tree[0]->getChildren()[0]->getResultRows()[0][0]->getValue(), 'Audi 80 expected'); $this->assertEquals('pro 16', $tree[1]->getChildren()[0]->getResultRows()[0][0]->getValue(), 'Mac Pro 16 expected'); } public function testMultiTwoLevels() { $result = $this->makeResult($this->multiItems); $nestedResult = new NestedResult($result); $tree = $nestedResult->getRoot(3)->getChildren(); // nest: color, type, brand -> model $this->assertCount(6, $tree, '6 root nodes of colors expected'); // Values on the first level will be multi-values, thus returning arrays $this->assertEquals('black', $tree[0]->getValueObject()->getValue()[0]); $this->assertEquals('blue', $tree[1]->getValueObject()->getValue()[0]); $this->assertEquals('gray', $tree[2]->getValueObject()->getValue()[0]); $this->assertEquals('green', $tree[3]->getValueObject()->getValue()[0]); $this->assertEquals('red', $tree[4]->getValueObject()->getValue()[0]); $this->assertEquals('yellow', $tree[5]->getValueObject()->getValue()[0]); // Results should now show up under multiple top-level nodes $this->assertEquals('a80', $tree[3] // green ->getChildren()[0] // car ->getChildren()[0] // audi ->getResultRows()[0][0] // a80 ->getValue(), 'green car audi a80 expected' ); $this->assertEquals('a80', $tree[5] // yellow ->getChildren()[0] // car ->getChildren()[0] // audi ->getResultRows()[0][0] // a80 ->getValue(), 'yellow car audi a80 expected' ); } }