Browse files

Merge pull request #6 from jbroadway/master

Added phpunit tests
  • Loading branch information...
2 parents 3410200 + 3ac8b77 commit 22ba6d52c27d50559b0db1f412e67031dfe387e0 @jbroadway committed Jun 1, 2011
Showing with 73 additions and 43 deletions.
  1. +1 −43 ActiveResource.php
  2. +72 −0 tests/ActiveResource.php
View
44 ActiveResource.php
@@ -290,7 +290,7 @@ function put ($method, $options = array ()) {
*/
function _build_xml ($k, $v) {
if (is_object ($v) && strtolower (get_class ($v)) == 'simplexmlelement') {
- return preg_replace ('/<\?xml(.*?)\?>/', '', $v->asXML ());
+ return preg_replace ('/<\?xml(.*?)\?>\n*/', '', $v->asXML ());
}
$res = '';
$attrs = '';
@@ -532,46 +532,4 @@ function set ($k, $v = false) {
}
}
-/** TODO: Replace with a proper set of tests.
-
-class Test extends ActiveResource {}
-
-$t = new Test;
-
-echo $t->pluralize ('person') . "\n";
-echo $t->pluralize ('people') . "\n";
-echo $t->pluralize ('man') . "\n";
-echo $t->pluralize ('woman') . "\n";
-echo $t->pluralize ('women') . "\n";
-echo $t->pluralize ('child') . "\n";
-echo $t->pluralize ('sheep') . "\n";
-echo $t->pluralize ('octopus') . "\n";
-echo $t->pluralize ('virus') . "\n";
-echo $t->pluralize ('quiz') . "\n";
-echo $t->pluralize ('axis') . "\n";
-echo $t->pluralize ('axe') . "\n";
-echo $t->pluralize ('buffalo') . "\n";
-echo $t->pluralize ('tomato') . "\n";
-echo $t->pluralize ('potato') . "\n";
-echo $t->pluralize ('ox') . "\n";
-echo $t->pluralize ('mouse') . "\n";
-echo $t->pluralize ('matrix') . "\n";
-echo $t->pluralize ('vertex') . "\n";
-echo $t->pluralize ('vortex') . "\n";
-echo $t->pluralize ('index') . "\n";
-echo $t->pluralize ('sandwich') . "\n";
-echo $t->pluralize ('mass') . "\n";
-echo $t->pluralize ('fax') . "\n";
-echo $t->pluralize ('pin') . "\n";
-echo $t->pluralize ('touch') . "\n";
-echo $t->pluralize ('sash') . "\n";
-echo $t->pluralize ('bromium') . "\n";
-echo $t->pluralize ('prophecy') . "\n";
-echo $t->pluralize ('crisis') . "\n";
-echo $t->pluralize ('life') . "\n";
-echo $t->pluralize ('wife') . "\n";
-echo $t->pluralize ('song') . "\n";
-
-*/
-
?>
View
72 tests/ActiveResource.php
@@ -0,0 +1,72 @@
+<?php
+
+require_once ('ActiveResource.php');
+
+class Test extends ActiveResource {
+}
+
+class ActiveResourceTest extends PHPUnit_Framework_TestCase {
+ function test_construct () {
+ $t = new Test (array ('foo' => 'bar'));
+
+ $this->assertEquals ($t->foo, 'bar');
+ $t->foo = 'asdf';
+ $this->assertEquals ($t->foo, 'asdf');
+ $this->assertEquals ($t->_data, array ('foo' => 'asdf'));
+ $this->assertEquals ($t->element_name, 'tests');
+ }
+
+ function test_build_xml () {
+ $t = new Test;
+
+ $this->assertEquals ($t->_build_xml (0, 'foo'), 'foo');
+ $this->assertEquals ($t->_build_xml (0, array ('foo' => 'bar')), "<foo>bar</foo>\n");
+ $this->assertEquals ($t->_build_xml ('foo', 'bar'), "<foo>bar</foo>\n");
+ $this->assertEquals ($t->_build_xml ('foo', array ('bar' => 'asdf')), "<foo><bar>asdf</bar>\n</foo>\n");
+ $this->assertEquals ($t->_build_xml ('foo', array ('@bar' => 'asdf')), "<foo bar=\"asdf\"></foo>\n");
+ $this->assertEquals ($t->_xml_entities ('<'), '&#60;');
+
+ $xml = new SimpleXMLElement ('<foo><bar asdf="qwerty" />what</foo>');
+ $this->assertEquals ($t->_build_xml (0, $xml), "<foo><bar asdf=\"qwerty\"/>what</foo>\n");
+ }
+
+ function test_pleuralize () {
+ $t = new Test;
+
+ $this->assertEquals ($t->pluralize ('person'), 'people');
+ $this->assertEquals ($t->pluralize ('people'), 'people');
+ $this->assertEquals ($t->pluralize ('man'), 'men');
+ $this->assertEquals ($t->pluralize ('woman'), 'women');
+ $this->assertEquals ($t->pluralize ('women'), 'women');
+ $this->assertEquals ($t->pluralize ('child'), 'children');
+ $this->assertEquals ($t->pluralize ('sheep'), 'sheep');
+ $this->assertEquals ($t->pluralize ('octopus'), 'octopi');
+ $this->assertEquals ($t->pluralize ('virus'), 'viruses');
+ $this->assertEquals ($t->pluralize ('quiz'), 'quizzes');
+ $this->assertEquals ($t->pluralize ('axis'), 'axes');
+ $this->assertEquals ($t->pluralize ('axe'), 'axes');
+ $this->assertEquals ($t->pluralize ('buffalo'), 'buffaloes');
+ $this->assertEquals ($t->pluralize ('tomato'), 'tomatoes');
+ $this->assertEquals ($t->pluralize ('potato'), 'potatoes');
+ $this->assertEquals ($t->pluralize ('ox'), 'oxen');
+ $this->assertEquals ($t->pluralize ('mouse'), 'mice');
+ $this->assertEquals ($t->pluralize ('matrix'), 'matrices');
+ $this->assertEquals ($t->pluralize ('vertex'), 'vertices');
+ $this->assertEquals ($t->pluralize ('vortex'), 'vortexes');
+ $this->assertEquals ($t->pluralize ('index'), 'indices');
+ $this->assertEquals ($t->pluralize ('sandwich'), 'sandwiches');
+ $this->assertEquals ($t->pluralize ('mass'), 'masses');
+ $this->assertEquals ($t->pluralize ('fax'), 'faxes');
+ $this->assertEquals ($t->pluralize ('pin'), 'pins');
+ $this->assertEquals ($t->pluralize ('touch'), 'touches');
+ $this->assertEquals ($t->pluralize ('sash'), 'sashes');
+ $this->assertEquals ($t->pluralize ('bromium'), 'bromia');
+ $this->assertEquals ($t->pluralize ('prophecy'), 'prophecies');
+ $this->assertEquals ($t->pluralize ('crisis'), 'crises');
+ $this->assertEquals ($t->pluralize ('life'), 'lives');
+ $this->assertEquals ($t->pluralize ('wife'), 'wives');
+ $this->assertEquals ($t->pluralize ('song'), 'songs');
+ }
+}
+
+?>

0 comments on commit 22ba6d5

Please sign in to comment.