Add tests for the demo files not to have fatal errors
[plcapi.git] / tests / 5DemofilesTest.php
1 <?php
2
3 include_once __DIR__ . '/parse_args.php';
4
5 class DemoFilesTest extends PHPUnit_Framework_TestCase
6 {
7     public $args = array();
8
9     protected $baseUrl;
10
11     protected $testId;
12     /** @var boolean $collectCodeCoverageInformation */
13     protected $collectCodeCoverageInformation;
14     protected $coverageScriptUrl;
15
16     public function run(PHPUnit_Framework_TestResult $result = NULL)
17     {
18         $this->testId = get_class($this) . '__' . $this->getName();
19
20         if ($result === NULL) {
21             $result = $this->createResult();
22         }
23
24         $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
25
26         parent::run($result);
27
28         if ($this->collectCodeCoverageInformation) {
29             $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
30                 $this->coverageScriptUrl,
31                 $this->testId
32             );
33             $result->getCodeCoverage()->append(
34                 $coverage->get(), $this
35             );
36         }
37
38         // do not call this before to give the time to the Listeners to run
39         //$this->getStrategy()->endOfTest($this->session);
40
41         return $result;
42     }
43
44     public function setUp()
45     {
46         $this->args = argParser::getArgs();
47
48         $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/demo/', $this->args['URI'] );
49
50         $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
51     }
52
53     protected function request($file, $method = 'GET', $payload = '')
54     {
55         $url = $this->baseUrl . $file;
56
57         $ch = curl_init($url);
58         curl_setopt_array($ch, array(
59             CURLOPT_RETURNTRANSFER => true,
60             CURLOPT_FAILONERROR => true
61         ));
62         if ($method == 'POST')
63         {
64             curl_setopt_array($ch, array(
65                 CURLOPT_POST => true,
66                 CURLOPT_POSTFIELDS => $payload
67             ));
68         }
69         if ($this->collectCodeCoverageInformation)
70         {
71             curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
72         }
73         $page = curl_exec($ch);
74         curl_close($ch);
75
76         $this->assertNotFalse($page);
77         $this->assertNotContains('Fatal error', $page);
78
79         return $page;
80     }
81
82     public function testAgeSort()
83     {
84         $page = $this->request('client/agesort.php');
85     }
86
87     public function testClient()
88     {
89         $page = $this->request('client/client.php');
90
91         // we could test many more calls to the client demo, but the upstream server is gone anyway...
92
93         $page = $this->request('client/client.php', 'POST', array('stateno' => '1'));
94     }
95
96     public function testComment()
97     {
98         $page = $this->request('client/comment.php');
99         $page = $this->request('client/client.php', 'POST', array('storyid' => '1'));
100     }
101
102     public function testIntrospect()
103     {
104         $page = $this->request('client/introspect.php');
105     }
106
107     public function testMail()
108     {
109         $page = $this->request('client/mail.php');
110         $page = $this->request('client/client.php', 'POST', array(
111             'server' => '',
112             "mailto" => '',
113             "mailsub" => '',
114             "mailmsg" => '',
115             "mailfrom" => '',
116             "mailcc" => '',
117             "mailbcc" => '',
118         ));
119     }
120
121     public function testSimpleCall()
122     {
123         $page = $this->request('client/simple_call.php');
124     }
125
126     public function testWhich()
127     {
128         $page = $this->request('client/which.php');
129     }
130
131     public function testWrap()
132     {
133         $page = $this->request('client/wrap.php');
134     }
135
136     public function testZopeTest()
137     {
138         $page = $this->request('client/zopetest.php');
139     }
140
141     public function testDiscussServer()
142     {
143         $page = $this->request('server/discuss.php');
144         $this->assertContains('<name>faultCode</name>', $page);
145         $this->assertContains('<int>105</int>', $page);
146     }
147
148     public function testProxyServer()
149     {
150         $page = $this->request('server/proxy.php');
151         $this->assertContains('<name>faultCode</name>', $page);
152         $this->assertContains('<int>105</int>', $page);
153     }
154 }