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 --- .../Elastica/Test/Aggregation/CardinalityTest.php | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php') diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php new file mode 100644 index 00000000..7bc383f0 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/CardinalityTest.php @@ -0,0 +1,132 @@ +_createIndex(); + + $index->getType('test')->addDocuments(array( + new Document(1, array('color' => 'blue')), + new Document(2, array('color' => 'blue')), + new Document(3, array('color' => 'red')), + new Document(4, array('color' => 'green')), + )); + + $index->refresh(); + + return $index; + } + + /** + * @group functional + */ + public function testCardinalityAggregation() + { + $agg = new Cardinality('cardinality'); + $agg->setField('color'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('cardinality'); + + $this->assertEquals(3, $results['value']); + } + + /** + * @dataProvider invalidPrecisionThresholdProvider + * @expectedException \InvalidArgumentException + * + * @param $threshold + */ + public function testInvalidPrecisionThreshold($threshold) + { + $agg = new Cardinality('threshold'); + $agg->setPrecisionThreshold($threshold); + } + + /** + * @dataProvider validPrecisionThresholdProvider + * + * @param $threshold + */ + public function testPrecisionThreshold($threshold) + { + $agg = new Cardinality('threshold'); + $agg->setPrecisionThreshold($threshold); + + $this->assertNotNull($agg->getParam('precision_threshold')); + $this->assertInternalType('int', $agg->getParam('precision_threshold')); + } + + public function invalidPrecisionThresholdProvider() + { + return array( + 'string' => array('100'), + 'float' => array(7.8), + 'boolean' => array(true), + 'array' => array(array()), + 'object' => array(new \StdClass()), + ); + } + + public function validPrecisionThresholdProvider() + { + return array( + 'negative-int' => array(-140), + 'zero' => array(0), + 'positive-int' => array(150), + 'more-than-max' => array(40001), + ); + } + + /** + * @dataProvider validRehashProvider + * + * @param bool $rehash + */ + public function testRehash($rehash) + { + $agg = new Cardinality('rehash'); + $agg->setRehash($rehash); + + $this->assertNotNull($agg->getParam('rehash')); + $this->assertInternalType('boolean', $agg->getParam('rehash')); + } + + /** + * @dataProvider invalidRehashProvider + * @expectedException \InvalidArgumentException + * + * @param mixed $rehash + */ + public function testInvalidRehash($rehash) + { + $agg = new Cardinality('rehash'); + $agg->setRehash($rehash); + } + + public function invalidRehashProvider() + { + return array( + 'string' => array('100'), + 'int' => array(100), + 'float' => array(7.8), + 'array' => array(array()), + 'object' => array(new \StdClass()), + ); + } + + public function validRehashProvider() + { + return array( + 'true' => array(true), + 'false' => array(false), + ); + } +} -- cgit v1.2.3-54-g00ecf