diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:47 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:47 -0400 |
commit | 7e85254903c7c0cb49e381f16b18441ea7b058cc (patch) | |
tree | b22328fcf4c8408fc25a7acb73d1cb1089cd82ac /vendor/ruflin/elastica/test/lib/Elastica/Test/Filter | |
parent | 1de335ad3f395ca6861085393ba366a9e3fb4a0d (diff) | |
parent | 1a365e77dfb8825136626202b1df462731b42060 (diff) |
Merge commit '1a365e'
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Filter')
29 files changed, 2495 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/AbstractTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/AbstractTest.php new file mode 100644 index 00000000..1e47819f --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/AbstractTest.php @@ -0,0 +1,69 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Test\Base as BaseTest; + +class AbstractTest extends BaseTest +{ + public function testSetCached() + { + $stubFilter = $this->getStub(); + + $stubFilter->setCached(true); + $arrayFilter = current($stubFilter->toArray()); + $this->assertTrue($arrayFilter['_cache']); + + $stubFilter->setCached(false); + $arrayFilter = current($stubFilter->toArray()); + $this->assertFalse($arrayFilter['_cache']); + } + + public function testSetCachedDefaultValue() + { + $stubFilter = $this->getStub(); + + $stubFilter->setCached(); + $arrayFilter = current($stubFilter->toArray()); + $this->assertTrue($arrayFilter['_cache']); + } + + public function testSetCacheKey() + { + $stubFilter = $this->getStub(); + + $cacheKey = 'myCacheKey'; + + $stubFilter->setCacheKey($cacheKey); + $arrayFilter = current($stubFilter->toArray()); + $this->assertEquals($cacheKey, $arrayFilter['_cache_key']); + } + + /** + * @expectedException \Elastica\Exception\InvalidException + */ + public function testSetCacheKeyEmptyKey() + { + $stubFilter = $this->getStub(); + + $cacheKey = ''; + + $stubFilter->setCacheKey($cacheKey); + } + + public function testSetName() + { + $stubFilter = $this->getStub(); + + $name = 'myFilter'; + + $stubFilter->setName($name); + $arrayFilter = current($stubFilter->toArray()); + $this->assertEquals($name, $arrayFilter['_name']); + } + + private function getStub() + { + return $this->getMockForAbstractClass('Elastica\Filter\AbstractFilter'); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolAndTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolAndTest.php new file mode 100644 index 00000000..672c6c67 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolAndTest.php @@ -0,0 +1,65 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\BoolAnd; +use Elastica\Filter\Ids; +use Elastica\Test\Base as BaseTest; + +class BoolAndTest extends BaseTest +{ + public function testToArray() + { + $and = new BoolAnd(); + $this->assertEquals(array('and' => array()), $and->toArray()); + + $idsFilter = new Ids(); + $idsFilter->setIds(12); + + $and->addFilter($idsFilter); + $and->addFilter($idsFilter); + + $expectedArray = array( + 'and' => array( + $idsFilter->toArray(), + $idsFilter->toArray() + ) + ); + + $this->assertEquals($expectedArray, $and->toArray()); + } + + public function testSetCache() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $doc = new Document(1, array('name' => 'hello world')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'nicolas ruflin')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'ruflin')); + $type->addDocument($doc); + + $and = new BoolAnd(); + + $idsFilter1 = new Ids(); + $idsFilter1->setIds(1); + + $idsFilter2 = new Ids(); + $idsFilter2->setIds(1); + + $and->addFilter($idsFilter1); + $and->addFilter($idsFilter2); + + $index->refresh(); + $and->setCached(true); + + $resultSet = $type->search($and); + + $this->assertEquals(1, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolNotTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolNotTest.php new file mode 100644 index 00000000..adcebf45 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolNotTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Ids; +use Elastica\Filter\BoolNot; +use Elastica\Test\Base as BaseTest; + +class BoolNotTest extends BaseTest +{ + public function testToArray() + { + $idsFilter = new Ids(); + $idsFilter->setIds(12); + $filter = new BoolNot($idsFilter); + + $expectedArray = array( + 'not' => array( + 'filter' => $idsFilter->toArray() + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolOrTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolOrTest.php new file mode 100644 index 00000000..25234a8c --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolOrTest.php @@ -0,0 +1,42 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\AbstractFilter; +use Elastica\Filter\BoolOr; +use Elastica\Filter\Ids; +use Elastica\Test\Base as BaseTest; + +class BoolOrTest extends BaseTest +{ + public function testAddFilter() + { + $filter = $this->getMockForAbstractClass('Elastica\Filter\AbstractFilter'); + $orFilter = new BoolOr(); + $returnValue = $orFilter->addFilter($filter); + $this->assertInstanceOf('Elastica\Filter\BoolOr', $returnValue); + } + + public function testToArray() + { + $orFilter = new BoolOr(); + + $filter1 = new Ids(); + $filter1->setIds('1'); + + $filter2 = new Ids(); + $filter2->setIds('2'); + + $orFilter->addFilter($filter1); + $orFilter->addFilter($filter2); + + $expectedArray = array( + 'or' => array( + $filter1->toArray(), + $filter2->toArray() + ) + ); + + $this->assertEquals($expectedArray, $orFilter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolTest.php new file mode 100644 index 00000000..60eb3a45 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolTest.php @@ -0,0 +1,107 @@ +<?php + +namespace Elastica\Test\Filter; + +use \Elastica\Query; +use Elastica\Filter\Bool; +use Elastica\Filter\Term; +use Elastica\Filter\Ids; +use Elastica\Test\Base as BaseTest; + +class BoolTest extends BaseTest +{ + public function testToArray() + { + $mainBool = new Bool(); + + $idsFilter1 = new Ids(); + $idsFilter1->setIds(1); + $idsFilter2 = new Ids(); + $idsFilter2->setIds(2); + $idsFilter3 = new Ids(); + $idsFilter3->setIds(3); + + $childBool = new Bool(); + $childBool->addShould(array($idsFilter1, $idsFilter2)); + $mainBool->addShould(array($childBool, $idsFilter3)); + + $expectedArray = array( + 'bool' => array( + 'should' => array( + array( + array( + 'bool' => array( + 'should' => array( + array( + $idsFilter1->toArray(), + $idsFilter2->toArray() + ) + ) + ) + ), + $idsFilter3->toArray() + ) + ) + ) + ); + + $this->assertEquals($expectedArray, $mainBool->toArray()); + } + + public function testBoolFilter() + { + $index = $this->_createIndex('bool_filter_test'); + $type = $index->getType('book'); + + //index some test data + $type->addDocument(new \Elastica\Document(1, array('author' => 'Michael Shermer', 'title' => 'The Believing Brain', 'publisher' => 'Robinson'))); + $type->addDocument(new \Elastica\Document(2, array('author' => 'Jared Diamond', 'title' => 'Guns, Germs and Steel', 'publisher' => 'Vintage'))); + $type->addDocument(new \Elastica\Document(3, array('author' => 'Jared Diamond', 'title' => 'Collapse', 'publisher' => 'Penguin'))); + $type->addDocument(new \Elastica\Document(4, array('author' => 'Richard Dawkins', 'title' => 'The Selfish Gene', 'publisher' => 'OUP Oxford'))); + $type->addDocument(new \Elastica\Document(5, array('author' => 'Anthony Burges', 'title' => 'A Clockwork Orange', 'publisher' => 'Penguin'))); + + $index->refresh(); + + //use the terms lookup feature to query for some data + //build query + //must + // should + // author = jared + // author = richard + // must_not + // publisher = penguin + + //construct the query + $query = new Query(); + $mainBoolFilter = new Bool(); + $shouldFilter = new Bool(); + $authorFilter1 = new Term(); + $authorFilter1->setTerm('author', 'jared'); + $authorFilter2 = new Term(); + $authorFilter2->setTerm('author', 'richard'); + $shouldFilter->addShould(array($authorFilter1, $authorFilter2)); + + $mustNotFilter = new Bool(); + $publisherFilter = new Term(); + $publisherFilter->setTerm('publisher', 'penguin'); + $mustNotFilter->addMustNot($publisherFilter); + + $mainBoolFilter->addMust(array($shouldFilter, $mustNotFilter)); + $query->setFilter($mainBoolFilter); + //execute the query + $results = $index->search($query); + + //check the number of results + $this->assertEquals($results->count(), 2, 'Bool filter with child Bool filters: number of results check'); + + //count compare the id's + $ids = array(); + /** @var \Elastica\Result $result **/ + foreach($results as $result){ + $ids[] = $result->getId(); + } + $this->assertEquals($ids, array("2","4"), 'Bool filter with child Bool filters: result ID check'); + + $index->delete(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTests.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTests.php new file mode 100644 index 00000000..9e4f5b67 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTests.php @@ -0,0 +1,31 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Exists; +use Elastica\Test\Base as BaseTest; + +class ExistsTest extends BaseTest +{ + public function testToArray() + { + $field = 'test'; + $filter = new Exists($field); + + $expectedArray = array('exists' => array('field' => $field)); + $this->assertEquals($expectedArray, $filter->toArray()); + } + + public function testSetField() + { + $field = 'test'; + $filter = new Exists($field); + + $this->assertEquals($field, $filter->getParam('field')); + + $newField = 'hello world'; + $this->assertInstanceOf('Elastica\Filter\Exists', $filter->setField($newField)); + + $this->assertEquals($newField, $filter->getParam('field')); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceRangeTest.php new file mode 100644 index 00000000..4c4d2bcc --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceRangeTest.php @@ -0,0 +1,218 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\GeoDistanceRange; +use Elastica\Query; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class GeoDistanceRangeTest extends BaseTest +{ + public function testGeoPoint() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type = $index->getType('test'); + + // Set mapping + $type->setMapping(array('point' => array('type' => 'geo_point'))); + + // Add doc 1 + $doc1 = new Document(1, + array( + 'name' => 'ruflin', + ) + ); + + $doc1->addGeoPoint('point', 17, 19); + $type->addDocument($doc1); + + // Add doc 2 + $doc2 = new Document(2, + array( + 'name' => 'ruflin', + ) + ); + + $doc2->addGeoPoint('point', 30, 40); + $type->addDocument($doc2); + + $index->optimize(); + $index->refresh(); + + // Only one point should be in radius + $query = new Query(); + $geoFilter = new GeoDistanceRange( + 'point', + array('lat' => 30, 'lon' => 40), + array('from' => '0km', 'to' => '2km') + ); + + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + $this->assertEquals(1, $type->search($query)->count()); + + // Both points should be inside + $query = new Query(); + $geoFilter = new GeoDistanceRange( + 'point', + array('lat' => 30, 'lon' => 40), + array('gte' => '0km', 'lte' => '40000km') + ); + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + $index->refresh(); + + $this->assertEquals(2, $type->search($query)->count()); + } + + /** + * @expectedException \Elastica\Exception\InvalidException + */ + public function testInvalidRange() + { + $geoFilter = new GeoDistanceRange( + 'point', + array('lat' => 30, 'lon' => 40), + array('invalid' => '0km', 'lte' => '40000km') + ); + } + + /** + * @dataProvider invalidLocationDataProvider + * @expectedException \Elastica\Exception\InvalidException + */ + public function testInvalidLocation($location) + { + $geoFilter = new GeoDistanceRange( + 'point', + $location, + array('gt' => '0km', 'lte' => '40000km') + ); + } + + /** + * @dataProvider constructDataProvider + */ + public function testConstruct($key, $location, $ranges, $expected) + { + $filter = new GeoDistanceRange($key, $location, $ranges); + + $data = $filter->toArray(); + + $this->assertEquals($expected, $data); + } + + public function invalidLocationDataProvider() + { + return array( + array( + array('lat' => 1.0), + ), + array( + array('lon' => 1.0), + ), + array( + array(), + ), + array( + new \stdClass(), + ), + array( + null, + ), + array( + true, + ), + array( + false, + ) + ); + } + + public function constructDataProvider() + { + return array( + array( + 'location', + 'u09tvqx', + array( + 'from' => '10km', + 'to' => '20km', + ), + array( + 'geo_distance_range' => array( + 'from' => '10km', + 'to' => '20km', + 'location' => 'u09tvqx', + ) + ) + ), + array( + 'location', + 'u09tvqx', + array( + 'to' => '20km', + 'include_upper' => 0, + 'from' => '10km', + 'include_lower' => 1, + ), + array( + 'geo_distance_range' => array( + 'to' => '20km', + 'include_upper' => false, + 'from' => '10km', + 'include_lower' => true, + 'location' => 'u09tvqx', + ) + ) + ), + array( + 'location', + array( + 'lon' => 2.35, + 'lat' => 48.86, + ), + array( + 'lte' => '20km', + 'gt' => '10km', + ), + array( + 'geo_distance_range' => array( + 'lte' => '20km', + 'gt' => '10km', + 'location' => array( + 'lat' => 48.86, + 'lon' => 2.35, + ), + ) + ) + ), + array( + 'location', + array( + 'lat' => 48.86, + 'lon' => 2.35, + ), + array( + 'lt' => '20km', + 'gte' => '10km', + ), + array( + 'geo_distance_range' => array( + 'lt' => '20km', + 'gte' => '10km', + 'location' => array( + 'lat' => 48.86, + 'lon' => 2.35, + ), + ) + ) + ) + ); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceTest.php new file mode 100644 index 00000000..a5049914 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceTest.php @@ -0,0 +1,129 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\GeoDistance; +use Elastica\Query; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class GeoDistanceTest extends BaseTest +{ + public function testGeoPoint() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type = $index->getType('test'); + + // Set mapping + $type->setMapping(array('point' => array('type' => 'geo_point'))); + + // Add doc 1 + $doc1 = new Document(1, + array( + 'name' => 'ruflin', + ) + ); + + $doc1->addGeoPoint('point', 17, 19); + $type->addDocument($doc1); + + // Add doc 2 + $doc2 = new Document(2, + array( + 'name' => 'ruflin', + ) + ); + + $doc2->addGeoPoint('point', 30, 40); + $type->addDocument($doc2); + + $index->optimize(); + $index->refresh(); + + // Only one point should be in radius + $query = new Query(); + $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km'); + + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + $this->assertEquals(1, $type->search($query)->count()); + + // Both points should be inside + $query = new Query(); + $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km'); + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + $index->refresh(); + + $this->assertEquals(2, $type->search($query)->count()); + } + + public function testConstructLatlon() + { + $key = 'location'; + $location = array( + 'lat' => 48.86, + 'lon' => 2.35 + ); + $distance = '10km'; + + $filter = new GeoDistance($key, $location, $distance); + + $expected = array( + 'geo_distance' => array( + $key => $location, + 'distance' => $distance + ) + ); + + $data = $filter->toArray(); + + $this->assertEquals($expected, $data); + } + + public function testConstructGeohash() + { + $key = 'location'; + $location = 'u09tvqx'; + $distance = '10km'; + + $filter = new GeoDistance($key, $location, $distance); + + $expected = array( + 'geo_distance' => array( + $key => $location, + 'distance' => $distance + ) + ); + + $data = $filter->toArray(); + + $this->assertEquals($expected, $data); + } + + public function testSetDistanceType() + { + $filter = new GeoDistance('location', array('lat' => 48.86, 'lon' => 2.35), '10km'); + $distanceType = GeoDistance::DISTANCE_TYPE_ARC; + $filter->setDistanceType($distanceType); + + $data = $filter->toArray(); + + $this->assertEquals($distanceType, $data['geo_distance']['distance_type']); + } + + public function testSetOptimizeBbox() + { + $filter = new GeoDistance('location', array('lat' => 48.86, 'lon' => 2.35), '10km'); + $optimizeBbox = GeoDistance::OPTIMIZE_BBOX_MEMORY; + $filter->setOptimizeBbox($optimizeBbox); + + $data = $filter->toArray(); + + $this->assertEquals($optimizeBbox, $data['geo_distance']['optimize_bbox']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoPolygonTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoPolygonTest.php new file mode 100644 index 00000000..7ebd738c --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoPolygonTest.php @@ -0,0 +1,65 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\GeoPolygon; +use Elastica\Query; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class GeoPolygonTest extends BaseTest +{ + public function testGeoPoint() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type = $index->getType('test'); + + // Set mapping + $type->setMapping(array('location' => array('type' => 'geo_point'))); + + // Add doc 1 + $doc1 = new Document(1, + array( + 'name' => 'ruflin', + ) + ); + + $doc1->addGeoPoint('location', 17, 19); + $type->addDocument($doc1); + + // Add doc 2 + $doc2 = new Document(2, + array( + 'name' => 'ruflin', + ) + ); + + $doc2->addGeoPoint('location', 30, 40); + $type->addDocument($doc2); + + $index->refresh(); + + // Only one point should be in polygon + $query = new Query(); + $points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16)); + $geoFilter = new GeoPolygon('location', $points); + + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + $this->assertEquals(1, $type->search($query)->count()); + + // Both points should be inside + $query = new Query(); + $points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16)); + $geoFilter = new GeoPolygon('location', $points); + + $query = new Query(new MatchAll()); + $query->setFilter($geoFilter); + + $this->assertEquals(2, $type->search($query)->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php new file mode 100644 index 00000000..21afec1a --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php @@ -0,0 +1,90 @@ +<?php + + +namespace Elastica\Test\Filter; + +use Elastica\Filter\AbstractGeoShape; +use Elastica\Filter\GeoShapePreIndexed; +use Elastica\Query\MatchAll; +use Elastica\Query\Filtered; +use Elastica\Test\Base as BaseTest; + +class GeoShapePreIndexedTest extends BaseTest +{ + public function testGeoProvided() + { + $indexName = 'geo_shape_filter_test'; + $index = $this->_createIndex($indexName); + $type = $index->getType('type'); + $otherType = $index->getType('other_type'); + + // create mapping + $mapping = new \Elastica\Type\Mapping($type, array( + 'location' => array( + 'type' => 'geo_shape' + ) + )); + $type->setMapping($mapping); + + // create other type mapping + $otherMapping = new \Elastica\Type\Mapping($type, array( + 'location' => array( + 'type' => 'geo_shape' + ) + )); + $otherType->setMapping($otherMapping); + + // add type docs + $type->addDocument(new \Elastica\Document('1', array( + 'location' => array( + "type" => "envelope", + "coordinates" => array( + array(0.0, 50.0), + array(50.0, 0.0) + ) + ) + ))); + + // add other type docs + $otherType->addDocument(new \Elastica\Document('2', array( + 'location' => array( + "type" => "envelope", + "coordinates" => array( + array(25.0, 75.0), + array(75.0, 25.0) + ) + ) + ))); + + $index->optimize(); + $index->refresh(); + + $gsp = new GeoShapePreIndexed( + 'location', '1', 'type', 'elastica_'.$indexName, 'location' + ); + $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT); + + $expected = array( + 'geo_shape' => array( + 'location' => array( + 'indexed_shape' => array( + 'id' => '1', + 'type' => 'type', + 'index' => 'elastica_'.$indexName, + 'path' => 'location' + ), + 'relation' => $gsp->getRelation() + ) + ) + ); + + $this->assertEquals($expected, $gsp->toArray()); + + $query = new Filtered(new MatchAll(), $gsp); + $results = $index->getType('type')->search($query); + + $this->assertEquals(1, $results->count()); + + $index->delete(); + } +}
\ No newline at end of file diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php new file mode 100644 index 00000000..146150a3 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php @@ -0,0 +1,88 @@ +<?php + + +namespace Elastica\Test\Filter; + +use Elastica\Filter\AbstractGeoShape; +use Elastica\Filter\GeoShapeProvided; +use Elastica\Query\Filtered; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class GeoShapeProvidedTest extends BaseTest +{ + public function testConstructEnvelope() + { + $index = $this->_createIndex('geo_shape_filter_test'); + $type = $index->getType('test'); + + // create mapping + $mapping = new \Elastica\Type\Mapping($type, array( + 'location' => array( + 'type' => 'geo_shape' + ) + )); + $type->setMapping($mapping); + + // add docs + $type->addDocument(new \Elastica\Document(1, array( + 'location' => array( + "type" => "envelope", + "coordinates" => array( + array(-50.0, 50.0), + array(50.0, -50.0) + ) + ) + ))); + + $index->optimize(); + $index->refresh(); + + $envelope = array( + array(25.0, 75.0), + array(75.0, 25.0) + ); + $gsp = new GeoShapeProvided('location', $envelope); + + $expected = array( + 'geo_shape' => array( + 'location' => array( + 'shape' => array( + 'type' => GeoShapeProvided::TYPE_ENVELOPE, + 'coordinates' => $envelope + ), + 'relation' => AbstractGeoShape::RELATION_INTERSECT + ), + ) + ); + + $this->assertEquals($expected, $gsp->toArray()); + + $query = new Filtered(new MatchAll(), $gsp); + $results = $type->search($query); + + $this->assertEquals(1, $results->count()); + + $index->delete(); + } + + public function testConstructPolygon() + { + $polygon = array(array(102.0, 2.0), array(103.0, 2.0), array(103.0, 3.0), array(103.0, 3.0), array(102.0, 2.0)); + $gsp = new GeoShapeProvided('location', $polygon, GeoShapeProvided::TYPE_POLYGON); + + $expected = array( + 'geo_shape' => array( + 'location' => array( + 'shape' => array( + 'type' => GeoShapeProvided::TYPE_POLYGON, + 'coordinates' => $polygon + ), + 'relation' => $gsp->getRelation() + ), + ) + ); + + $this->assertEquals($expected, $gsp->toArray()); + } +}
\ No newline at end of file diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeohashCellTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeohashCellTest.php new file mode 100644 index 00000000..7cb8aef6 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeohashCellTest.php @@ -0,0 +1,60 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Test\Base as BaseTest; +use Elastica\Filter\GeohashCell; + +class GeohashCellTest extends BaseTest +{ + public function testToArray() + { + $filter = new GeohashCell('pin', array('lat' => 37.789018, 'lon' => -122.391506), '50m'); + $expected = array( + 'geohash_cell' => array( + 'pin' => array( + 'lat' => 37.789018, + 'lon' => -122.391506 + ), + 'precision' => '50m', + 'neighbors' => false + ) + ); + $this->assertEquals($expected, $filter->toArray()); + } + + public function testFilter() + { + $index = $this->_createIndex('geohash_filter_test'); + $type = $index->getType('test'); + $mapping = new \Elastica\Type\Mapping($type, array( + 'pin' => array( + 'type' => 'geo_point', + 'geohash' => true, + 'geohash_prefix' => true + ) + )); + $type->setMapping($mapping); + + $type->addDocument(new \Elastica\Document(1, array('pin' => '9q8yyzm0zpw8'))); + $type->addDocument(new \Elastica\Document(2, array('pin' => '9mudgb0yued0'))); + $index->refresh(); + + $filter = new GeohashCell('pin', array('lat' => 32.828326, 'lon' => -117.255854)); + $query = new \Elastica\Query(); + $query->setFilter($filter); + $results = $type->search($query); + + $this->assertEquals(1, $results->count()); + + //test precision parameter + $filter = new GeohashCell('pin', '9', 1); + $query = new \Elastica\Query(); + $query->setFilter($filter); + $results = $type->search($query); + + $this->assertEquals(2, $results->count()); + + $index->delete(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasChildTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasChildTest.php new file mode 100644 index 00000000..8bba8173 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasChildTest.php @@ -0,0 +1,166 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\HasChild; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class HasChildTest extends BaseTest +{ + public function testToArray() + { + $q = new MatchAll(); + + $type = 'test'; + + $filter = new HasChild($q, $type); + + $expectedArray = array( + 'has_child' => array( + 'query' => $q->toArray(), + 'type' => $type + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + public function testSetScope() + { + $q = new MatchAll(); + + $type = 'test'; + + $scope = 'foo'; + + $filter = new HasChild($q, $type); + $filter->setScope($scope); + + $expectedArray = array( + 'has_child' => array( + 'query' => $q->toArray(), + 'type' => $type, + '_scope' => $scope + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + public function testFilterInsideHasChild() + { + $f = new \Elastica\Filter\MatchAll(); + + $type = 'test'; + + $filter = new HasChild($f, $type); + + $expectedArray = array( + 'has_child' => array( + 'filter' => $f->toArray(), + 'type' => $type + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + + } + + public function testFilterInsideHasChildSearch() + { + $index = $this->prepareSearchData(); + + $f = new \Elastica\Filter\Term(); + $f->setTerm('user', 'child1'); + $filter = new HasChild($f, 'child'); + + $searchQuery = new \Elastica\Query(); + $searchQuery->setFilter($filter); + $searchResults = $index->search($searchQuery); + + $this->assertEquals(1, $searchResults->count()); + + $result = $searchResults->current()->getData(); + $expected = array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'); + + $this->assertEquals($expected, $result); + } + + public function testQueryInsideHasChildSearch() + { + $index = $this->prepareSearchData(); + + $f = new \Elastica\Query\Term(); + $f->setTerm('user', 'child1'); + $filter = new HasChild($f, 'child'); + + $searchQuery = new \Elastica\Query(); + $searchQuery->setFilter($filter); + $searchResults = $index->search($searchQuery); + + $this->assertEquals(1, $searchResults->count()); + + $result = $searchResults->current()->getData(); + $expected = array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'); + + $this->assertEquals($expected, $result); + } + + public function testTypeInsideHasChildSearch() + { + $index = $this->prepareSearchData(); + + $f = new \Elastica\Query\Match(); + $f->setField('alt.name', 'testname'); + $filter = new HasChild($f, 'child'); + + $searchQuery = new \Elastica\Query(); + $searchQuery->setFilter($filter); + $searchResults = $index->search($searchQuery); + + $this->assertEquals(1, $searchResults->count()); + + $result = $searchResults->current()->getData(); + $expected = array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'); + + $this->assertEquals($expected, $result); + } + + private function prepareSearchData() + { + $client = $this->_getClient(); + $index = $client->getIndex('has_child_test'); + $index->create(array(), true); + + $parentType = $index->getType('parent'); + + $childType = $index->getType('child'); + $childMapping = new \Elastica\Type\Mapping($childType); + $childMapping->setParent('parent'); + $childMapping->send(); + + $altType = $index->getType('alt'); + $altDoc = new Document('alt1', array('name' => 'altname')); + $altType->addDocument($altDoc); + + $parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com')); + $parentType->addDocument($parent1); + $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com')); + $parentType->addDocument($parent2); + + $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com')); + $child1->setParent('parent1'); + $childType->addDocument($child1); + $child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com')); + $child2->setParent('parent2'); + $childType->addDocument($child2); + $child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname')))); + $child3->setParent('parent2'); + $childType->addDocument($child3); + + $index->refresh(); + return $index; + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasParentTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasParentTest.php new file mode 100644 index 00000000..7998372b --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasParentTest.php @@ -0,0 +1,139 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\HasParent; +use Elastica\Query\MatchAll; +use Elastica\Test\Base as BaseTest; + +class HasParentTest extends BaseTest +{ + public function testToArray() + { + $q = new MatchAll(); + + $type = 'test'; + + $filter = new HasParent($q, $type); + + $expectedArray = array( + 'has_parent' => array( + 'query' => $q->toArray(), + 'type' => $type + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + public function testSetScope() + { + $q = new MatchAll(); + + $type = 'test'; + + $scope = 'foo'; + + $filter = new HasParent($q, $type); + $filter->setScope($scope); + + $expectedArray = array( + 'has_parent' => array( + 'query' => $q->toArray(), + 'type' => $type, + '_scope' => $scope + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + public function testFilterInsideHasParent() + { + $f = new \Elastica\Filter\MatchAll(); + + $type = 'test'; + + $filter = new HasParent($f, $type); + + $expectedArray = array( + 'has_parent' => array( + 'filter' => $f->toArray(), + 'type' => $type + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + + } + + public function testFilterInsideHasParentSearch() + { + $index = $this->prepareSearchData(); + + $f = new \Elastica\Filter\Term(); + $f->setTerm('user', 'parent1'); + $filter = new HasParent($f, 'parent'); + + $searchQuery = new \Elastica\Query(); + $searchQuery->setFilter($filter); + $searchResults = $index->search($searchQuery); + + $this->assertEquals(1, $searchResults->count()); + + $result = $searchResults->current()->getData(); + $expected = array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'); + + $this->assertEquals($expected, $result); + } + + public function testQueryInsideHasParentSearch() + { + $index = $this->prepareSearchData(); + + $f = new \Elastica\Query\Term(); + $f->setTerm('user', 'parent1'); + $filter = new HasParent($f, 'parent'); + + $searchQuery = new \Elastica\Query(); + $searchQuery->setFilter($filter); + $searchResults = $index->search($searchQuery); + + $this->assertEquals(1, $searchResults->count()); + + $result = $searchResults->current()->getData(); + $expected = array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'); + + $this->assertEquals($expected, $result); + } + + private function prepareSearchData() + { + $client = $this->_getClient(); + $index = $client->getIndex('has_parent_test'); + $index->create(array(), true); + + $parentType = $index->getType('parent'); + + $childType = $index->getType('child'); + $childMapping = new \Elastica\Type\Mapping($childType); + $childMapping->setParent('parent'); + $childMapping->send(); + + $parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com')); + $parentType->addDocument($parent1); + $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com')); + $parentType->addDocument($parent2); + + $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com')); + $child1->setParent('parent1'); + $childType->addDocument($child1); + $child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com')); + $child2->setParent('parent2'); + $childType->addDocument($child2); + + $index->refresh(); + return $index; + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IdsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IdsTest.php new file mode 100644 index 00000000..3d6af870 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IdsTest.php @@ -0,0 +1,201 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\Ids; +use Elastica\Filter\Type; +use Elastica\Query; +use Elastica\Test\Base as BaseTest; + +class IdsTest extends BaseTest +{ + protected $_index; + protected $_type; + + public function setUp() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + + $type1 = $index->getType('helloworld1'); + $type2 = $index->getType('helloworld2'); + + // Add documents to first type + for ($i = 1; $i < 100; $i++) { + $doc = new Document($i, array('name' => 'ruflin')); + $type1->addDocument($doc); + } + + // Add documents to second type + for ($i = 1; $i < 100; $i++) { + $doc = new Document($i, array('name' => 'ruflin')); + $type2->addDocument($doc); + } + + // This is a special id that will only be in the second type + $doc = new Document('101', array('name' => 'ruflin')); + $type2->addDocument($doc); + + $index->optimize(); + $index->refresh(); + + $this->_type = $type1; + $this->_index = $index; + } + + public function tearDown() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->delete(); + } + + public function testSetIdsSearchSingle() + { + $filter = new Ids(); + $filter->setIds('1'); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testSetIdsSearchArray() + { + $filter = new Ids(); + $filter->setIds(array(1, 7, 13)); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + $this->assertEquals(3, $resultSet->count()); + } + + public function testAddIdsSearchSingle() + { + $filter = new Ids(); + $filter->addId('39'); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testAddIdsSearchSingleNotInType() + { + $filter = new Ids(); + $filter->addId('39'); + + // Add an ID that is not in the index + $filter->addId(104); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testComboIdsSearchArray() + { + $filter = new Ids(); + $filter->setIds(array(1, 7, 13)); + $filter->addId('39'); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + public function testSetTypeSingleSearchSingle() + { + $filter = new Ids(); + $filter->setIds('1'); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_index->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + public function testSetTypeSingleSearchArray() + { + $filter = new Ids(); + $filter->setIds(array('1', '2')); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_index->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + public function testSetTypeSingleSearchSingleDocInOtherType() + { + $filter = new Ids(); + + // Doc 4 is in the second type... + $filter->setIds('101'); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + // ...therefore 0 results should be returned + $this->assertEquals(0, $resultSet->count()); + } + + public function testSetTypeSingleSearchArrayDocInOtherType() + { + $filter = new Ids(); + + // Doc 4 is in the second type... + $filter->setIds(array('1', '101')); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_type->search($query); + + // ...therefore only 1 result should be returned + $this->assertEquals(1, $resultSet->count()); + } + + public function testSetTypeArraySearchArray() + { + $filter = new Ids(); + $filter->setIds(array('1', '4')); + $filter->setType(array('helloworld1', 'helloworld2')); + + $query = Query::create($filter); + $resultSet = $this->_index->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + public function testSetTypeArraySearchSingle() + { + $filter = new Ids(); + $filter->setIds('4'); + $filter->setType(array('helloworld1', 'helloworld2')); + + $query = Query::create($filter); + $resultSet = $this->_index->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + public function testFilterTypeAndTypeCollision() + { + // This test ensures that Elastica\Type and Elastica\Filter\Type + // do not collide when used together, which at one point + // happened because of a use statement in Elastica\Filter\Ids + // Test goal is to make sure a Fatal Error is not triggered + $filterType = new Type(); + $filter = new Ids(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IndicesTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IndicesTest.php new file mode 100644 index 00000000..b682a5ce --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IndicesTest.php @@ -0,0 +1,93 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\BoolNot; +use Elastica\Filter\Indices; +use Elastica\Filter\Term; +use Elastica\Index; +use Elastica\Query; +use Elastica\Test\Base as BaseTest; + +class IndicesTest extends BaseTest +{ + /** + * @var Index + */ + protected $_index1; + + /** + * @var Index + */ + protected $_index2; + + protected function setUp() + { + parent::setUp(); + $this->_index1 = $this->_createIndex('indices_filter_1'); + $this->_index2 = $this->_createIndex('indices_filter_2'); + $this->_index1->addAlias("indices_filter"); + $this->_index2->addAlias("indices_filter"); + $docs = array( + new Document("1", array("color" => "blue")), + new Document("2", array("color" => "green")), + new Document("3", array("color" => "blue")), + new Document("4", array("color" => "yellow")), + ); + $this->_index1->getType("test")->addDocuments($docs); + $this->_index2->getType("test")->addDocuments($docs); + $this->_index1->refresh(); + $this->_index2->refresh(); + } + + protected function tearDown() + { + $this->_index1->delete(); + $this->_index2->delete(); + parent::tearDown(); + } + + public function testToArray() + { + $expected = array( + "indices" => array( + "indices" => array("index1", "index2"), + "filter" => array( + "term" => array("tag" => "wow") + ), + "no_match_filter" => array( + "term" => array("tag" => "such filter") + ) + ) + ); + $filter = new Indices(new Term(array("tag" => "wow")), array("index1", "index2")); + $filter->setNoMatchFilter(new Term(array("tag" => "such filter"))); + $this->assertEquals($expected, $filter->toArray()); + } + + public function testIndicesFilter() + { + $filter = new Indices(new BoolNot(new Term(array("color" => "blue"))), array($this->_index1->getName())); + $filter->setNoMatchFilter(new BoolNot(new Term(array("color" => "yellow")))); + $query = new Query(); + $query->setFilter($filter); + + // search over the alias + $index = $this->_getClient()->getIndex("indices_filter"); + $results = $index->search($query); + + // ensure that the proper docs have been filtered out for each index + $this->assertEquals(5, $results->count()); + foreach ($results->getResults() as $result) { + $data = $result->getData(); + $color = $data["color"]; + if ($result->getIndex() == $this->_index1->getName()) { + $this->assertNotEquals("blue", $color); + } else { + $this->assertNotEquals("yellow", $color); + } + } + } +} +
\ No newline at end of file diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MatchAllTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MatchAllTest.php new file mode 100644 index 00000000..6696f11d --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MatchAllTest.php @@ -0,0 +1,18 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\MatchAll; +use Elastica\Test\Base as BaseTest; + +class MatchAllTest extends BaseTest +{ + public function testToArray() + { + $filter = new MatchAll(); + + $expectedArray = array('match_all' => new \stdClass()); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MultiTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MultiTest.php new file mode 100644 index 00000000..f6513338 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MultiTest.php @@ -0,0 +1,95 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\AbstractMulti; +use Elastica\Filter\MatchAll; +use Elastica\Test\Base as BaseTest; + +class AbstractMultiTest extends BaseTest +{ + public function testConstruct() + { + $stub = $this->getStub(); + + $this->assertEmpty($stub->getFilters()); + } + + public function testAddFilter() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->addFilter($filter); + + $expected = array( + $filter->toArray() + ); + + $this->assertEquals($expected, $stub->getFilters()); + } + + public function testSetFilters() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->setFilters(array($filter)); + + $expected = array( + $filter->toArray() + ); + + $this->assertEquals($expected, $stub->getFilters()); + } + + public function testToArray() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->addFilter($filter); + + $expected = array( + $stub->getBaseName() => array( + $filter->toArray() + ) + ); + + $this->assertEquals($expected, $stub->toArray()); + } + + public function testToArrayWithParam() + { + $stub = $this->getStub(); + + $stub->setCached(true); + + $filter = new MatchAll(); + $stub->addFilter($filter); + + $expected = array( + $stub->getBaseName() => array( + '_cache' => true, + 'filters' => array( + $filter->toArray() + ) + ) + ); + + $this->assertEquals($expected, $stub->toArray()); + } + + private function getStub() + { + return $this->getMockForAbstractClass('Elastica\Test\Filter\AbstractMultiDebug'); + } +} + +class AbstractMultiDebug extends AbstractMulti +{ + public function getBaseName() + { + return parent::_getBaseName(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php new file mode 100644 index 00000000..12dbb598 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php @@ -0,0 +1,121 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\Nested; +use Elastica\Filter\Terms; +use Elastica\Search; +use Elastica\Type\Mapping; +use Elastica\Test\Base as BaseTest; + +class NestedFilterWithSetFilterTest extends BaseTest +{ + public function setUp() + { + $client = $this->_getClient(); + $index = $client->getIndex('elastica_test_filter_nested_abstract_filter'); + $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_abstract_filter'); + $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->setFilter($q); + + $expectedArray = array( + 'nested' => array( + 'path' => 'hobbies', + 'filter' => 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->setFilter($q); + + $c = $this->_getClient(); + $s = new Search($c); + $i = $c->getIndex('elastica_test_filter_nested_abstract_filter'); + $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->setFilter($q); + + $c = $this->_getClient(); + $s = new Search($c); + $i = $c->getIndex('elastica_test_filter_nested_abstract_filter'); + $s->addIndex($i); + $r = $s->search($f); + $this->assertEquals(2, $r->getTotalHits()); + } +} 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()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NumericRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NumericRangeTest.php new file mode 100644 index 00000000..6cc2de06 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NumericRangeTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\NumericRange; +use Elastica\Test\Base as BaseTest; + +class NumericRangeTest extends BaseTest +{ + public function testAddField() + { + $rangeFilter = new NumericRange(); + $returnValue = $rangeFilter->addField('fieldName', array('to' => 'value')); + $this->assertInstanceOf('Elastica\Filter\NumericRange', $returnValue); + } + + public function testToArray() + { + $filter = new NumericRange(); + + $fromTo = array('from' => 'ra', 'to' => 'ru'); + $filter->addField('name', $fromTo); + + $expectedArray = array( + 'numeric_range' => array( + 'name' => $fromTo + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/PrefixTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/PrefixTest.php new file mode 100644 index 00000000..16362140 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/PrefixTest.php @@ -0,0 +1,149 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\Prefix; +use Elastica\Type\Mapping; +use Elastica\Test\Base as BaseTest; + +class PrefixTest extends BaseTest +{ + public function testToArray() + { + $field = 'name'; + $prefix = 'ruf'; + + $filter = new Prefix($field, $prefix); + + $expectedArray = array( + 'prefix' => array( + $field => $prefix + ) + ); + + $this->assertequals($expectedArray, $filter->toArray()); + } + + public function testDifferentPrefixes() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + + /*$indexParams = array( + 'analysis' => array( + 'analyzer' => array( + 'lw' => array( + 'type' => 'custom', + 'tokenizer' => 'keyword', + 'filter' => array('lowercase') + ) + ), + ) + );*/ + + $index->create(array(), true); + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no', 'index' => 'not_analyzed'), + ) + ); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'Basel-Stadt')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'New York')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'Baden')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Baden Baden')); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'New Orleans')); + $type->addDocument($doc); + + $index->refresh(); + + $query = new Prefix('name', 'Ba'); + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + + // Lower case should not return a result + $query = new Prefix('name', 'ba'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + + $query = new Prefix('name', 'Baden'); + $resultSet = $index->search($query); + $this->assertEquals(2, $resultSet->count()); + + $query = new Prefix('name', 'Baden B'); + $resultSet = $index->search($query); + $this->assertEquals(1, $resultSet->count()); + + $query = new Prefix('name', 'Baden Bas'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + } + + public function testDifferentPrefixesLowercase() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + + $indexParams = array( + 'analysis' => array( + 'analyzer' => array( + 'lw' => array( + 'type' => 'custom', + 'tokenizer' => 'keyword', + 'filter' => array('lowercase') + ) + ), + ) + ); + + $index->create($indexParams, true); + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'lw'), + ) + ); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'Basel-Stadt')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'New York')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'Baden')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Baden Baden')); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'New Orleans')); + $type->addDocument($doc); + + $index->refresh(); + + $query = new Prefix('name', 'ba'); + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + + // Upper case should not return a result + $query = new Prefix('name', 'Ba'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + + $query = new Prefix('name', 'baden'); + $resultSet = $index->search($query); + $this->assertEquals(2, $resultSet->count()); + + $query = new Prefix('name', 'baden b'); + $resultSet = $index->search($query); + $this->assertEquals(1, $resultSet->count()); + + $query = new Prefix('name', 'baden bas'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/QueryTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/QueryTest.php new file mode 100644 index 00000000..0a331098 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/QueryTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Query\QueryString; +use Elastica\Filter\Query; +use Elastica\Test\Base as BaseTest; + +class QueryTest extends BaseTest +{ + public function testSimple() + { + $query = new QueryString('foo bar'); + $filter = new Query($query); + + $expected = array( + 'query' => array( + 'query_string' => array( + 'query' => 'foo bar', + ) + ) + ); + + $this->assertEquals($expected, $filter->toArray()); + } + + public function testExtended() + { + $query = new QueryString('foo bar'); + $filter = new Query($query); + $filter->setCached(true); + + $expected = array( + 'fquery' => array( + 'query' => array( + 'query_string' => array( + 'query' => 'foo bar', + ), + ), + '_cache' => true + ) + ); + + $this->assertEquals($expected, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RangeTest.php new file mode 100644 index 00000000..bf2cb260 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RangeTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Range; +use Elastica\Test\Base as BaseTest; + +class RangeTest extends BaseTest +{ + public function testAddField() + { + $rangeFilter = new Range(); + $returnValue = $rangeFilter->addField('fieldName', array('to' => 'value')); + $this->assertInstanceOf('Elastica\Filter\Range', $returnValue); + } + + public function testToArray() + { + $filter = new Range(); + + $fromTo = array('from' => 'ra', 'to' => 'ru'); + $filter->addField('name', $fromTo); + + $expectedArray = array( + 'range' => array( + 'name' => $fromTo + ) + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RegexpTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RegexpTest.php new file mode 100644 index 00000000..e06064dd --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RegexpTest.php @@ -0,0 +1,137 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Document; +use Elastica\Filter\Regexp; +use Elastica\Type\Mapping; +use Elastica\Test\Base as BaseTest; + +class RegexpTest extends BaseTest +{ + public function testToArray() + { + $field = 'name'; + $regexp = 'ruf'; + + $filter = new Regexp($field, $regexp); + + $expectedArray = array( + 'regexp' => array( + $field => $regexp + ) + ); + + $this->assertequals($expectedArray, $filter->toArray()); + } + + public function testDifferentRegexp() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + + $index->create(array(), true); + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no', 'index' => 'not_analyzed'), + ) + ); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'Basel-Stadt')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'New York')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'Baden')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Baden Baden')); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'New Orleans')); + $type->addDocument($doc); + + $index->refresh(); + + $query = new Regexp('name', 'Ba.*'); + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + + // Lower case should not return a result + $query = new Regexp('name', 'ba.*'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + + $query = new Regexp('name', 'Baden.*'); + $resultSet = $index->search($query); + $this->assertEquals(2, $resultSet->count()); + + $query = new Regexp('name', 'Baden B.*'); + $resultSet = $index->search($query); + $this->assertEquals(1, $resultSet->count()); + + $query = new Regexp('name', 'Baden Bas.*'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + } + + public function testDifferentRegexpLowercase() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + + $indexParams = array( + 'analysis' => array( + 'analyzer' => array( + 'lw' => array( + 'type' => 'custom', + 'tokenizer' => 'keyword', + 'filter' => array('lowercase') + ) + ), + ) + ); + + $index->create($indexParams, true); + $type = $index->getType('test'); + + $mapping = new Mapping($type, array( + 'name' => array('type' => 'string', 'store' => 'no', 'analyzer' => 'lw'), + ) + ); + $type->setMapping($mapping); + + $doc = new Document(1, array('name' => 'Basel-Stadt')); + $type->addDocument($doc); + $doc = new Document(2, array('name' => 'New York')); + $type->addDocument($doc); + $doc = new Document(3, array('name' => 'Baden')); + $type->addDocument($doc); + $doc = new Document(4, array('name' => 'Baden Baden')); + $type->addDocument($doc); + $doc = new Document(5, array('name' => 'New Orleans')); + $type->addDocument($doc); + + $index->refresh(); + + $query = new Regexp('name', 'ba.*'); + $resultSet = $index->search($query); + $this->assertEquals(3, $resultSet->count()); + + // Upper case should not return a result + $query = new Regexp('name', 'Ba.*'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + + $query = new Regexp('name', 'baden.*'); + $resultSet = $index->search($query); + $this->assertEquals(2, $resultSet->count()); + + $query = new Regexp('name', 'baden b.*'); + $resultSet = $index->search($query); + $this->assertEquals(1, $resultSet->count()); + + $query = new Regexp('name', 'baden bas.*'); + $resultSet = $index->search($query); + $this->assertEquals(0, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ScriptTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ScriptTest.php new file mode 100644 index 00000000..65ea628e --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ScriptTest.php @@ -0,0 +1,52 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Script; +use Elastica\Filter\Script as ScriptFilter; +use Elastica\Test\Base as BaseTest; + +class ScriptTest extends BaseTest +{ + public function testToArray() + { + $string = '_score * 2.0'; + + $filter = new ScriptFilter($string); + + $array = $filter->toArray(); + $this->assertInternalType('array', $array); + + $expected = array( + 'script' => array( + 'script' => $string, + ) + ); + $this->assertEquals($expected, $array); + } + + public function testSetScript() + { + $string = '_score * 2.0'; + $params = array( + 'param1' => 'one', + 'param2' => 1, + ); + $lang = 'mvel'; + $script = new Script($string, $params, $lang); + + $filter = new ScriptFilter(); + $filter->setScript($script); + + $array = $filter->toArray(); + + $expected = array( + 'script' => array( + 'script' => $string, + 'params' => $params, + 'lang' => $lang, + ) + ); + $this->assertEquals($expected, $array); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermTest.php new file mode 100644 index 00000000..9a116851 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermTest.php @@ -0,0 +1,23 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Term; +use Elastica\Test\Base as BaseTest; + +class TermTest extends BaseTest +{ + + public function testToArray() + { + $query = new Term(); + $key = 'name'; + $value = 'ruflin'; + $query->setTerm($key, $value); + + $data = $query->toArray(); + + $this->assertInternalType('array', $data['term']); + $this->assertEquals(array($key => $value), $data['term']); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermsTest.php new file mode 100644 index 00000000..96994730 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermsTest.php @@ -0,0 +1,54 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Terms; +use Elastica\Test\Base as BaseTest; + +class TermsTest extends BaseTest +{ + + public function testLookup() + { + $index = $this->_createIndex('terms_filter_test'); + $type1 = $index->getType('musicians'); + $type2 = $index->getType('bands'); + + //index some test data + $type1->addDocument(new \Elastica\Document(1, array('name' => 'robert', 'lastName' => 'plant'))); + $type1->addDocument(new \Elastica\Document(2, array('name' => 'jimmy', 'lastName' => 'page'))); + $type1->addDocument(new \Elastica\Document(3, array('name' => 'john paul', 'lastName' => 'jones'))); + $type1->addDocument(new \Elastica\Document(4, array('name' => 'john', 'lastName' => 'bonham'))); + $type1->addDocument(new \Elastica\Document(5, array('name' => 'jimi', 'lastName' => 'hendrix'))); + + $type2->addDocument(new \Elastica\Document('led zeppelin', array('members' => array('plant', 'page', 'jones', 'bonham')))); + $index->refresh(); + + //use the terms lookup feature to query for some data + $termsFilter = new Terms(); + $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', NULL); + $query = new \Elastica\Query(); + $query->setFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with null index'); + + $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', $index); + $query->setFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with index as object'); + + //Query with index given as string + $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', $index->getName()); + $query->setFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with index as string'); + + //Query with array of options + $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', array('index' => $index, 'cache' => false)); + $query->setFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with options array'); + + $index->delete(); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TypeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TypeTest.php new file mode 100644 index 00000000..fcada826 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TypeTest.php @@ -0,0 +1,27 @@ +<?php + +namespace Elastica\Test\Filter; + +use Elastica\Filter\Type; +use Elastica\Test\Base as BaseTest; + +class TypeTest extends BaseTest +{ + public function testSetType() + { + $typeFilter = new Type(); + $returnValue = $typeFilter->setType('type_name'); + $this->assertInstanceOf('Elastica\Filter\Type', $returnValue); + } + + public function testToArray() + { + $typeFilter = new Type('type_name'); + + $expectedArray = array( + 'type' => array('value' => 'type_name') + ); + + $this->assertEquals($expectedArray, $typeFilter->toArray()); + } +} |