forked from civicrm/cv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvalCommandTest.php
105 lines (85 loc) · 3.32 KB
/
EvalCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Civi\Cv\Command;
use Civi\Cv\Util\Process;
/**
* @group std
* @group php
*/
class EvalCommandTest extends \Civi\Cv\CivilTestCase {
public function setUp(): void {
parent::setUp();
}
public function testEv() {
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}
public function testPhpEval() {
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}
public function testPhpEval_Exit0() {
$p = Process::runDebug($this->cv("ev 'exit(0);'"));
$this->assertEquals(0, $p->getExitCode());
}
public function testPhpEval_Exit1() {
$p = Process::runDebug($this->cv("ev 'exit(1);'"));
$this->assertEquals(1, $p->getExitCode());
}
public function testPhpEval_ExitCodeError() {
$p = Process::runDebug($this->cv("ev 'invalid();'"));
$this->assertEquals(255, $p->getExitCode());
}
public function testPhpEval_CvVar_Full() {
$helloPhp = escapeshellarg('printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);');
$p = Process::runOk($this->cv("ev --level=full $helloPhp"));
$this->assertRegExp('/^my admin is \w+\s*$/', $p->getOutput());
}
public function testPhpEval_CvVar_CmsFull() {
$helloPhp = escapeshellarg('printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);');
$p = Process::runOk($this->cv("ev --level=cms-full $helloPhp"));
$this->assertRegExp('/^my admin is \w+\s*$/', $p->getOutput());
}
public function testBoot() {
$checkBoot = escapeshellarg('echo (function_exists("drupal_add_js") || function_exists("wp_redirect") || class_exists("JFactory") || class_exists("Drupal")) ? "found" : "not-found";');
$p1 = Process::runOk($this->cv("ev $checkBoot"));
$this->assertRegExp('/^found$/', $p1->getOutput());
}
public function getLevels() {
return [
['settings'],
['classloader'],
['full'],
['cms-only'],
['cms-full'],
];
}
/**
* @param string $level
* @dataProvider getLevels
*/
public function testBootLevels($level) {
$checkBoot = escapeshellarg('echo "Hello world";');
$p1 = Process::runOk($this->cv("ev $checkBoot --level=$level"));
$this->assertRegExp('/^Hello world/', $p1->getOutput());
}
public function testTestMode() {
$checkUf = escapeshellarg('return CIVICRM_UF;');
$p1 = Process::runOk($this->cv("ev $checkUf"));
$this->assertRegExp('/(Drupal|Joomla|WordPress|Backdrop)/i', $p1->getOutput());
$p1 = Process::runOk($this->cv("ev -t $checkUf"));
$this->assertRegExp('/UnitTests/i', $p1->getOutput());
}
/**
* Tests --cwd option.
*/
public function testEvalWithCwdOption() {
// Go somewhere else, where cv won't work.
chdir(sys_get_temp_dir());
$cwdOpt = "--cwd=" . escapeshellarg($this->getExampleDir());
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $cwdOpt $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}
}