File: DecodeTest.php

package info (click to toggle)
php-horde-xml-wbxml 2.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 292 kB
  • sloc: php: 1,312; xml: 834; sh: 3; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
 * @author     Jan Schneider <jan@horde.org>
 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @category   Horde
 * @package    Xml_Wbxml
 * @subpackage UnitTests
 */

class Horde_Xml_Wbxml_DecodeTest extends Horde_Test_Case
{
    public function testDecode()
    {
        if (!is_executable('/usr/bin/wbxml2xml')) {
            $this->markTestSkipped('/usr/bin/wbxml2xml is required for comparison tests.');
        }

        $decoder = new Horde_Xml_Wbxml_Decoder();

        foreach (glob(__DIR__ . '/../../../../doc/Horde/Xml/Wbxml/examples/*.wbxml') as $file) {
            $xml_ref = shell_exec('/usr/bin/wbxml2xml' . ' -m 0 -o - "' . $file . '" 2>/dev/null');
            $xml_ref = preg_replace(
                array(
                    // Ignore <?xml and <!DOCTYPE stuff:
                    '/<\?xml version=\"1\.0\"\?><!DOCTYPE [^>]*>/',
                    // Normalize empty tags.
                    '|<([^>]+)/>|'),
                array('', '<$1></$1>'),
                $xml_ref);

            $xml = $decoder->decodeToString(file_get_contents($file));

            if (is_string($xml)) {
                // Ignore <?xml and <!DOCTYPE stuff.
                $xml = preg_replace('/<\?xml version=\"1\.0\"\?><!DOCTYPE [^>]*>/', '', $xml);

                // Handle different mimetypes.
                $xml = str_replace('application/vnd.syncml-devinf+wbxml',
                                   'application/vnd.syncml-devinf+xml',
                                   $xml);
            }

            $this->assertEquals(Horde_String::lower($xml_ref), Horde_String::lower($xml));
        }
    }
}