add unittest helper method
authorAlexander Stintzing <a.stintzing@metaways.de>
Fri, 4 Jul 2014 13:33:06 +0000 (15:33 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 7 Jul 2014 10:01:22 +0000 (12:01 +0200)
 - get the content.xml from a ods file

Change-Id: Ia28cc2a99d76766875444ff1adf5479727aef8eb
Reviewed-on: http://gerrit.tine20.com/customers/825
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/TestCase.php

index ccd7acd..f0f89fa 100644 (file)
@@ -257,4 +257,30 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         
         self::getMailer()->flush();
     }
+    
+    /**
+     * returns the content.xml of an ods document
+     * 
+     * @param string $filename
+     * @return SimpleXMLElement
+     */
+    protected function _getContentXML($filename)
+    {
+        $zipHandler = zip_open($filename);
+        
+        do {
+            $entry = zip_read($zipHandler);
+        } while ($entry && zip_entry_name($entry) != "content.xml");
+        
+        // open entry
+        zip_entry_open($zipHandler, $entry, "r");
+        
+        // read entry
+        $entryContent = zip_entry_read($entry, zip_entry_filesize($entry));
+        
+        $xml = simplexml_load_string($entryContent);
+        zip_close($zipHandler);
+        
+        return $xml;
+    }
 }