forked from civicrm/cv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootCommandTest.php
67 lines (55 loc) · 2.56 KB
/
BootCommandTest.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
<?php
namespace Civi\Cv\Command;
use Civi\Cv\Util\Process;
/**
* @group std
* @group php
*/
class BootCommandTest extends \Civi\Cv\CivilTestCase {
public function setUp(): void {
parent::setUp();
}
public function testBootFull() {
$phpBoot = Process::runOk($this->cv("php:boot --level=full"));
$this->assertRegExp(';CIVICRM_SETTINGS_PATH;', $phpBoot->getOutput());
$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'printf("count is %s\n", CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_contact"));'
. 'printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^count is [0-9]+\n/', $phpRun->getOutput());
$this->assertRegExp('/my admin is \w+\n/', $phpRun->getOutput());
}
public function testBootCmsFull() {
$phpBoot = Process::runOk($this->cv("php:boot --level=cms-full"));
$this->assertRegExp(';BEGINPHP;', $phpBoot->getOutput());
$this->assertRegExp(';ENDPHP;', $phpBoot->getOutput());
$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'printf("count is %s\n", CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_contact"));'
. 'printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^count is [0-9]+\n/', $phpRun->getOutput());
$this->assertRegExp('/my admin is \w+\n/', $phpRun->getOutput());
}
public function testBootClassLoader() {
$phpBoot = Process::runOk($this->cv("php:boot --level=classloader"));
$this->assertRegExp(';ClassLoader;', $phpBoot->getOutput());
// In the classloader level, config vals like CIVICRM_DSN are not loaded.
$helloPhp = escapeshellarg($phpBoot->getOutput()
. '$x=array("a"=>defined("CIVICRM_DSN") ? "yup" : "nope");'
. 'printf("phpr says %s\n", CRM_Utils_Array::value("a",$x));'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^phpr says nope$/', $phpRun->getOutput());
}
public function testBootTest() {
$phpBoot = Process::runOk($this->cv("php:boot --test"));
$this->assertRegExp(';CIVICRM_SETTINGS_PATH;', $phpBoot->getOutput());
$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'echo CIVICRM_UF;'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -ddisplay_errors=1 -r $helloPhp"));
$this->assertRegExp('/UnitTests/i', $phpRun->getOutput());
}
}