function test_memory_xml_output() { // Instantiate xml_output $xo = new memory_xml_output(); $this->assertTrue($xo instanceof xml_output); // Try to write some contents before starting it $xo = new memory_xml_output(); try { $xo->write('test'); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_started'); } // Try to set buffer size if unsupported $xo = new memory_xml_output(); try { $xo->set_buffersize(8192); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_buffer_nosupport'); } // Try to set buffer after start $xo = new memory_xml_output(); $xo->start(); try { $xo->set_buffersize(8192); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_already_started'); } // Try to stop output before starting it $xo = new memory_xml_output(); try { $xo->stop(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_started'); } // Try to debug_info() before starting $xo = new memory_xml_output(); try { $xo->debug_info(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_stopped'); } // Start output twice $xo = new memory_xml_output(); $xo->start(); try { $xo->start(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_already_started'); } // Try to debug_info() before stoping $xo = new memory_xml_output(); $xo->start(); try { $xo->debug_info(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_stopped'); } // Stop output twice $xo = new memory_xml_output(); $xo->start(); $xo->stop(); try { $xo->stop(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_started'); } // Try to re-start after stop $xo = new memory_xml_output(); $xo->start(); $xo->stop(); try { $xo->start(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_already_stopped'); } // Try to get contents before stopping $xo = new memory_xml_output(); $xo->start(); try { $xo->get_allcontents(); $this->assertTrue(false, 'xml_output_exception expected'); } catch (exception $e) { $this->assertTrue($e instanceof xml_output_exception); $this->assertEqual($e->errorcode, 'xml_output_not_stopped'); } // Write some contents and check them $xo = new memory_xml_output(); $xo->start(); $xo->write('first test'); $xo->stop(); $this->assertEqual('first test', $xo->get_allcontents()); // Write 3 times and check them $xo = new memory_xml_output(); $xo->start(); $xo->write('first test'); $xo->write(', sencond test'); $xo->write(', third test'); $xo->stop(); $this->assertEqual('first test, sencond test, third test', $xo->get_allcontents()); // Write some line feeds, tabs and friends $string = "\n\r\tcrazy test\n\r\t"; $xo = new memory_xml_output(); $xo->start(); $xo->write($string); $xo->stop(); $this->assertEqual($string, $xo->get_allcontents()); // Write some UTF-8 chars $string = 'áéíóú'; $xo = new memory_xml_output(); $xo->start(); $xo->write($string); $xo->stop(); $this->assertEqual($string, $xo->get_allcontents()); // Write some empty content $xo = new memory_xml_output(); $xo->start(); $xo->write('Hello '); $xo->write(null); $xo->write(false); $xo->write(''); $xo->write('World'); $xo->write(null); $xo->stop(); $this->assertEqual('Hello World', $xo->get_allcontents()); // Get debug info $xo = new memory_xml_output(); $xo->start(); $xo->write('01234'); $xo->write('56789'); $xo->stop(); $this->assertEqual('0123456789', $xo->get_allcontents()); $debug = $xo->debug_info(); $this->assertTrue(is_array($debug)); $this->assertTrue(array_key_exists('sent', $debug)); $this->assertEqual($debug['sent'], 10); }