Skip to content

Commit

Permalink
Added tests for issue 12.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbroadway committed Dec 7, 2011
1 parent 67d32d5 commit f19a6e7
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/ActiveResource.php
Expand Up @@ -18,13 +18,44 @@ function test_construct () {

function test_build_xml () {
$t = new Test;


// value only
$this->assertEquals ($t->_build_xml (0, 'foo'), 'foo');

// no initial tag
$this->assertEquals ($t->_build_xml (0, array ('foo' => 'bar')), "<foo>bar</foo>\n");

// tag and value
$this->assertEquals ($t->_build_xml ('foo', 'bar'), "<foo>bar</foo>\n");

// sub-tags
$this->assertEquals ($t->_build_xml ('foo', array ('bar' => 'asdf')), "<foo><bar>asdf</bar>\n</foo>\n");

// attributes
$this->assertEquals ($t->_build_xml ('foo', array ('@bar' => 'asdf')), "<foo bar=\"asdf\"></foo>\n");

// attributes and content
$this->assertEquals ($t->_build_xml ('foo', array ('@bar' => 'asdf', 'bar')), "<foo bar=\"asdf\">bar</foo>\n");

// repeating tags
$this->assertEquals (
$t->_build_xml ('foo', array (array ('bar'), array ('bar'))),
"<foo>bar</foo>\n<foo>bar</foo>\n"
);

// repeating tags with attributes
$this->assertEquals (
$t->_build_xml ('foo', array (array ('@id' => 'one', 'bar'), array ('@id' => 'two', 'bar'))),
"<foo id=\"one\">bar</foo>\n<foo id=\"two\">bar</foo>\n"
);

// repeating tags with attributes and sub-tags
$this->assertEquals (
$t->_build_xml ('foo', array (array ('@id' => 'one', 'bar' => 'asdf'), array ('@id' => 'two', 'bar' => 'qwerty'))),
"<foo id=\"one\"><bar>asdf</bar>\n</foo>\n<foo id=\"two\"><bar>qwerty</bar>\n</foo>\n"
);

// starting from a SimpleXMLElement
$xml = new SimpleXMLElement ('<foo><bar asdf="qwerty" />what</foo>');
$this->assertEquals ($t->_build_xml (0, $xml), "<foo><bar asdf=\"qwerty\"/>what</foo>\n");
}
Expand Down

0 comments on commit f19a6e7

Please sign in to comment.