[7576] | 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_Document_ReadOnlyTest extends PHPUnit_Framework_TestCase |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | protected $_doc; |
---|
| 36 | |
---|
| 37 | protected $_fields = array( |
---|
| 38 | 'id' => 123, |
---|
| 39 | 'name' => 'Test document', |
---|
| 40 | 'categories' => array(1,2,3) |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | protected function setUp() |
---|
| 44 | { |
---|
| 45 | $this->_doc = new Solarium_Document_ReadOnly($this->_fields); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | public function testGetFields() |
---|
| 49 | { |
---|
| 50 | $this->assertEquals($this->_fields,$this->_doc->getFields()); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | public function testGetFieldAsProperty() |
---|
| 54 | { |
---|
| 55 | $this->assertEquals( |
---|
| 56 | $this->_fields['categories'], |
---|
| 57 | $this->_doc->categories |
---|
| 58 | ); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public function testGetInvalidFieldAsProperty() |
---|
| 62 | { |
---|
| 63 | $this->assertEquals( |
---|
| 64 | null, |
---|
| 65 | $this->_doc->invalidfieldname |
---|
| 66 | ); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public function testSetField() |
---|
| 70 | { |
---|
| 71 | $this->setExpectedException('Solarium_Exception'); |
---|
| 72 | $this->_doc->newField = 'new value'; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public function testIterator() |
---|
| 76 | { |
---|
| 77 | $fields = array(); |
---|
| 78 | foreach($this->_doc AS $key => $field) |
---|
| 79 | { |
---|
| 80 | $fields[$key] = $field; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | $this->assertEquals($this->_fields, $fields); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | public function testArrayGet() |
---|
| 87 | { |
---|
| 88 | $this->assertEquals( |
---|
| 89 | $this->_fields['categories'], |
---|
| 90 | $this->_doc['categories'] |
---|
| 91 | ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | public function testArrayGetInvalidField() |
---|
| 95 | { |
---|
| 96 | $this->assertEquals( |
---|
| 97 | null, |
---|
| 98 | $this->_doc['invalidfield'] |
---|
| 99 | ); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | public function testArrayIsset() |
---|
| 103 | { |
---|
| 104 | $this->assertTrue( |
---|
| 105 | isset($this->_doc['categories']) |
---|
| 106 | ); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | public function testArrayIssetInvalidField() |
---|
| 110 | { |
---|
| 111 | $this->assertFalse( |
---|
| 112 | isset($this->_doc['invalidfield']) |
---|
| 113 | ); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | public function testArraySet() |
---|
| 117 | { |
---|
| 118 | $this->setExpectedException('Solarium_Exception'); |
---|
| 119 | $this->_doc['newField'] = 'new value'; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | public function testArrayUnset() |
---|
| 123 | { |
---|
| 124 | $this->setExpectedException('Solarium_Exception'); |
---|
| 125 | unset($this->_doc['newField']); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | public function testCount() |
---|
| 129 | { |
---|
| 130 | $this->assertEquals(count($this->_fields), count($this->_doc)); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | } |
---|