Inheritance: implements fluidxml\FluidInterface, use trait FluidAliasesTrait, use trait FluidSaveTrait, use trait NewableTrait, use trait ReservedCallTrait, use trait ReservedCallStaticTrait
コード例 #1
0
 /**
  * @dataProvider data_provider
  * @param array $questionsAndAnswers
  * @param string $xpath
  * @param int $expectedCount
  */
 public function test_factory_question(array $questionsAndAnswers, $xpath, $expectedCount)
 {
     foreach ($questionsAndAnswers as $question => $answer) {
         $this->mock_question_helper($question, $answer);
     }
     $xml = $this->call_create_on_sut();
     $fluidXml = FluidXml::load($xml);
     $results = $fluidXml->query($xpath);
     self::assertCount($expectedCount, $results);
 }
コード例 #2
0
ファイル: FluidXml.php プロジェクト: Lucascvs/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();
        $cx = $xml->appendChild(['head', 'body'], true);
        $actual = $cx;
        assert_is_a($actual, \Iterator::class);
        $representation = [];
        foreach ($cx as $k => $v) {
コード例 #3
0
ファイル: fluid.php プロジェクト: servo-php/fluidxml
function fluidify(...$arguments)
{
    return \FluidXml\FluidXml::load(...$arguments);
}
コード例 #4
0
ファイル: 00_Intro.php プロジェクト: servo-php/fluidxml
$back = '..' . $DS;
$source = __DIR__ . $DS . $back . $back . 'source';
\set_include_path($source . PATH_SEPARATOR . \get_include_path());
////////////////////////////////////////////////////////////////////////////////
require_once 'FluidXml.php';
use FluidXml\FluidXml;
use FluidXml\FluidNamespace;
use function FluidXml\fluidxml;
use function FluidXml\fluidns;
use function FluidXml\fluidify;
/*****************************
 * Creating An XML Document. *
******************************/
$book = new FluidXml('book');
// or
$book = new FluidXml(null, ['root' => 'book']);
// $book is an XML document with 'book' as root node.
// The default options are:
// [ 'root'       => 'doc',      // The root node of the document.
//   'version'    => '1.0',      // The version for the XML header.
//   'encoding'   => 'UTF-8',    // The encoding for the XML header.
//   'stylesheet' => null ];     // An url pointing to an XSL file.
$booksheet = new FluidXml('book', ['stylesheet' => 'http://domain.com/style.xsl']);
// With PHP 7 this is valid too:
// $booksheet = FluidXml::new('book', ['stylesheet' => 'http://domain.com/style.xsl']);
$book->setAttribute('type', 'science')->addChild(['title' => 'The Theory Of Everything', 'author' => 'S. Hawking']);
// It creates two nodes, each one with some text inside.
echo $book->xml();
// Exports the xml document as a string.
echo "————————————————————————————————————————————————————————————————————————————————\n";
/**********************
コード例 #5
0
 public function test_adds_testsuites()
 {
     $xml = FluidXml::load($this->sut->addTestSuite('foo', 'path/to/foo')->addTestSuite('bar', 'path/to/bar')->__toString());
     $testsuites = $xml->query('/phpunit/testsuites/testsuite');
     self::assertCount(2, $testsuites);
     self::assertEquals('foo', $testsuites[0]->getAttribute('name'));
     self::assertEquals('bar', $testsuites[1]->getAttribute('name'));
     $directories = $testsuites->query('//directory');
     self::assertCount(2, $directories);
     self::assertEquals('path/to/foo', $directories[0]->nodeValue);
     self::assertEquals('path/to/bar', $directories[1]->nodeValue);
 }
コード例 #6
0
ファイル: FluidXml.php プロジェクト: servo-php/fluidxml
            $expected = "<doc/>";
            \assert($actual === $expected, __($actual, $expected));
        });
    });
    describe('simplexmlToStringWithoutHeaders()', function () {
        it('should convert a SimpleXMLElement instance to an XML string without the XML headers (declaration and stylesheets)', function () {
            $xml = \simplexml_import_dom((new FluidXml())->dom());
            $actual = FluidHelper::simplexmlToStringWithoutHeaders($xml);
            $expected = "<doc/>";
            \assert($actual === $expected, __($actual, $expected));
        });
    });
});
describe('CssTranslator', function () {
    describe('.xpath()', function () {
        $hml = new FluidXml(['html' => ['body' => ['div' => ['p' => ['@class' => 'a', '@id' => '123', ['span']], 'h1' => ['@class' => 'b'], 'p' => ['@class' => 'a b'], 'p' => ['@class' => 'a']]]]]);
        $hml->namespace('svg', 'http://svg.org');
        $hml->query('//body')->add('svg', true)->add('shape');
        it('should support the CSS selector A', function () use($hml) {
            $actual = $hml->query('p')->array();
            $expected = $hml->query('.//p')->array();
            \assert($actual === $expected, __($actual, $expected));
            $expected = $hml->query('//p')->array();
            \assert($actual === $expected, __($actual, $expected));
        });
        it('should support the CSS selector ns|A', function () use($hml) {
            $actual = $hml->query('svg|shape')->array();
            $expected = $hml->query('//svg:shape')->array();
            \assert($actual === $expected, __($actual, $expected));
        });
        it('should support the CSS selector :root', function () use($hml) {