First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,54 @@
<?php
namespace CiviDrupal {
use Civi\Test\EndToEndInterface;
/**
* Class HookTest
* @package CiviDrupal
* @group e2e
*/
class HookTest extends \PHPUnit_Framework_TestCase implements EndToEndInterface {
public function testFoo() {
$arg1 = 'hello';
$arg2 = array(
'foo' => 123,
);
$this->assertNotEquals($arg2['foo'], 456);
$this->assertNotEquals($arg2['hook_was_called'], 1);
\CRM_Utils_Hook::singleton()
->invoke(
2,
$arg1,
$arg2,
\CRM_Utils_Hook::$_nullObject,
\CRM_Utils_Hook::$_nullObject,
\CRM_Utils_Hook::$_nullObject,
\CRM_Utils_Hook::$_nullObject,
'civicrm_fakeAlterableHook'
);
$this->assertEquals($arg2['foo'], 456);
$this->assertEquals($arg2['hook_was_called'], 1);
}
}
}
namespace {
function civicrm_civicrm_fakeAlterableHook($arg1, &$arg2) {
if ($arg1 != 'hello') {
throw new \Exception("Failed to receive arg1");
}
if ($arg2['foo'] != 123) {
throw new \Exception("Failed to receive arg2[foo]");
}
$arg2['foo'] = 456;
$arg2['hook_was_called'] = 1;
}
}

View file

@ -0,0 +1,54 @@
<?php
// We switch between a few different container configurations during testing.
define('CIVICRM_CONTAINER_CACHE', 'never');
ini_set('memory_limit', '2G');
ini_set('safe_mode', 0);
eval(cv('php:boot', 'phpcode'));
assert("CIVICRM_UF === 'Drupal'");
/**
* Call the "cv" command.
*
* @param string $cmd
* The rest of the command to send.
* @param string $decode
* Ex: 'json' or 'phpcode'.
* @return string
* Response output (if the command executed normally).
* @throws \RuntimeException
* If the command terminates abnormally.
*/
function cv($cmd, $decode = 'json') {
$cmd = 'cv ' . $cmd;
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR);
$oldOutput = getenv('CV_OUTPUT');
putenv("CV_OUTPUT=json");
$process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__);
putenv("CV_OUTPUT=$oldOutput");
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
if (proc_close($process) !== 0) {
throw new RuntimeException("Command failed ($cmd):\n$result");
}
switch ($decode) {
case 'raw':
return $result;
case 'phpcode':
// If the last output is /*PHPCODE*/, then we managed to complete execution.
if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" || substr(trim($result), -10) !== "/*ENDPHP*/") {
throw new \RuntimeException("Command failed ($cmd):\n$result");
}
return $result;
case 'json':
return json_decode($result, 1);
default:
throw new RuntimeException("Bad decoder format ($decode)");
}
}