PHP Classes
elePHPant
Icontem

File: tests/stand-alone-test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 4 years ago
Size: 1,369 bytes
 

Contents

Class file image Download
<?php
/*
 * 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();
   
$helper->setCaseFolding(false);
   
$helper->setTrimText(true);
   
$data = $helper->xmlToArray ($xmlString);
// print_r($data);
   
assert(is_array($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);
?>