Esempio n. 1
0
        it('should be fluid', function () {
            assert_is_fluid('text', 'a');
        });
        it('should behave like .setText', function () {
            $xml = new FluidXml();
            $xml->setText('Text1')->appendChild('child', true)->setText('Text2');
            $alias = new FluidXml();
            $alias->text('Text1')->appendChild('child', true)->text('Text2');
            $actual = $xml->xml();
            $expected = $alias->xml();
            \assert($actual === $expected, __($actual, $expected));
        });
    });
    describe('.cdata', function () {
        it('should be fluid', function () {
            assert_is_fluid('cdata', 'a');
        });
        it('should behave like .setCdata', function () {
            $xml = new FluidXml();
            $xml->setCdata('Text1')->appendChild('child', true)->setCdata('Text2');
            $alias = new FluidXml();
            $alias->cdata('Text1')->appendChild('child', true)->cdata('Text2');
            $actual = $xml->xml();
            $expected = $alias->xml();
            \assert($actual === $expected, __($actual, $expected));
        });
    });
});
describe('FluidContext', function () {
    it('should be iterable returning the represented DOMNode objects', function () {
        $xml = new FluidXml();
Esempio n. 2
0
         $xml = new FluidXml(['html' => ['body' => ['input', 'div']]]);
         $actual = $xml->html(true);
         $expected = "<html>\n" . "  <body>\n" . "    <input/>\n" . "    <div></div>\n" . "  </body>\n" . "</html>";
         \assert($actual === $expected, __($actual, $expected));
     });
     it('should return a node and the descendants as HTML string', function () {
         $xml = new FluidXml(['html' => ['body' => ['input', 'div']]]);
         $actual = $xml->query('//body/*')->html();
         $expected = "<input/>\n" . "<div></div>";
         \assert($actual === $expected, __($actual, $expected));
     });
 });
 describe('.save()', function () {
     it('should be fluid', function () {
         $file = "{$this->out_dir}.test_save0.xml";
         assert_is_fluid('save', $file);
         \unlink($file);
     });
     it('should store the entire XML document in a file', function () {
         $xml = new FluidXml();
         $xml->addChild('parent', true)->addChild('child', 'content');
         $file = "{$this->out_dir}.test_save1.xml";
         $xml->save($file);
         $actual = \trim(\file_get_contents($file));
         $expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<doc>\n" . "  <parent>\n" . "    <child>content</child>\n" . "  </parent>\n" . "</doc>";
         \unlink($file);
         \assert($actual === $expected, __($actual, $expected));
     });
     it('should store a fragment of the XML document in a file', function () {
         $xml = new FluidXml();
         $xml->addChild('parent', true)->addChild('child', 'content');