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/lib/Elastica/Test/Filter/AbstractTest.php | 81 +++++++ .../test/lib/Elastica/Test/Filter/BoolAndTest.php | 86 ++++++++ .../lib/Elastica/Test/Filter/BoolFilterTest.php | 200 +++++++++++++++++ .../test/lib/Elastica/Test/Filter/BoolNotTest.php | 27 +++ .../test/lib/Elastica/Test/Filter/BoolOrTest.php | 90 ++++++++ .../test/lib/Elastica/Test/Filter/ExistsTest.php | 36 +++ .../Elastica/Test/Filter/GeoBoundingBoxTest.php | 55 +++++ .../Elastica/Test/Filter/GeoDistanceRangeTest.php | 220 +++++++++++++++++++ .../lib/Elastica/Test/Filter/GeoDistanceTest.php | 141 ++++++++++++ .../lib/Elastica/Test/Filter/GeoPolygonTest.php | 65 ++++++ .../Test/Filter/GeoShapePreIndexedTest.php | 102 +++++++++ .../Elastica/Test/Filter/GeoShapeProvidedTest.php | 103 +++++++++ .../lib/Elastica/Test/Filter/GeohashCellTest.php | 68 ++++++ .../test/lib/Elastica/Test/Filter/HasChildTest.php | 213 ++++++++++++++++++ .../lib/Elastica/Test/Filter/HasParentTest.php | 153 +++++++++++++ .../test/lib/Elastica/Test/Filter/IdsTest.php | 244 +++++++++++++++++++++ .../test/lib/Elastica/Test/Filter/IndicesTest.php | 125 +++++++++++ .../test/lib/Elastica/Test/Filter/LimitTest.php | 34 +++ .../test/lib/Elastica/Test/Filter/MatchAllTest.php | 20 ++ .../test/lib/Elastica/Test/Filter/MissingTest.php | 78 +++++++ .../test/lib/Elastica/Test/Filter/MultiTest.php | 109 +++++++++ .../Test/Filter/NestedFilterWithSetFilterTest.php | 110 ++++++++++ .../test/lib/Elastica/Test/Filter/NestedTest.php | 127 +++++++++++ .../lib/Elastica/Test/Filter/NumericRangeTest.php | 37 ++++ .../test/lib/Elastica/Test/Filter/PrefixTest.php | 138 ++++++++++++ .../test/lib/Elastica/Test/Filter/QueryTest.php | 51 +++++ .../test/lib/Elastica/Test/Filter/RangeTest.php | 61 ++++++ .../test/lib/Elastica/Test/Filter/RegexpTest.php | 162 ++++++++++++++ .../test/lib/Elastica/Test/Filter/ScriptTest.php | 57 +++++ .../test/lib/Elastica/Test/Filter/TermTest.php | 24 ++ .../test/lib/Elastica/Test/Filter/TermsTest.php | 129 +++++++++++ .../test/lib/Elastica/Test/Filter/TypeTest.php | 32 +++ 32 files changed, 3178 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/AbstractTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolAndTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolFilterTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolNotTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolOrTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoBoundingBoxTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceRangeTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoPolygonTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeohashCellTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasChildTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasParentTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IdsTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IndicesTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/LimitTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MatchAllTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MissingTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MultiTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NumericRangeTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/PrefixTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/QueryTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RangeTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RegexpTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ScriptTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermsTest.php create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TypeTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Filter') 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..3ba64dd1 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/AbstractTest.php @@ -0,0 +1,81 @@ +getStub(); + + $stubFilter->setCached(true); + $arrayFilter = current($stubFilter->toArray()); + $this->assertTrue($arrayFilter['_cache']); + + $stubFilter->setCached(false); + $arrayFilter = current($stubFilter->toArray()); + $this->assertFalse($arrayFilter['_cache']); + } + + /** + * @group unit + */ + public function testSetCachedDefaultValue() + { + $stubFilter = $this->getStub(); + + $stubFilter->setCached(); + $arrayFilter = current($stubFilter->toArray()); + $this->assertTrue($arrayFilter['_cache']); + } + + /** + * @group unit + */ + public function testSetCacheKey() + { + $stubFilter = $this->getStub(); + + $cacheKey = 'myCacheKey'; + + $stubFilter->setCacheKey($cacheKey); + $arrayFilter = current($stubFilter->toArray()); + $this->assertEquals($cacheKey, $arrayFilter['_cache_key']); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testSetCacheKeyEmptyKey() + { + $stubFilter = $this->getStub(); + + $cacheKey = ''; + + $stubFilter->setCacheKey($cacheKey); + } + + /** + * @group unit + */ + 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..a8f47633 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolAndTest.php @@ -0,0 +1,86 @@ +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()); + } + + /** + * @group functional + */ + public function testSetCache() + { + $client = $this->_getClient(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $type->addDocuments(array( + new Document(1, array('name' => 'hello world')), + new Document(2, array('name' => 'nicolas ruflin')), + new Document(3, array('name' => 'ruflin')), + )); + + $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()); + } + + /** + * @group unit + */ + public function testConstruct() + { + $ids1 = new Ids('foo', array(1, 2)); + $ids2 = new Ids('bar', array(3, 4)); + + $and1 = new BoolAnd(array($ids1, $ids2)); + + $and2 = new BoolAnd(); + $and2->addFilter($ids1); + $and2->addFilter($ids2); + + $this->assertEquals($and1->toArray(), $and2->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolFilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolFilterTest.php new file mode 100644 index 00000000..ec7728af --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolFilterTest.php @@ -0,0 +1,200 @@ +setIds(1); + $idsFilter2 = new Ids(); + $idsFilter2->setIds(2); + $idsFilter3 = new Ids(); + $idsFilter3->setIds(3); + + $childBool = new BoolFilter(); + $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(), + ), + ), + ), + ); + $out[] = array($mainBool, $expectedArray); + + // case #1 _cache parameter should be supported + $bool = new BoolFilter(); + $terms = new Terms('field1', array('value1', 'value2')); + $termsNot = new Terms('field2', array('value1', 'value2')); + $bool->addMust($terms); + $bool->addMustNot($termsNot); + $bool->setCached(true); + $bool->setCacheKey('my-cache-key'); + $expected = array( + 'bool' => array( + 'must' => array( + $terms->toArray(), + ), + 'must_not' => array( + $termsNot->toArray(), + ), + '_cache' => true, + '_cache_key' => 'my-cache-key', + ), + ); + $out[] = array($bool, $expected); + + return $out; + } + + /** + * @group unit + * @dataProvider getTestToArrayData() + * + * @param Bool $bool + * @param array $expectedArray + */ + public function testToArray(BoolFilter $bool, $expectedArray) + { + $this->assertEquals($expectedArray, $bool->toArray()); + } + + /** + * @group functional + */ + public function testBoolFilter() + { + $index = $this->_createIndex(); + $type = $index->getType('book'); + + //index some test data + $type->addDocuments(array( + new Document(1, array('author' => 'Michael Shermer', 'title' => 'The Believing Brain', 'publisher' => 'Robinson')), + new Document(2, array('author' => 'Jared Diamond', 'title' => 'Guns, Germs and Steel', 'publisher' => 'Vintage')), + new Document(3, array('author' => 'Jared Diamond', 'title' => 'Collapse', 'publisher' => 'Penguin')), + new Document(4, array('author' => 'Richard Dawkins', 'title' => 'The Selfish Gene', 'publisher' => 'OUP Oxford')), + new 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 BoolFilter(); + $shouldFilter = new BoolFilter(); + $authorFilter1 = new Term(); + $authorFilter1->setTerm('author', 'jared'); + $authorFilter2 = new Term(); + $authorFilter2->setTerm('author', 'richard'); + $shouldFilter->addShould(array($authorFilter1, $authorFilter2)); + + $mustNotFilter = new BoolFilter(); + $publisherFilter = new Term(); + $publisherFilter->setTerm('publisher', 'penguin'); + $mustNotFilter->addMustNot($publisherFilter); + + $mainBoolFilter->addMust(array($shouldFilter, $mustNotFilter)); + $query->setPostFilter($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(); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testAddMustInvalidException() + { + $filter = new BoolFilter(); + $filter->addMust('fail!'); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testAddMustNotInvalidException() + { + $filter = new BoolFilter(); + $filter->addMustNot('fail!'); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testAddShouldInvalidException() + { + $filter = new BoolFilter(); + $filter->addShould('fail!'); + } + + /** + * Small unit test to check if also the old object name works. + * + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testOldObject() + { + if (version_compare(phpversion(), 7, '>=')) { + self::markTestSkipped('These objects are not supported in PHP 7'); + } + + $filter = new \Elastica\Filter\Bool(); + $filter->addShould('fail!'); + } +} 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..75461496 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolNotTest.php @@ -0,0 +1,27 @@ +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..6462d1fa --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/BoolOrTest.php @@ -0,0 +1,90 @@ +getMockForAbstractClass('Elastica\Filter\AbstractFilter'); + $orFilter = new BoolOr(); + $returnValue = $orFilter->addFilter($filter); + $this->assertInstanceOf('Elastica\Filter\BoolOr', $returnValue); + } + + /** + * @group unit + */ + 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()); + } + + /** + * @group unit + */ + public function testConstruct() + { + $ids1 = new Ids('foo', array(1, 2)); + $ids2 = new Ids('bar', array(3, 4)); + + $and1 = new BoolOr(array($ids1, $ids2)); + + $and2 = new BoolOr(); + $and2->addFilter($ids1); + $and2->addFilter($ids2); + + $this->assertEquals($and1->toArray(), $and2->toArray()); + } + + /** + * @group functional + */ + public function testOrFilter() + { + $index = $this->_createIndex(); + $type = $index->getType('test'); + + $doc1 = new Document('', array('categoryId' => 1)); + $doc2 = new Document('', array('categoryId' => 2)); + $doc3 = new Document('', array('categoryId' => 3)); + + $type->addDocument($doc1); + $type->addDocument($doc2); + $type->addDocument($doc3); + + $index->refresh(); + + $boolOr = new \Elastica\Filter\BoolOr(); + $boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '1'))); + $boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '2'))); + + $resultSet = $type->search($boolOr); + $this->assertEquals(2, $resultSet->count()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTest.php new file mode 100644 index 00000000..25afa724 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ExistsTest.php @@ -0,0 +1,36 @@ + array('field' => $field)); + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group unit + */ + 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/GeoBoundingBoxTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoBoundingBoxTest.php new file mode 100644 index 00000000..8fdde965 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoBoundingBoxTest.php @@ -0,0 +1,55 @@ +addCoordinates($key, $coords); + $expectedArray = array('top_left' => $coords[0], 'bottom_right' => $coords[1]); + $this->assertEquals($expectedArray, $filter->getParam($key)); + + $returnValue = $filter->addCoordinates($key, $coords); + $this->assertInstanceOf('Elastica\Filter\GeoBoundingBox', $returnValue); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testAddCoordinatesInvalidException() + { + $filter = new GeoBoundingBox('foo', array()); + } + + /** + * @group unit + */ + public function testToArray() + { + $key = 'pin.location'; + $coords = array('40.73, -74.1', '40.01, -71.12'); + $filter = new GeoBoundingBox($key, $coords); + + $expectedArray = array( + 'geo_bounding_box' => array( + $key => array( + 'top_left' => $coords[0], + 'bottom_right' => $coords[1], + ), + ), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} 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..203a45de --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceRangeTest.php @@ -0,0 +1,220 @@ +_createIndex(); + $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->setPostFilter($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->setPostFilter($geoFilter); + $index->refresh(); + + $this->assertEquals(2, $type->search($query)->count()); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testInvalidRange() + { + $geoFilter = new GeoDistanceRange( + 'point', + array('lat' => 30, 'lon' => 40), + array('invalid' => '0km', 'lte' => '40000km') + ); + } + + /** + * @group unit + * @dataProvider invalidLocationDataProvider + * @expectedException \Elastica\Exception\InvalidException + */ + public function testInvalidLocation($location) + { + $geoFilter = new GeoDistanceRange( + 'point', + $location, + array('gt' => '0km', 'lte' => '40000km') + ); + } + + /** + * @group unit + * @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..b61b4adc --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoDistanceTest.php @@ -0,0 +1,141 @@ +_createIndex(); + + $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->setPostFilter($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->setPostFilter($geoFilter); + $index->refresh(); + + $this->assertEquals(2, $type->search($query)->count()); + } + + /** + * @group unit + */ + 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); + } + + /** + * @group unit + */ + 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); + } + + /** + * @group unit + */ + 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']); + } + + /** + * @group unit + */ + 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..b56f73b0 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoPolygonTest.php @@ -0,0 +1,65 @@ +_createIndex(); + + $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->setPostFilter($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->setPostFilter($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..96453527 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php @@ -0,0 +1,102 @@ +_createIndex(); + $indexName = $index->getName(); + $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', $indexName, 'location' + ); + $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT); + + $expected = array( + 'geo_shape' => array( + 'location' => array( + 'indexed_shape' => array( + 'id' => '1', + 'type' => 'type', + 'index' => $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(); + } + + /** + * @group unit + */ + public function testSetRelation() + { + $gsp = new GeoShapePreIndexed('location', '1', 'type', 'indexName', 'location'); + $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT); + $this->assertEquals(AbstractGeoShape::RELATION_INTERSECT, $gsp->getRelation()); + $this->assertInstanceOf('Elastica\Filter\GeoShapePreIndexed', $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT)); + } +} 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..d631e44e --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php @@ -0,0 +1,103 @@ +_createIndex(); + $type = $index->getType('test'); + + // create mapping + $mapping = new Mapping($type, array( + 'location' => array( + 'type' => 'geo_shape', + ), + )); + $type->setMapping($mapping); + + // add docs + $type->addDocument(new 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()); + } + + /** + * @group unit + */ + 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()); + } + + /** + * @group unit + */ + public function testSetRelation() + { + $gsp = new GeoShapeProvided('location', array(array(25.0, 75.0), array(75.0, 25.0))); + $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT); + $this->assertEquals(AbstractGeoShape::RELATION_INTERSECT, $gsp->getRelation()); + $this->assertInstanceOf('Elastica\Filter\GeoShapeProvided', $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT)); + } +} 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..7ef0d04f --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeohashCellTest.php @@ -0,0 +1,68 @@ + 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()); + } + + /** + * @group functional + */ + public function testFilter() + { + $index = $this->_createIndex(); + $type = $index->getType('test'); + $mapping = new Mapping($type, array( + 'pin' => array( + 'type' => 'geo_point', + 'geohash' => true, + 'geohash_prefix' => true, + ), + )); + $type->setMapping($mapping); + + $type->addDocument(new Document(1, array('pin' => '9q8yyzm0zpw8'))); + $type->addDocument(new Document(2, array('pin' => '9mudgb0yued0'))); + $index->refresh(); + + $filter = new GeohashCell('pin', array('lat' => 32.828326, 'lon' => -117.255854)); + $query = new Query(); + $query->setPostFilter($filter); + $results = $type->search($query); + + $this->assertEquals(1, $results->count()); + + //test precision parameter + $filter = new GeohashCell('pin', '9', 1); + $query = new Query(); + $query->setPostFilter($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..00af1def --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasChildTest.php @@ -0,0 +1,213 @@ + array( + 'query' => $q->toArray(), + 'type' => $type, + ), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + public function testSetType() + { + $index = $this->prepareSearchData(); + + $filter = new HasChild(new MatchAll(), 'type_name'); + $this->assertEquals('type_name', $filter->getParam('type')); + + $filter->setType('new_type_name'); + $this->assertEquals('new_type_name', $filter->getParam('type')); + + $type = $index->getType('foo'); + $filter = new HasChild(new MatchAll(), $type); + $this->assertEquals('foo', $filter->getParam('type')); + + $type = $index->getType('bar'); + $filter->setType($type); + $this->assertEquals('bar', $filter->getParam('type')); + + $returnValue = $filter->setType('last'); + $this->assertInstanceOf('Elastica\Filter\HasChild', $returnValue); + } + + /** + * @group unit + */ + public function testSetMinimumChildrenCount() + { + $query = new MatchAll(); + $filter = new HasChild($query, 'test'); + + $filter->setMinimumChildrenCount(2); + $this->assertEquals(2, $filter->getParam('min_children')); + + $returnValue = $filter->setMinimumChildrenCount(2); + $this->assertInstanceOf('Elastica\Filter\HasChild', $returnValue); + } + + /** + * @group unit + */ + public function testSetMaximumChildrenCount() + { + $query = new MatchAll(); + $filter = new HasChild($query, 'test'); + + $filter->setMaximumChildrenCount(10); + $this->assertEquals(10, $filter->getParam('max_children')); + + $returnValue = $filter->setMaximumChildrenCount(10); + $this->assertInstanceOf('Elastica\Filter\HasChild', $returnValue); + } + + /** + * @group unit + */ + 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()); + } + + /** + * @group functional + */ + 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->setPostFilter($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); + } + + /** + * @group functional + */ + 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->setPostFilter($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); + } + + /** + * @group functional + */ + 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->setPostFilter($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..50143dda --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/HasParentTest.php @@ -0,0 +1,153 @@ + array( + 'query' => $q->toArray(), + 'type' => $type, + ), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + public function testSetType() + { + $index = $this->prepareSearchData(); + + $filter = new HasParent(new MatchAll(), 'type_name'); + $this->assertEquals('type_name', $filter->getParam('type')); + + $filter->setType('new_type_name'); + $this->assertEquals('new_type_name', $filter->getParam('type')); + + $type = $index->getType('foo'); + $filter = new HasParent(new MatchAll(), $type); + $this->assertEquals('foo', $filter->getParam('type')); + + $type = $index->getType('bar'); + $filter->setType($type); + $this->assertEquals('bar', $filter->getParam('type')); + + $returnValue = $filter->setType('last'); + $this->assertInstanceOf('Elastica\Filter\HasParent', $returnValue); + } + + /** + * @group unit + */ + 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()); + } + + /** + * @group functional + */ + 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->setPostFilter($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); + } + + /** + * @group functional + */ + 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->setPostFilter($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..8395f39a --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IdsTest.php @@ -0,0 +1,244 @@ +_createIndex(); + + // Add documents to first type + $docs = array(); + for ($i = 1; $i < 100; $i++) { + $docs[] = new Document($i, array('name' => 'ruflin')); + } + $index->getType('helloworld1')->addDocuments($docs); + + // Add documents to second type + $docs = array(); + for ($i = 1; $i < 100; $i++) { + $docs[] = new Document($i, array('name' => 'ruflin')); + } + // This is a special id that will only be in the second type + $docs[] = new Document(101, array('name' => 'ruflin')); + $index->getType('helloworld2')->addDocuments($docs); + + $index->optimize(); + $index->refresh(); + + return $index; + } + + protected function _getTypeForTest() + { + return $this->_getIndexForTest()->getType('helloworld1'); + } + + /** + * @group functional + */ + public function testSetIdsSearchSingle() + { + $filter = new Ids(); + $filter->setIds('1'); + + $query = Query::create($filter); + $resultSet = $this->_getTypeForTest()->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ + public function testSetIdsSearchArray() + { + $filter = new Ids(); + $filter->setIds(array(1, 7, 13)); + + $query = Query::create($filter); + $resultSet = $this->_getTypeForTest()->search($query); + + $this->assertEquals(3, $resultSet->count()); + } + + /** + * @group functional + */ + public function testAddIdsSearchSingle() + { + $filter = new Ids(); + $filter->addId('39'); + + $query = Query::create($filter); + $resultSet = $this->_getTypeForTest()->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ + 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->_getTypeForTest()->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ + public function testComboIdsSearchArray() + { + $filter = new Ids(); + $filter->setIds(array(1, 7, 13)); + $filter->addId('39'); + + $query = Query::create($filter); + $resultSet = $this->_getTypeForTest()->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + /** + * @group functional + */ + public function testSetTypeSingleSearchSingle() + { + $filter = new Ids(); + $filter->setIds('1'); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_getIndexForTest()->search($query); + + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ + public function testSetTypeSingleSearchArray() + { + $filter = new Ids(); + $filter->setIds(array('1', '2')); + $filter->setType('helloworld1'); + + $query = Query::create($filter); + $resultSet = $this->_getIndexForTest()->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + /** + * @group functional + */ + 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->_getTypeForTest()->search($query); + + // ...therefore 0 results should be returned + $this->assertEquals(0, $resultSet->count()); + } + + /** + * @group functional + */ + 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->_getTypeForTest()->search($query); + + // ...therefore only 1 result should be returned + $this->assertEquals(1, $resultSet->count()); + } + + /** + * @group functional + */ + public function testSetTypeArraySearchArray() + { + $filter = new Ids(); + $filter->setIds(array('1', '4')); + $filter->setType(array('helloworld1', 'helloworld2')); + + $query = Query::create($filter); + $resultSet = $this->_getIndexForTest()->search($query); + + $this->assertEquals(4, $resultSet->count()); + } + + /** + * @group functional + */ + public function testSetTypeArraySearchSingle() + { + $filter = new Ids(); + $filter->setIds('4'); + $filter->setType(array('helloworld1', 'helloworld2')); + + $query = Query::create($filter); + $resultSet = $this->_getIndexForTest()->search($query); + + $this->assertEquals(2, $resultSet->count()); + } + + /** + * @group unit + */ + 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(); + } + + /** + * @group unit + */ + public function testAddType() + { + $type = $this->_getClient()->getIndex('indexname')->getType('typename'); + + $filter = new Ids(); + + $filter->addType('foo'); + $this->assertEquals(array('foo'), $filter->getParam('type')); + + $filter->addType($type); + $this->assertEquals(array('foo', $type->getName()), $filter->getParam('type')); + + $returnValue = $filter->addType('bar'); + $this->assertInstanceOf('Elastica\Filter\Ids', $returnValue); + } +} 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..bc78aa6b --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/IndicesTest.php @@ -0,0 +1,125 @@ + 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()); + } + + /** + * @group functional + */ + public function testIndicesFilter() + { + $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')), + ); + + $index1 = $this->_createIndex(); + $index1->addAlias('indices_filter'); + $index1->getType('test')->addDocuments($docs); + $index1->refresh(); + + $index2 = $this->_createIndex(); + $index2->addAlias('indices_filter'); + $index2->getType('test')->addDocuments($docs); + $index2->refresh(); + + $filter = new Indices(new BoolNot(new Term(array('color' => 'blue'))), array($index1->getName())); + $filter->setNoMatchFilter(new BoolNot(new Term(array('color' => 'yellow')))); + $query = new Query(); + $query->setPostFilter($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() === $index1->getName()) { + $this->assertNotEquals('blue', $color); + } else { + $this->assertNotEquals('yellow', $color); + } + } + } + + /** + * @group unit + */ + public function testSetIndices() + { + $client = $this->_getClient(); + $index1 = $client->getIndex('index1'); + $index2 = $client->getIndex('index2'); + + $indices = array('one', 'two'); + $filter = new Indices(new Term(array('color' => 'blue')), $indices); + $this->assertEquals($indices, $filter->getParam('indices')); + + $indices[] = 'three'; + $filter->setIndices($indices); + $this->assertEquals($indices, $filter->getParam('indices')); + + $filter->setIndices(array($index1, $index2)); + $expected = array($index1->getName(), $index2->getName()); + $this->assertEquals($expected, $filter->getParam('indices')); + + $returnValue = $filter->setIndices($indices); + $this->assertInstanceOf('Elastica\Filter\Indices', $returnValue); + } + + /** + * @group unit + */ + public function testAddIndex() + { + $client = $this->_getClient(); + $index = $client->getIndex('someindex'); + + $filter = new Indices(new Term(array('color' => 'blue')), array()); + + $filter->addIndex($index); + $expected = array($index->getName()); + $this->assertEquals($expected, $filter->getParam('indices')); + + $filter->addIndex('foo'); + $expected = array($index->getName(), 'foo'); + $this->assertEquals($expected, $filter->getParam('indices')); + + $returnValue = $filter->addIndex('bar'); + $this->assertInstanceOf('Elastica\Filter\Indices', $returnValue); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/LimitTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/LimitTest.php new file mode 100644 index 00000000..0cdfee39 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/LimitTest.php @@ -0,0 +1,34 @@ +assertEquals(10, $filter->getParam('value')); + + $this->assertInstanceOf('Elastica\Filter\Limit', $filter->setLimit(20)); + $this->assertEquals(20, $filter->getParam('value')); + } + + /** + * @group unit + */ + public function testToArray() + { + $filter = new Limit(15); + + $expectedArray = array( + 'limit' => array('value' => 15), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} 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..9bfd511f --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MatchAllTest.php @@ -0,0 +1,20 @@ + new \stdClass()); + + $this->assertEquals($expectedArray, $filter->toArray()); + } +} diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MissingTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MissingTest.php new file mode 100644 index 00000000..f87df790 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MissingTest.php @@ -0,0 +1,78 @@ + array('field' => 'field_name')); + $this->assertEquals($expectedArray, $filter->toArray()); + + $filter = new Missing('field_name'); + $filter->setExistence(true); + $expectedArray = array('missing' => array('field' => 'field_name', 'existence' => true)); + $this->assertEquals($expectedArray, $filter->toArray()); + + $filter = new Missing('field_name'); + $filter->setNullValue(true); + $expectedArray = array('missing' => array('field' => 'field_name', 'null_value' => true)); + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group unit + */ + public function testSetField() + { + $filter = new Missing('field_name'); + + $this->assertEquals('field_name', $filter->getParam('field')); + + $filter->setField('new_field_name'); + $this->assertEquals('new_field_name', $filter->getParam('field')); + + $returnValue = $filter->setField('very_new_field_name'); + $this->assertInstanceOf('Elastica\Filter\Missing', $returnValue); + } + + /** + * @group unit + */ + public function testSetExistence() + { + $filter = new Missing('field_name'); + + $filter->setExistence(true); + $this->assertTrue($filter->getParam('existence')); + + $filter->setExistence(false); + $this->assertFalse($filter->getParam('existence')); + + $returnValue = $filter->setExistence(true); + $this->assertInstanceOf('Elastica\Filter\Missing', $returnValue); + } + + /** + * @group unit + */ + public function testSetNullValue() + { + $filter = new Missing('field_name'); + + $filter->setNullValue(true); + $this->assertTrue($filter->getParam('null_value')); + + $filter->setNullValue(false); + $this->assertFalse($filter->getParam('null_value')); + + $returnValue = $filter->setNullValue(true); + $this->assertInstanceOf('Elastica\Filter\Missing', $returnValue); + } +} 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..cc8a56e8 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/MultiTest.php @@ -0,0 +1,109 @@ +getStub(); + + $this->assertEmpty($stub->getFilters()); + } + + /** + * @group unit + */ + public function testAddFilter() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->addFilter($filter); + + $expected = array( + $filter->toArray(), + ); + + $this->assertEquals($expected, $stub->getFilters()); + } + + /** + * @group unit + */ + public function testSetFilters() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->setFilters(array($filter)); + + $expected = array( + $filter->toArray(), + ); + + $this->assertEquals($expected, $stub->getFilters()); + } + + /** + * @group unit + */ + public function testToArray() + { + $stub = $this->getStub(); + + $filter = new MatchAll(); + $stub->addFilter($filter); + + $expected = array( + $stub->getBaseName() => array( + $filter->toArray(), + ), + ); + + $this->assertEquals($expected, $stub->toArray()); + } + + /** + * @group unit + */ + 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..96a49a77 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php @@ -0,0 +1,110 @@ +_createIndex(); + $type = $index->getType('user'); + + $type->setMapping(new Mapping(null, 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->addDocuments(array( + new Document(1, array( + 'firstname' => 'Nicolas', + 'lastname' => 'Ruflin', + 'hobbies' => array( + array('hobby' => 'opensource'), + ), + )), + new Document(2, array( + 'firstname' => 'Nicolas', + 'lastname' => 'Ippolito', + 'hobbies' => array( + array('hobby' => 'opensource'), + array('hobby' => 'guitar'), + ), + )), + )); + + $index->refresh(); + + return $index; + } + + /** + * @group unit + */ + public function testToArray() + { + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setFilter($query); + + $expectedArray = array( + 'nested' => array( + 'path' => 'hobbies', + 'filter' => array('terms' => array( + 'hobby' => array('guitar'), + )), + ), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + public function testShouldReturnTheRightNumberOfResult() + { + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setFilter($query); + + $client = $this->_getClient(); + $search = new Search($client); + $index = $this->_getIndexForTest(); + $search->addIndex($index); + $resultSet = $search->search($filter); + + $this->assertEquals(1, $resultSet->getTotalHits()); + + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('opensource')); + $filter->setPath('hobbies'); + $filter->setFilter($query); + + $client = $this->_getClient(); + $search = new Search($client); + $index = $this->_getIndexForTest(); + $search->addIndex($index); + $resultSet = $search->search($filter); + $this->assertEquals(2, $resultSet->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..8eb42d37 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedTest.php @@ -0,0 +1,127 @@ +_createIndex('elastica_test_filter_nested'); + $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); + + $response = $type->addDocuments(array( + new Document(1, + array( + 'firstname' => 'Nicolas', + 'lastname' => 'Ruflin', + 'hobbies' => array( + array('hobby' => 'opensource'), + ), + ) + ), + new Document(2, + array( + 'firstname' => 'Nicolas', + 'lastname' => 'Ippolito', + 'hobbies' => array( + array('hobby' => 'opensource'), + array('hobby' => 'guitar'), + ), + ) + ), + )); + + $index->refresh(); + + return $index; + } + + /** + * @group unit + */ + public function testToArray() + { + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setQuery($query); + + $expectedArray = array( + 'nested' => array( + 'path' => 'hobbies', + 'query' => array('terms' => array( + 'hobby' => array('guitar'), + )), + ), + ); + + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + public function testShouldReturnTheRightNumberOfResult() + { + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setQuery($query); + + $search = new Search($this->_getClient()); + $search->addIndex($this->_getIndexForTest()); + $resultSet = $search->search($filter); + $this->assertEquals(1, $resultSet->getTotalHits()); + + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('opensource')); + $filter->setPath('hobbies'); + $filter->setQuery($query); + + $search = new Search($this->_getClient()); + $search->addIndex($this->_getIndexForTest()); + $resultSet = $search->search($filter); + $this->assertEquals(2, $resultSet->getTotalHits()); + } + + /** + * @group unit + */ + public function testSetJoin() + { + $filter = new Nested(); + + $this->assertTrue($filter->setJoin(true)->getParam('join')); + + $this->assertFalse($filter->setJoin(false)->getParam('join')); + + $returnValue = $filter->setJoin(true); + $this->assertInstanceOf('Elastica\Filter\Nested', $returnValue); + } +} 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..590b5137 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NumericRangeTest.php @@ -0,0 +1,37 @@ +addField('fieldName', array('to' => 'value')); + $this->assertInstanceOf('Elastica\Filter\NumericRange', $returnValue); + } + + /** + * @group unit + */ + 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..aab37615 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/PrefixTest.php @@ -0,0 +1,138 @@ + array( + $field => $prefix, + ), + ); + + $this->assertequals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + public function testDifferentPrefixes() + { + $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); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + new Document(5, array('name' => 'New Orleans')), + )); + + $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()); + } + + /** + * @group functional + */ + 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); + + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + new Document(5, array('name' => 'New Orleans')), + )); + + $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..23754510 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/QueryTest.php @@ -0,0 +1,51 @@ + array( + 'query_string' => array( + 'query' => 'foo bar', + ), + ), + ); + + $this->assertEquals($expected, $filter->toArray()); + } + + /** + * @group unit + */ + 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..b7cad3ac --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RangeTest.php @@ -0,0 +1,61 @@ +addField('fieldName', array('to' => 'value')); + $this->assertInstanceOf('Elastica\Filter\Range', $returnValue); + } + + /** + * @group unit + */ + public function testToArray() + { + $field = 'field_name'; + $range = array('gte' => 10, 'lte' => 99); + + $filter = new Range(); + $filter->addField($field, $range); + $expectedArray = array('range' => array($field => $range)); + $this->assertEquals($expectedArray, $filter->toArray()); + } + + /** + * @group unit + */ + public function testSetExecution() + { + $field = 'field_name'; + $range = array('gte' => 10, 'lte' => 99); + $filter = new Range('field_name', $range); + + $filter->setExecution('fielddata'); + $this->assertEquals('fielddata', $filter->getParam('execution')); + + $returnValue = $filter->setExecution('index'); + $this->assertInstanceOf('Elastica\Filter\Range', $returnValue); + } + + /** + * Tests that parent fields are not overwritten by the toArray method. + * + * @group unit + */ + public function testSetCachedNotOverwritten() + { + $filter = new Range('field_name', array()); + $filter->setCached(true); + $array = $filter->toArray(); + $this->assertTrue($array['range']['_cache']); + } +} 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..6e3a0395 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/RegexpTest.php @@ -0,0 +1,162 @@ + array( + $field => $regexp, + ), + ); + + $this->assertequals($expectedArray, $filter->toArray()); + } + + /** + * @group unit + */ + public function testToArrayWithOptions() + { + $field = 'name'; + $regexp = 'ruf'; + $options = array( + 'flags' => 'ALL', + ); + + $filter = new Regexp($field, $regexp, $options); + + $expectedArray = array( + 'regexp' => array( + $field => array( + 'value' => $regexp, + 'flags' => 'ALL', + ), + ), + ); + + $this->assertequals($expectedArray, $filter->toArray()); + } + + /** + * @group functional + */ + 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); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + new Document(5, array('name' => 'New Orleans')), + )); + + $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()); + } + + /** + * @group functional + */ + 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); + $type->addDocuments(array( + new Document(1, array('name' => 'Basel-Stadt')), + new Document(2, array('name' => 'New York')), + new Document(3, array('name' => 'Baden')), + new Document(4, array('name' => 'Baden Baden')), + new Document(5, array('name' => 'New Orleans')), + )); + + $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..fdec0381 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/ScriptTest.php @@ -0,0 +1,57 @@ +toArray(); + $this->assertInternalType('array', $array); + + $expected = array( + 'script' => array( + 'script' => $string, + ), + ); + $this->assertEquals($expected, $array); + } + + /** + * @group unit + */ + 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..9c8f5a2a --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermTest.php @@ -0,0 +1,24 @@ +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..bb37ba96 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TermsTest.php @@ -0,0 +1,129 @@ +_createIndex(); + $type1 = $index->getType('musicians'); + $type2 = $index->getType('bands'); + + //index some test data + $type1->addDocuments(array( + new Document(1, array('name' => 'robert', 'lastName' => 'plant')), + new Document(2, array('name' => 'jimmy', 'lastName' => 'page')), + new Document(3, array('name' => 'john paul', 'lastName' => 'jones')), + new Document(4, array('name' => 'john', 'lastName' => 'bonham')), + new Document(5, array('name' => 'jimi', 'lastName' => 'hendrix')), + )); + + $type2->addDocument(new 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 Query(); + $query->setPostFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with null index'); + + $termsFilter->setLookup('lastName', $type2, 'led zeppelin', 'members', $index); + $query->setPostFilter($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->setPostFilter($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->setPostFilter($termsFilter); + $results = $index->search($query); + $this->assertEquals($results->count(), 4, 'Terms lookup with options array'); + + $index->delete(); + } + + /** + * @group unit + */ + public function testSetExecution() + { + $filter = new Terms('color', array('blue', 'green')); + + $filter->setExecution('bool'); + $this->assertEquals('bool', $filter->getParam('execution')); + + $returnValue = $filter->setExecution('bool'); + $this->assertInstanceOf('Elastica\Filter\Terms', $returnValue); + } + + /** + * @group unit + */ + public function testSetTerms() + { + $field = 'color'; + $terms = array('blue', 'green'); + + $filter = new Terms(); + $filter->setTerms($field, $terms); + $expected = array('terms' => array($field => $terms)); + $this->assertEquals($expected, $filter->toArray()); + + $returnValue = $filter->setTerms($field, $terms); + $this->assertInstanceOf('Elastica\Filter\Terms', $returnValue); + } + + /** + * @group unit + */ + public function testAddTerm() + { + $filter = new Terms('color', array('blue')); + + $filter->addTerm('green'); + $expected = array('terms' => array('color' => array('blue', 'green'))); + $this->assertEquals($expected, $filter->toArray()); + + $returnValue = $filter->addTerm('cyan'); + $this->assertInstanceOf('Elastica\Filter\Terms', $returnValue); + } + + /** + * @group unit + */ + public function testToArray() + { + $filter = new Terms('color', array()); + $expected = array('terms' => array('color' => array())); + $this->assertEquals($expected, $filter->toArray()); + + $filter = new Terms('color', array('cyan')); + $expected = array('terms' => array('color' => array('cyan'))); + $this->assertEquals($expected, $filter->toArray()); + } + + /** + * @group unit + * @expectedException \Elastica\Exception\InvalidException + */ + public function testToArrayInvalidException() + { + $filter = new Terms(); + $filter->toArray(); + } +} 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..8da19273 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/TypeTest.php @@ -0,0 +1,32 @@ +setType('type_name'); + $this->assertInstanceOf('Elastica\Filter\Type', $returnValue); + } + + /** + * @group unit + */ + public function testToArray() + { + $typeFilter = new Type('type_name'); + + $expectedArray = array( + 'type' => array('value' => 'type_name'), + ); + + $this->assertEquals($expectedArray, $typeFilter->toArray()); + } +} -- cgit v1.2.3-54-g00ecf