summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
commit7e85254903c7c0cb49e381f16b18441ea7b058cc (patch)
treeb22328fcf4c8408fc25a7acb73d1cb1089cd82ac /vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php
parent1de335ad3f395ca6861085393ba366a9e3fb4a0d (diff)
parent1a365e77dfb8825136626202b1df462731b42060 (diff)
Merge commit '1a365e'
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php121
1 files changed, 121 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php
new file mode 100644
index 00000000..8d0d2004
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php
@@ -0,0 +1,121 @@
+<?php
+
+namespace Elastica\Test\Filter;
+
+use Elastica\Document;
+use Elastica\Filter\Nested;
+use Elastica\Query\Terms;
+use Elastica\Search;
+use Elastica\Type\Mapping;
+use Elastica\Test\Base as BaseTest;
+
+class NestedTest extends BaseTest
+{
+ public function setUp()
+ {
+ $client = $this->_getClient();
+ $index = $client->getIndex('elastica_test_filter_nested');
+ $index->create(array(), true);
+ $type = $index->getType('user');
+ $mapping = new Mapping();
+ $mapping->setProperties(
+ array(
+ 'firstname' => array('type' => 'string', 'store' => 'yes'),
+ // default is store => no expected
+ 'lastname' => array('type' => 'string'),
+ 'hobbies' => array(
+ 'type' => 'nested',
+ 'include_in_parent' => true,
+ 'properties' => array('hobby' => array('type' => 'string'))
+ )
+ )
+ );
+ $type->setMapping($mapping);
+
+ // Adds a list of documents with _bulk upload to the index
+ $docs = array();
+ $docs[] = new Document(1,
+ array(
+ 'firstname' => 'Nicolas',
+ 'lastname' => 'Ruflin',
+ 'hobbies' => array(
+ array('hobby' => 'opensource')
+ )
+ )
+ );
+ $docs[] = new Document(2,
+ array(
+ 'firstname' => 'Nicolas',
+ 'lastname' => 'Ippolito',
+ 'hobbies' => array(
+ array('hobby' => 'opensource'),
+ array('hobby' => 'guitar'),
+ )
+ )
+ );
+ $response = $type->addDocuments($docs);
+
+ // Refresh index
+ $index->refresh();
+ }
+
+ public function tearDown()
+ {
+ $client = $this->_getClient();
+ $index = $client->getIndex('elastica_test_filter_nested');
+ $index->delete();
+ }
+
+ public function testToArray()
+ {
+ $f = new Nested();
+ $this->assertEquals(array('nested' => array()), $f->toArray());
+ $q = new Terms();
+ $q->setTerms('hobby', array('guitar'));
+ $f->setPath('hobbies');
+ $f->setQuery($q);
+
+ $expectedArray = array(
+ 'nested' => array(
+ 'path' => 'hobbies',
+ 'query' => array('terms' => array(
+ 'hobby' => array('guitar')
+ ))
+ )
+ );
+
+ $this->assertEquals($expectedArray, $f->toArray());
+ }
+
+ public function testShouldReturnTheRightNumberOfResult()
+ {
+ $f = new Nested();
+ $this->assertEquals(array('nested' => array()), $f->toArray());
+ $q = new Terms();
+ $q->setTerms('hobby', array('guitar'));
+ $f->setPath('hobbies');
+ $f->setQuery($q);
+
+ $c = $this->_getClient();
+ $s = new Search($c);
+ $i = $c->getIndex('elastica_test_filter_nested');
+ $s->addIndex($i);
+ $r = $s->search($f);
+
+ $this->assertEquals(1, $r->getTotalHits());
+
+ $f = new Nested();
+ $this->assertEquals(array('nested' => array()), $f->toArray());
+ $q = new Terms();
+ $q->setTerms('hobby', array('opensource'));
+ $f->setPath('hobbies');
+ $f->setQuery($q);
+
+ $c = $this->_getClient();
+ $s = new Search($c);
+ $i = $c->getIndex('elastica_test_filter_nested');
+ $s->addIndex($i);
+ $r = $s->search($f);
+ $this->assertEquals(2, $r->getTotalHits());
+ }
+}