PHP Classes

File: tests/stand-alone-test.php

Recommend this page to a friend!
  Classes of Richard Williams  >  XML Helper  >  tests/stand-alone-test.php  >  Download  
File: tests/stand-alone-test.php
Role: Example script
Content type: text/plain
Description: non-phpunit example/test
Class: XML Helper
Extract XML data into an array and vice-versa
Author: By
Last change:
Date: 11 years ago
Size: 1,369 bytes


Class file image Download
 * To change this template, choose Tools | Templates
 * and open the template in the editor.

include '../XmlHelper.class.php';

$xmlString = file_get_contents(dirname(__FILE__) . "/testXmlData/55521_total_only.xml");
$helper = new XmlHelper();
$data = $helper->xmlToArray ($xmlString);
// print_r($data);
assert('USD' == $data['Order']['attributes']['currency']);
assert('rogue-55521' == $data['Order']['attributes']['id']);
assert('166.95' == $data['Order']['Total']['Line'][0]['value']);
assert(8.32 == $data['Order']['Total']['Line'][1]['value']);
assert(24 == $data['Order']['Total']['Line'][2]['InnerLine']['value']);
assert(175.27 == $data['Order']['Total']['Line'][3]['value']);
assert('Subtotal' == $data['Order']['Total']['Line'][0]['attributes']['type']);
assert('Shipping' == $data['Order']['Total']['Line'][1]['attributes']['type']);
assert('Tax' == $data['Order']['Total']['Line'][2]['attributes']['type']);
assert('Total' == $data['Order']['Total']['Line'][3]['attributes']['type']);

// Convert the array back to XML and assert that it is the same as the original XML.

$xml = $helper->arrayToXml($data);
$save = $helper->xmlToArray($xml);
assert($data == $save);

For more information send a message to info at phpclasses dot org.