| 11 | | * Helper class for the test. |
|---|
| 12 | | * |
|---|
| 13 | | * @package stubbles |
|---|
| 14 | | * @subpackage websites_xml_test |
|---|
| 15 | | */ |
|---|
| 16 | | class TeststubXMLProcessor extends stubXMLProcessor |
|---|
| 17 | | { |
|---|
| 18 | | /** |
|---|
| 19 | | * xml stream writer instance to be used |
|---|
| 20 | | * |
|---|
| 21 | | * @var stubXMLStreamWriter |
|---|
| 22 | | */ |
|---|
| 23 | | protected $xmlStreamWriter; |
|---|
| 24 | | /** |
|---|
| 25 | | * xml serializer instance to be used |
|---|
| 26 | | * |
|---|
| 27 | | * @var stubXMLSerializer |
|---|
| 28 | | */ |
|---|
| 29 | | protected $xmlSerializer; |
|---|
| 30 | | |
|---|
| 31 | | /** |
|---|
| 32 | | * sets the xml stream writer instance to be used |
|---|
| 33 | | * |
|---|
| 34 | | * @param stubXMLStreamWriter $xmlStreamWriter |
|---|
| 35 | | */ |
|---|
| 36 | | public function setXMLStreamWriter($xmlStreamWriter) |
|---|
| 37 | | { |
|---|
| 38 | | $this->xmlStreamWriter = $xmlStreamWriter; |
|---|
| 39 | | } |
|---|
| 40 | | |
|---|
| 41 | | /** |
|---|
| 42 | | * sets the xml serializer instance to be used |
|---|
| 43 | | * |
|---|
| 44 | | * @param stubXMLSerializer $xmlSerializer |
|---|
| 45 | | */ |
|---|
| 46 | | public function setXMLSerializer($xmlSerializer) |
|---|
| 47 | | { |
|---|
| 48 | | $this->xmlSerializer = $xmlSerializer; |
|---|
| 49 | | } |
|---|
| 50 | | |
|---|
| 51 | | /** |
|---|
| 52 | | * returns a xml stream writer |
|---|
| 53 | | * |
|---|
| 54 | | * @return stubXMLStreamWriter |
|---|
| 55 | | */ |
|---|
| 56 | | protected function createXMLStreamWriter() |
|---|
| 57 | | { |
|---|
| 58 | | return $this->xmlStreamWriter; |
|---|
| 59 | | } |
|---|
| 60 | | |
|---|
| 61 | | /** |
|---|
| 62 | | * returns the xml serializer |
|---|
| 63 | | * |
|---|
| 64 | | * @return stubXMLSerializer |
|---|
| 65 | | */ |
|---|
| 66 | | protected function createXMLSerializer() |
|---|
| 67 | | { |
|---|
| 68 | | return $this->xmlSerializer; |
|---|
| 69 | | } |
|---|
| 70 | | } |
|---|
| 71 | | /** |
|---|
| 149 | | * assure that processing works as expected |
|---|
| 150 | | * |
|---|
| 151 | | * @test |
|---|
| 152 | | */ |
|---|
| 153 | | /*public function defaultPageWithoutElements() |
|---|
| 154 | | { |
|---|
| | 100 | * clean up test environment |
|---|
| | 101 | */ |
|---|
| | 102 | public function tearDown() |
|---|
| | 103 | { |
|---|
| | 104 | stubRegistry::remove(stubBinder::REGISTRY_KEY); |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | /** |
|---|
| | 108 | * no binder available > runtime exception |
|---|
| | 109 | * |
|---|
| | 110 | * @test |
|---|
| | 111 | * @expectedException stubRuntimeException |
|---|
| | 112 | */ |
|---|
| | 113 | public function processWithoutBinderInRegistryThrowsRuntimeException() |
|---|
| | 114 | { |
|---|
| | 115 | stubRegistry::remove(stubBinder::REGISTRY_KEY); |
|---|
| | 118 | $this->xmlProcessor->expects($this->never())->method('createXMLStreamWriter'); |
|---|
| | 119 | $this->xmlProcessor->expects($this->never())->method('createXMLSerializer'); |
|---|
| | 120 | $this->xmlProcessor->expects($this->never())->method('createSkinGenerator'); |
|---|
| | 121 | $this->xmlProcessor->expects($this->never())->method('createXSLProcessor'); |
|---|
| | 122 | $this->xmlProcessor->process(); |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | /** |
|---|
| | 126 | * assure that processing works as expected |
|---|
| | 127 | * |
|---|
| | 128 | * @test |
|---|
| | 129 | */ |
|---|
| | 130 | public function defaultPage() |
|---|
| | 131 | { |
|---|
| | 132 | $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false)); |
|---|
| | 133 | $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index')); |
|---|
| | 134 | $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); |
|---|
| | 135 | $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); |
|---|
| 158 | | $this->mockXMLStreamWriter->expects($this->never())->method('writeEndElement'); |
|---|
| 159 | | $this->mockXMLSerializer->expects($this->once())->method('serialize'); |
|---|
| 160 | | $return = $this->xmlProcessor->process(); |
|---|
| 161 | | $this->assertSame($this->xmlProcessor, $return); |
|---|
| 162 | | $response = $this->xmlProcessor->getResponse(); |
|---|
| 163 | | $this->assertType('stubResponse', $response); |
|---|
| 164 | | }*/ |
|---|
| | 137 | $this->mockXMLStreamWriter->expects($this->once())->method('writeAttribute')->with($this->equalTo('page'), $this->equalTo('index')); |
|---|
| | 138 | $this->mockXMLStreamWriter->expects($this->once())->method('writeEndElement'); |
|---|
| | 139 | $mockGlobalXMLElement = $this->getMock('stubGlobalXMLElement'); |
|---|
| | 140 | $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockGlobalXMLElement)); |
|---|
| | 141 | $mockGlobalXMLElement->expects($this->exactly(3))->method('append')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); |
|---|
| | 142 | $resultXSL = new DOMDocument(); |
|---|
| | 143 | $mockSkinGenerator = $this->getMock('stubSkinGenerator'); |
|---|
| | 144 | $mockSkinGenerator->expects($this->once()) |
|---|
| | 145 | ->method('generate') |
|---|
| | 146 | ->will($this->returnValue($resultXSL)); |
|---|
| | 147 | $this->xmlProcessor->expects($this->once())->method('createSkinGenerator')->will($this->returnValue($mockSkinGenerator)); |
|---|
| | 148 | |
|---|
| | 149 | $mockXSLProcessor = $this->getMock('stubXSLProcessor'); |
|---|
| | 150 | $mockXSLProcessor->expects($this->once())->method('importXSLStylesheet')->with($this->equalTo($resultXSL)); |
|---|
| | 151 | $mockXSLProcessor->expects($this->once())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 152 | $this->xmlProcessor->expects($this->once())->method('createXSLProcessor')->will($this->returnValue($mockXSLProcessor)); |
|---|
| | 153 | |
|---|
| | 154 | $domDocument0 = new DOMDocument(); |
|---|
| | 155 | $domDocument0->createElement('bar', 'foo'); |
|---|
| | 156 | $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); |
|---|
| | 157 | $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 158 | $this->xmlProcessor->process(); |
|---|
| | 159 | } |
|---|
| 176 | | $pageElement1 = $this->getMock('stubPageElement'); |
|---|
| 177 | | $pageElement1->expects($this->any())->method('getName')->will($this->returnValue('foo')); |
|---|
| 178 | | $pageElement1->expects($this->once())->method('process')->will($this->returnValue('foo')); |
|---|
| 179 | | $pageElement1->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); |
|---|
| 180 | | $pageElement2 = $this->getMock('stubPageElement'); |
|---|
| 181 | | $pageElement2->expects($this->any())->method('getName')->will($this->returnValue('bar')); |
|---|
| 182 | | $pageElement2->expects($this->once())->method('process')->will($this->returnValue('bar')); |
|---|
| 183 | | $pageElement2->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); |
|---|
| 184 | | $pageElement3 = $this->getMock('stubPageElement'); |
|---|
| 185 | | $pageElement3->expects($this->any())->method('getName')->will($this->returnValue('baz')); |
|---|
| 186 | | $pageElement3->expects($this->never())->method('process'); |
|---|
| 187 | | $pageElement3->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); |
|---|
| 188 | | $this->page->addElement($pageElement1); |
|---|
| 189 | | $this->page->addElement($pageElement2); |
|---|
| 190 | | $this->page->addElement($pageElement3); |
|---|
| | 171 | $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); |
|---|
| | 172 | $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); |
|---|
| 192 | | $this->mockXMLStreamWriter->expects($this->never())->method('writeEndElement'); |
|---|
| 193 | | $this->mockXMLSerializer->expects($this->at(0)) |
|---|
| 194 | | ->method('serialize') |
|---|
| 195 | | ->with($this->equalTo('foo'), |
|---|
| 196 | | $this->equalTo($this->mockXMLStreamWriter), |
|---|
| 197 | | $this->equalTo(array(stubXMLSerializer::OPT_ROOT_TAG => 'foo')) |
|---|
| 198 | | ); |
|---|
| 199 | | $this->mockXMLSerializer->expects($this->at(1)) |
|---|
| 200 | | ->method('serialize') |
|---|
| 201 | | ->with($this->equalTo('bar'), |
|---|
| 202 | | $this->equalTo($this->mockXMLStreamWriter), |
|---|
| 203 | | $this->equalTo(array(stubXMLSerializer::OPT_ROOT_TAG => 'bar')) |
|---|
| 204 | | ); |
|---|
| 205 | | $return = $this->xmlProcessor->process(); |
|---|
| 206 | | $this->assertSame($this->xmlProcessor, $return); |
|---|
| 207 | | $response = $this->xmlProcessor->getResponse(); |
|---|
| 208 | | $this->assertType('stubResponse', $response); |
|---|
| 209 | | }*/ |
|---|
| | 174 | $this->mockXMLStreamWriter->expects($this->once())->method('writeAttribute')->with($this->equalTo('page'), $this->equalTo('index')); |
|---|
| | 175 | $this->mockXMLStreamWriter->expects($this->once())->method('writeEndElement'); |
|---|
| | 176 | $mockGlobalXMLElement = $this->getMock('stubGlobalXMLElement'); |
|---|
| | 177 | $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockGlobalXMLElement)); |
|---|
| | 178 | $mockGlobalXMLElement->expects($this->exactly(3))->method('append')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); |
|---|
| | 179 | $resultXSL = new DOMDocument(); |
|---|
| | 180 | $mockSkinGenerator = $this->getMock('stubSkinGenerator'); |
|---|
| | 181 | $mockSkinGenerator->expects($this->once()) |
|---|
| | 182 | ->method('generate') |
|---|
| | 183 | ->will($this->returnValue($resultXSL)); |
|---|
| | 184 | $this->xmlProcessor->expects($this->once())->method('createSkinGenerator')->will($this->returnValue($mockSkinGenerator)); |
|---|
| | 185 | |
|---|
| | 186 | $mockXSLProcessor = $this->getMock('stubXSLProcessor'); |
|---|
| | 187 | $mockXSLProcessor->expects($this->once())->method('importXSLStylesheet')->with($this->equalTo($resultXSL)); |
|---|
| | 188 | $mockXSLProcessor->expects($this->once())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 189 | $this->xmlProcessor->expects($this->once())->method('createXSLProcessor')->will($this->returnValue($mockXSLProcessor)); |
|---|
| | 190 | |
|---|
| | 191 | $domDocument0 = new DOMDocument(); |
|---|
| | 192 | $domDocument0->createElement('bar', 'foo'); |
|---|
| | 193 | $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); |
|---|
| | 194 | $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 195 | $this->xmlProcessor->process(); |
|---|
| | 196 | } |
|---|
| 222 | | $this->xmlProcessor->process(); |
|---|
| 223 | | }*/ |
|---|
| | 209 | $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); |
|---|
| | 210 | $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); |
|---|
| | 211 | $this->mockXMLStreamWriter->expects($this->once())->method('writeStartElement'); |
|---|
| | 212 | $this->mockXMLStreamWriter->expects($this->once())->method('writeAttribute')->with($this->equalTo('page'), $this->equalTo('baz')); |
|---|
| | 213 | $this->mockXMLStreamWriter->expects($this->once())->method('writeEndElement'); |
|---|
| | 214 | $mockGlobalXMLElement = $this->getMock('stubGlobalXMLElement'); |
|---|
| | 215 | $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockGlobalXMLElement)); |
|---|
| | 216 | $mockGlobalXMLElement->expects($this->exactly(3))->method('append')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); |
|---|
| | 217 | $resultXSL = new DOMDocument(); |
|---|
| | 218 | $mockSkinGenerator = $this->getMock('stubSkinGenerator'); |
|---|
| | 219 | $mockSkinGenerator->expects($this->once()) |
|---|
| | 220 | ->method('generate') |
|---|
| | 221 | ->will($this->returnValue($resultXSL)); |
|---|
| | 222 | $this->xmlProcessor->expects($this->once())->method('createSkinGenerator')->will($this->returnValue($mockSkinGenerator)); |
|---|
| | 223 | |
|---|
| | 224 | $mockXSLProcessor = $this->getMock('stubXSLProcessor'); |
|---|
| | 225 | $mockXSLProcessor->expects($this->once())->method('importXSLStylesheet')->with($this->equalTo($resultXSL)); |
|---|
| | 226 | $mockXSLProcessor->expects($this->once())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 227 | $this->xmlProcessor->expects($this->once())->method('createXSLProcessor')->will($this->returnValue($mockXSLProcessor)); |
|---|
| | 228 | |
|---|
| | 229 | $domDocument0 = new DOMDocument(); |
|---|
| | 230 | $domDocument0->createElement('bar', 'foo'); |
|---|
| | 231 | $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); |
|---|
| | 232 | $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); |
|---|
| | 233 | $this->xmlProcessor->process(); |
|---|
| | 234 | } |
|---|