summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php108
1 files changed, 108 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php
new file mode 100644
index 00000000..31a89852
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/HasParentTest.php
@@ -0,0 +1,108 @@
+<?php
+namespace Elastica\Test\Query;
+
+use Elastica\Document;
+use Elastica\Query\HasParent;
+use Elastica\Query\Match;
+use Elastica\Query\MatchAll;
+use Elastica\Search;
+use Elastica\Test\Base as BaseTest;
+use Elastica\Type\Mapping;
+
+class HasParentTest extends BaseTest
+{
+ /**
+ * @group unit
+ */
+ public function testToArray()
+ {
+ $q = new MatchAll();
+
+ $type = 'test';
+
+ $query = new HasParent($q, $type);
+
+ $expectedArray = array(
+ 'has_parent' => array(
+ 'query' => $q->toArray(),
+ 'type' => $type,
+ ),
+ );
+
+ $this->assertEquals($expectedArray, $query->toArray());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testSetScope()
+ {
+ $q = new MatchAll();
+
+ $type = 'test';
+
+ $scope = 'foo';
+
+ $query = new HasParent($q, $type);
+ $query->setScope($scope);
+
+ $expectedArray = array(
+ 'has_parent' => array(
+ 'query' => $q->toArray(),
+ 'type' => $type,
+ '_scope' => $scope,
+ ),
+ );
+
+ $this->assertEquals($expectedArray, $query->toArray());
+ }
+
+ /**
+ * @group functional
+ */
+ public function testHasParent()
+ {
+ $index = $this->_createIndex();
+
+ $shopType = $index->getType('shop');
+ $productType = $index->getType('product');
+ $mapping = new Mapping();
+ $mapping->setParent('shop');
+ $productType->setMapping($mapping);
+
+ $shopType->addDocuments(
+ array(
+ new Document('zurich', array('brand' => 'google')),
+ new Document('london', array('brand' => 'apple')),
+ )
+ );
+
+ $doc1 = new Document(1, array('device' => 'chromebook'));
+ $doc1->setParent('zurich');
+
+ $doc2 = new Document(2, array('device' => 'macmini'));
+ $doc2->setParent('london');
+
+ $productType->addDocument($doc1);
+ $productType->addDocument($doc2);
+
+ $index->refresh();
+
+ // All documents
+ $parentQuery = new HasParent(new MatchAll(), $shopType->getName());
+ $search = new Search($index->getClient());
+ $results = $search->search($parentQuery);
+ $this->assertEquals(2, $results->count());
+
+ $match = new Match();
+ $match->setField('brand', 'google');
+
+ $parentQuery = new HasParent($match, $shopType->getName());
+ $search = new Search($index->getClient());
+ $results = $search->search($parentQuery);
+ $this->assertEquals(1, $results->count());
+ $result = $results->current();
+ $data = $result->getData();
+ $this->assertEquals($data['device'], 'chromebook');
+ }
+}