Add tests for the demo files not to have fatal errors
authorgggeek <giunta.gaetano@gmail.com>
Fri, 27 Mar 2015 08:51:29 +0000 (08:51 +0000)
committergggeek <giunta.gaetano@gmail.com>
Fri, 27 Mar 2015 08:51:29 +0000 (08:51 +0000)
composer.json
tests/1ParsingBugsTest.php
tests/5DemofilesTest.php [new file with mode: 0644]

index bae04ba..51130cb 100644 (file)
@@ -11,7 +11,8 @@
     "require-dev": {
         "phpunit/phpunit": ">=4.0.0",
         "phpunit/phpunit-selenium": "*",
-        "codeclimate/php-test-reporter": "dev-master"
+        "codeclimate/php-test-reporter": "dev-master",
+        "ext-curl": "*"
     },
     "suggest": {
         "ext-curl": "Needed for HTTPS and HTTP 1.1 support, NTLM Auth etc...",
index db03a47..0868a91 100644 (file)
@@ -14,6 +14,13 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
         $this->assertEquals($u->scalarval(), $v->scalarval());
     }
 
+    public function testMinusOneInt()
+    {
+        $v = new xmlrpcval(-1);
+        $u = new xmlrpcval(-1, 'string');
+        $this->assertEquals($u->scalarval(), $v->scalarval());
+    }
+
     public function testUnicodeInMemberName()
     {
         $str = "G" . chr(252) . "nter, El" . chr(232) . "ne";
@@ -403,19 +410,19 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
     {
         $s = new xmlrpcmsg('dummy');
         $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
-<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode('àüèàüè') . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
+<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode('������') . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
 ';
         $r = $s->parseResponse($f, false, 'phpvals');
         $v = $r->value();
         $v = $v['content'];
-        $this->assertEquals("àüèàüè", $v);
+        $this->assertEquals("������", $v);
         $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
-<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode('àüèàüè') . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
+<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . utf8_encode('������') . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
 ';
         $r = $s->parseResponse($f, false, 'phpvals');
         $v = $r->value();
         $v = $v['content'];
-        $this->assertEquals("àüèàüè", $v);
+        $this->assertEquals("������", $v);
     }
 
     public function testUTF8IntString()
diff --git a/tests/5DemofilesTest.php b/tests/5DemofilesTest.php
new file mode 100644 (file)
index 0000000..be97eeb
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+
+include_once __DIR__ . '/parse_args.php';
+
+class DemoFilesTest extends PHPUnit_Framework_TestCase
+{
+    public $args = array();
+
+    protected $baseUrl;
+
+    protected $testId;
+    /** @var boolean $collectCodeCoverageInformation */
+    protected $collectCodeCoverageInformation;
+    protected $coverageScriptUrl;
+
+    public function run(PHPUnit_Framework_TestResult $result = NULL)
+    {
+        $this->testId = get_class($this) . '__' . $this->getName();
+
+        if ($result === NULL) {
+            $result = $this->createResult();
+        }
+
+        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
+
+        parent::run($result);
+
+        if ($this->collectCodeCoverageInformation) {
+            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
+                $this->coverageScriptUrl,
+                $this->testId
+            );
+            $result->getCodeCoverage()->append(
+                $coverage->get(), $this
+            );
+        }
+
+        // do not call this before to give the time to the Listeners to run
+        //$this->getStrategy()->endOfTest($this->session);
+
+        return $result;
+    }
+
+    public function setUp()
+    {
+        $this->args = argParser::getArgs();
+
+        $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/demo/', $this->args['URI'] );
+
+        $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+    }
+
+    protected function request($file, $method = 'GET', $payload = '')
+    {
+        $url = $this->baseUrl . $file;
+
+        $ch = curl_init($url);
+        curl_setopt_array($ch, array(
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_FAILONERROR => true
+        ));
+        if ($method == 'POST')
+        {
+            curl_setopt_array($ch, array(
+                CURLOPT_POST => true,
+                CURLOPT_POSTFIELDS => $payload
+            ));
+        }
+        if ($this->collectCodeCoverageInformation)
+        {
+            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
+        }
+        $page = curl_exec($ch);
+        curl_close($ch);
+
+        $this->assertNotFalse($page);
+        $this->assertNotContains('Fatal error', $page);
+
+        return $page;
+    }
+
+    public function testAgeSort()
+    {
+        $page = $this->request('client/agesort.php');
+    }
+
+    public function testClient()
+    {
+        $page = $this->request('client/client.php');
+
+        // we could test many more calls to the client demo, but the upstream server is gone anyway...
+
+        $page = $this->request('client/client.php', 'POST', array('stateno' => '1'));
+    }
+
+    public function testComment()
+    {
+        $page = $this->request('client/comment.php');
+        $page = $this->request('client/client.php', 'POST', array('storyid' => '1'));
+    }
+
+    public function testIntrospect()
+    {
+        $page = $this->request('client/introspect.php');
+    }
+
+    public function testMail()
+    {
+        $page = $this->request('client/mail.php');
+        $page = $this->request('client/client.php', 'POST', array(
+            'server' => '',
+            "mailto" => '',
+            "mailsub" => '',
+            "mailmsg" => '',
+            "mailfrom" => '',
+            "mailcc" => '',
+            "mailbcc" => '',
+        ));
+    }
+
+    public function testSimpleCall()
+    {
+        $page = $this->request('client/simple_call.php');
+    }
+
+    public function testWhich()
+    {
+        $page = $this->request('client/which.php');
+    }
+
+    public function testWrap()
+    {
+        $page = $this->request('client/wrap.php');
+    }
+
+    public function testZopeTest()
+    {
+        $page = $this->request('client/zopetest.php');
+    }
+
+    public function testDiscussServer()
+    {
+        $page = $this->request('server/discuss.php');
+        $this->assertContains('<name>faultCode</name>', $page);
+        $this->assertContains('<int>105</int>', $page);
+    }
+
+    public function testProxyServer()
+    {
+        $page = $this->request('server/proxy.php');
+        $this->assertContains('<name>faultCode</name>', $page);
+        $this->assertContains('<int>105</int>', $page);
+    }
+}