diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php new file mode 100644 index 00000000..bf32b251 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ScriptTest.php @@ -0,0 +1,87 @@ +<?php +namespace Elastica\Test\Aggregation; + +use Elastica\Aggregation\Sum; +use Elastica\Document; +use Elastica\Query; +use Elastica\Script; + +class ScriptTest extends BaseAggregationTest +{ + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + + $index->getType('test')->addDocuments(array( + new Document('1', array('price' => 5)), + new Document('2', array('price' => 8)), + new Document('3', array('price' => 1)), + new Document('4', array('price' => 3)), + )); + + $index->refresh(); + + return $index; + } + + /** + * @group functional + */ + public function testAggregationScript() + { + $agg = new Sum('sum'); + // x = (0..1) is groovy-specific syntax, to see if lang is recognized + $script = new Script("x = (0..1); return doc['price'].value", null, 'groovy'); + $agg->setScript($script); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('sum'); + + $this->assertEquals(5 + 8 + 1 + 3, $results['value']); + } + + /** + * @group functional + */ + public function testAggregationScriptAsString() + { + $agg = new Sum('sum'); + $agg->setScript("doc['price'].value"); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('sum'); + + $this->assertEquals(5 + 8 + 1 + 3, $results['value']); + } + + /** + * @group unit + */ + public function testSetScript() + { + $aggregation = 'sum'; + $string = "doc['price'].value"; + $params = array( + 'param1' => 'one', + 'param2' => 1, + ); + $lang = 'groovy'; + + $agg = new Sum($aggregation); + $script = new Script($string, $params, $lang); + $agg->setScript($script); + + $array = $agg->toArray(); + + $expected = array( + $aggregation => array( + 'script' => $string, + 'params' => $params, + 'lang' => $lang, + ), + ); + $this->assertEquals($expected, $array); + } +} |