Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added phpunit tests #6

Merged
merged 1 commit into from

1 participant

@jbroadway
Owner

Running tests:

phpunit tests/ActiveResource.php

Covered:

  • __construct()
  • _build_xml()
  • _xml_entities()
  • pluralize()
@jbroadway jbroadway merged commit 22ba6d5 into jbroadway:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 1, 2011
  1. Added phpunit tests

    authored
This page is out of date. Refresh to see the latest.
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');
+ }
+}
+
+?>
Something went wrong with that request. Please try again.