From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- .../Test/Aggregation/ReverseNestedTest.php | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php new file mode 100644 index 00000000..0e2ed2e6 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php @@ -0,0 +1,134 @@ +_createIndex(); + $mapping = new Mapping(); + $mapping->setProperties(array( + 'comments' => array( + 'type' => 'nested', + 'properties' => array( + 'name' => array('type' => 'string'), + 'body' => array('type' => 'string'), + ), + ), + )); + $type = $index->getType('test'); + $type->setMapping($mapping); + + $type->addDocuments(array( + new Document(1, array( + 'comments' => array( + array( + 'name' => 'bob', + 'body' => 'this is bobs comment', + ), + array( + 'name' => 'john', + 'body' => 'this is johns comment', + ), + ), + 'tags' => array('foo', 'bar'), + )), + new Document(2, array( + 'comments' => array( + array( + 'name' => 'bob', + 'body' => 'this is another comment from bob', + ), + array( + 'name' => 'susan', + 'body' => 'this is susans comment', + ), + ), + 'tags' => array('foo', 'baz'), + )), + )); + + $index->refresh(); + + return $index; + } + + /** + * @group unit + */ + public function testPathNotSetIfNull() + { + $agg = new ReverseNested('nested'); + $this->assertFalse($agg->hasParam('path')); + } + + /** + * @group unit + */ + public function testPathSetIfNotNull() + { + $agg = new ReverseNested('nested', 'some_field'); + $this->assertEquals('some_field', $agg->getParam('path')); + } + + /** + * @group functional + */ + public function testReverseNestedAggregation() + { + $agg = new Nested('comments', 'comments'); + $names = new Terms('name'); + $names->setField('comments.name'); + + $tags = new Terms('tags'); + $tags->setField('tags'); + + $reverseNested = new ReverseNested('main'); + $reverseNested->addAggregation($tags); + + $names->addAggregation($reverseNested); + + $agg->addAggregation($names); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('comments'); + + $this->assertArrayHasKey('name', $results); + $nameResults = $results['name']; + + $this->assertCount(3, $nameResults['buckets']); + + // bob + $this->assertEquals('bob', $nameResults['buckets'][0]['key']); + $tags = array( + array('key' => 'foo', 'doc_count' => 2), + array('key' => 'bar', 'doc_count' => 1), + array('key' => 'baz', 'doc_count' => 1), + ); + $this->assertEquals($tags, $nameResults['buckets'][0]['main']['tags']['buckets']); + + // john + $this->assertEquals('john', $nameResults['buckets'][1]['key']); + $tags = array( + array('key' => 'bar', 'doc_count' => 1), + array('key' => 'foo', 'doc_count' => 1), + ); + $this->assertEquals($tags, $nameResults['buckets'][1]['main']['tags']['buckets']); + + // susan + $this->assertEquals('susan', $nameResults['buckets'][2]['key']); + $tags = array( + array('key' => 'baz', 'doc_count' => 1), + array('key' => 'foo', 'doc_count' => 1), + ); + $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']); + } +} -- cgit v1.2.2