13160c71ce4739e20818bbf552e1b7a8b16d318d
[plcapi.git] / tests / LocalFileTestCase.php
1 <?php
2
3 include_once __DIR__ . '/parse_args.php';
4
5 include_once __DIR__ . '/PolyfillTestCase.php';
6
7 abstract class PhpXmlRpc_LocalFileTestCase extends PhpXmlRpc_PolyfillTestCase
8 {
9     public $args = array();
10
11     protected $baseUrl;
12
13     protected $testId;
14     /** @var boolean $collectCodeCoverageInformation */
15     protected $collectCodeCoverageInformation;
16     protected $coverageScriptUrl;
17
18     public function _run($result = NULL)
19     {
20         $this->testId = get_class($this) . '__' . $this->getName();
21
22         if ($result === NULL) {
23             $result = $this->createResult();
24         }
25
26         $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
27
28         parent::_run($result);
29
30         if ($this->collectCodeCoverageInformation) {
31             $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
32                 $this->coverageScriptUrl,
33                 $this->testId
34             );
35             $result->getCodeCoverage()->append(
36                 $coverage->get(), $this
37             );
38         }
39
40         // do not call this before to give the time to the Listeners to run
41         //$this->getStrategy()->endOfTest($this->session);
42
43         return $result;
44     }
45
46     protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
47     {
48         $url = $this->baseUrl . $file;
49
50         $ch = curl_init($url);
51         curl_setopt_array($ch, array(
52             CURLOPT_RETURNTRANSFER => true,
53             CURLOPT_FAILONERROR => true
54         ));
55         if ($method == 'POST')
56         {
57             curl_setopt_array($ch, array(
58                 CURLOPT_POST => true,
59                 CURLOPT_POSTFIELDS => $payload
60             ));
61         }
62         if ($this->collectCodeCoverageInformation)
63         {
64             curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
65         }
66         if ($this->args['DEBUG'] > 0) {
67             curl_setopt($ch, CURLOPT_VERBOSE, 1);
68         }
69         $page = curl_exec($ch);
70         curl_close($ch);
71
72         $this->assertNotFalse($page);
73         if (!$emptyPageOk) {
74             $this->assertNotEquals('', $page);
75         }
76         $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
77         $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);
78
79         return $page;
80     }
81
82 }