[7588] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Copyright 2011 Bas de Nooijer. All rights reserved. |
---|
| 4 | * |
---|
| 5 | * Redistribution and use in source and binary forms, with or without |
---|
| 6 | * modification, are permitted provided that the following conditions are met: |
---|
| 7 | * |
---|
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
| 9 | * this list of conditions and the following disclaimer. |
---|
| 10 | * |
---|
| 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
| 12 | * this listof conditions and the following disclaimer in the documentation |
---|
| 13 | * and/or other materials provided with the distribution. |
---|
| 14 | * |
---|
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
| 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
| 26 | * |
---|
| 27 | * The views and conclusions contained in the software and documentation are |
---|
| 28 | * those of the authors and should not be interpreted as representing official |
---|
| 29 | * policies, either expressed or implied, of the copyright holder. |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | class Solarium_Client_ResponseParser_Analysis_FieldTest extends PHPUnit_Framework_TestCase |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | public function testParse() |
---|
| 36 | { |
---|
| 37 | $data = array( |
---|
| 38 | 'analysis' => array( |
---|
| 39 | 'doc1' => array( |
---|
| 40 | 'field1' => array( |
---|
| 41 | 'type1' => array( |
---|
| 42 | array( |
---|
| 43 | 'org.apache.solr.analysis.PatternReplaceCharFilter', |
---|
| 44 | 'string value', |
---|
| 45 | 'analysisClass', |
---|
| 46 | array( |
---|
| 47 | array( |
---|
| 48 | 'text' => 'test', |
---|
| 49 | 'start' => 1, |
---|
| 50 | 'end' => 23, |
---|
| 51 | 'position' => 4, |
---|
| 52 | 'positionHistory' => 'test', |
---|
| 53 | 'type' => 'test', |
---|
| 54 | ), |
---|
| 55 | array( |
---|
| 56 | 'text' => 'test2', |
---|
| 57 | 'start' => 1, |
---|
| 58 | 'end' => 23, |
---|
| 59 | 'position' => 4, |
---|
| 60 | 'positionHistory' => 'test', |
---|
| 61 | 'type' => 'test', |
---|
| 62 | ) |
---|
| 63 | ) |
---|
| 64 | ) |
---|
| 65 | ) |
---|
| 66 | ) |
---|
| 67 | ) |
---|
| 68 | ), |
---|
| 69 | 'responseHeader' => array( |
---|
| 70 | 'status' => 1, |
---|
| 71 | 'QTime' => 5 |
---|
| 72 | ) |
---|
| 73 | ); |
---|
| 74 | |
---|
| 75 | $resultStub = $this->getMock('Solarium_Result', array(), array(), '', false); |
---|
| 76 | $resultStub->expects($this->once()) |
---|
| 77 | ->method('getData') |
---|
| 78 | ->will($this->returnValue($data)); |
---|
| 79 | |
---|
| 80 | $parser = new Solarium_Client_ResponseParser_Analysis_Field(); |
---|
| 81 | $result = $parser->parse($resultStub); |
---|
| 82 | |
---|
| 83 | $docs = $result['items'][0]->getItems(); |
---|
| 84 | $fields = $docs[0]->getItems(); |
---|
| 85 | $types = $fields[0]->getItems(); |
---|
| 86 | $class1items = $types[0]->getItems(); |
---|
| 87 | $class2items = $types[1]->getItems(); |
---|
| 88 | |
---|
| 89 | $this->assertEquals('string value', $class1items[0]->getText()); |
---|
| 90 | $this->assertEquals('test2', $class2items[1]->getText()); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public function testParseNoData() |
---|
| 94 | { |
---|
| 95 | $data = array( |
---|
| 96 | 'responseHeader' => array( |
---|
| 97 | 'status' => 1, |
---|
| 98 | 'QTime' => 5 |
---|
| 99 | ) |
---|
| 100 | ); |
---|
| 101 | |
---|
| 102 | $resultStub = $this->getMock('Solarium_Result', array(), array(), '', false); |
---|
| 103 | $resultStub->expects($this->once()) |
---|
| 104 | ->method('getData') |
---|
| 105 | ->will($this->returnValue($data)); |
---|
| 106 | |
---|
| 107 | $parser = new Solarium_Client_ResponseParser_Analysis_Field(); |
---|
| 108 | $result = $parser->parse($resultStub); |
---|
| 109 | |
---|
| 110 | $this->assertEquals( |
---|
| 111 | array( |
---|
| 112 | 'status' => 1, |
---|
| 113 | 'queryTime' => 5, |
---|
| 114 | 'items' => array() |
---|
| 115 | ), |
---|
| 116 | $result |
---|
| 117 | ); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | } |
---|