diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-18 06:00:00 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-18 06:00:00 +0100 |
commit | 15e69f7b20b6596b9148030acce5b59993b95a45 (patch) | |
tree | 7b828b8920b0e222dc2a2c97dde933c9c4864fab /vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.25.4
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php new file mode 100644 index 00000000..fce6f857 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/IpRangeTest.php @@ -0,0 +1,56 @@ +<?php + +namespace Elastica\Test\Aggregation; + + +use Elastica\Aggregation\IpRange; +use Elastica\Document; +use Elastica\Query; +use Elastica\Type\Mapping; + +class IpRangeTest extends BaseAggregationTest +{ + protected function setUp() + { + parent::setUp(); + $this->_index = $this->_createIndex("ip_range"); + $mapping = new Mapping(); + $mapping->setProperties(array( + "address" => array("type" => "ip") + )); + $type = $this->_index->getType("test"); + $type->setMapping($mapping); + $docs = array( + new Document("1", array("address" => "192.168.1.100")), + new Document("2", array("address" => "192.168.1.150")), + new Document("3", array("address" => "192.168.1.200")), + ); + $type->addDocuments($docs); + $this->_index->refresh(); + } + + public function testIpRangeAggregation() + { + $agg = new IpRange("ip", "address"); + $agg->addRange("192.168.1.101"); + $agg->addRange(null, "192.168.1.200"); + + $cidrRange = "192.168.1.0/24"; + $agg->addMaskRange($cidrRange); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_index->search($query)->getAggregation("ip"); + + foreach ($results['buckets'] as $bucket) { + if (array_key_exists('key', $bucket) && $bucket['key'] == $cidrRange) { + // the CIDR mask + $this->assertEquals(3, $bucket['doc_count']); + } else { + // the normal ip ranges + $this->assertEquals(2, $bucket['doc_count']); + } + } + } +} +
\ No newline at end of file |