1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8class Search_Elastic_FacetReaderTest extends PHPUnit_Framework_TestCase 9{ 10 private $reader; 11 12 function setUp() 13 { 14 $this->reader = new Search_Elastic_FacetReader( 15 (object) [ 16 'facets' => (object) [ 17 'categories' => (object) [ 18 '_type' => "terms", 19 'missing' => 0, 20 'total' => 7, 21 'other' => 0, 22 'terms' => [ 23 (object) [ 24 'term' => "1", 25 'count' => 3, 26 ], 27 (object) [ 28 'term' => "2", 29 'count' => 2, 30 ], 31 (object) [ 32 'term' => "3", 33 'count' => 1, 34 ], 35 ], 36 ], 37 'tracker_field_priority' => (object) [ 38 '_type' => "terms", 39 'missing' => 0, 40 'total' => 7, 41 'other' => 0, 42 'terms' => [ 43 (object) [ 44 'term' => "", 45 'count' => 3, 46 ], 47 (object) [ 48 'term' => "2", 49 'count' => 2, 50 ], 51 (object) [ 52 'term' => "3", 53 'count' => 1, 54 ], 55 ], 56 ], 57 ], 58 ] 59 ); 60 } 61 62 function testReadUnavailable() 63 { 64 $this->assertNull($this->reader->getFacetFilter(new Search_Query_Facet_Term('foobar'))); 65 } 66 67 function testReadAvailable() 68 { 69 $facet = new Search_Query_Facet_Term('categories'); 70 $expect = new Search_ResultSet_FacetFilter( 71 $facet, 72 [ 73 ['value' => "1", 'count' => 3], 74 ['value' => "2", 'count' => 2], 75 ['value' => "3", 'count' => 1], 76 ] 77 ); 78 79 $this->assertEquals($expect, $this->reader->getFacetFilter($facet)); 80 } 81 82 function testIgnoreEmptyValue() 83 { 84 $facet = new Search_Query_Facet_Term('tracker_field_priority'); 85 $expect = new Search_ResultSet_FacetFilter( 86 $facet, 87 [ 88 ['value' => "2", 'count' => 2], 89 ['value' => "3", 'count' => 1], 90 ] 91 ); 92 93 $this->assertEquals($expect, $this->reader->getFacetFilter($facet)); 94 } 95} 96