Add 'php/phpxmlrpc/' from commit 'cd5dbb4a511e7a616a61187a5de1a611a9748cbd'
[plcapi.git] / php / phpxmlrpc / tests / LocalFileTestCase.php
1 <?php
2
3 include_once __DIR__ . '/parse_args.php';
4
5 abstract class PhpXmlRpc_LocalFileTestCase 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     protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
45     {
46         $url = $this->baseUrl . $file;
47
48         $ch = curl_init($url);
49         curl_setopt_array($ch, array(
50             CURLOPT_RETURNTRANSFER => true,
51             CURLOPT_FAILONERROR => true
52         ));
53         if ($method == 'POST')
54         {
55             curl_setopt_array($ch, array(
56                 CURLOPT_POST => true,
57                 CURLOPT_POSTFIELDS => $payload
58             ));
59         }
60         if ($this->collectCodeCoverageInformation)
61         {
62             curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
63         }
64         if ($this->args['DEBUG'] > 0) {
65             curl_setopt($ch, CURLOPT_VERBOSE, 1);
66         }
67         $page = curl_exec($ch);
68         curl_close($ch);
69
70         $this->assertNotFalse($page);
71         if (!$emptyPageOk) {
72             $this->assertNotEquals('', $page);
73         }
74         $this->assertNotContains('Fatal error', $page);
75         $this->assertNotContains('Notice:', $page);
76
77         return $page;
78     }
79
80 }