AbstractDrupalBootTest.php in X Autoload 7.5
File
tests/src/DrupalBootTest/AbstractDrupalBootTest.php
View source
<?php
namespace Drupal\xautoload\Tests\DrupalBootTest;
use Drupal\xautoload\Tests\Example\AbstractExampleModules;
use Drupal\xautoload\Tests\VirtualDrupal\DrupalEnvironment;
use Drupal\xautoload\Tests\Util\CallLog;
use Drupal\xautoload\Tests\Util\StaticCallLog;
abstract class AbstractDrupalBootTest extends \PHPUnit_Framework_TestCase {
protected $exampleDrupal;
protected $exampleModules;
protected $callLog;
protected function providerArrayKeyVariations(array $bases, $key, array $values) {
$result = array();
foreach ($bases as $variation) {
foreach ($values as $value) {
$variation[$key] = $value;
$result[] = $variation;
}
}
return $result;
}
function testNormalRequest() {
$this
->prepare();
$this
->prepareAllEnabled();
$this->exampleDrupal
->boot();
$expectedCalls = $this
->getExpectedCallsForNormalRequest();
$this->callLog
->assertCalls($this, $expectedCalls);
foreach ($this->exampleModules
->getExampleClasses() as $classes) {
foreach ((array) $classes as $class) {
$this
->assertClassExists($class);
}
}
$this
->unprepare();
}
function testModuleEnable(array $initialModules, array $expectedCalls) {
$this
->prepare();
$this
->prepareInitialModules($initialModules);
foreach ($this->exampleModules
->getExampleClasses() as $classes) {
foreach ((array) $classes as $class) {
$this
->assertClassIsUndefined($class);
}
}
$this->exampleDrupal
->boot();
$new_modules = array_keys($this->exampleModules
->getExampleClasses());
$this->exampleDrupal
->moduleEnable($new_modules);
$this->callLog
->assertCalls($this, $expectedCalls);
foreach ($this->exampleModules
->getExampleClasses() as $classes) {
foreach ((array) $classes as $class) {
$this
->assertClassExists($class);
}
}
$this
->unprepare();
}
public abstract function providerModuleEnable();
private function prepareAllEnabled() {
foreach (array(
'system',
'xautoload',
'libraries',
) as $name) {
$this->exampleDrupal
->getSystemTable()
->moduleSetEnabled($name);
}
foreach ($this->exampleModules
->getExampleClasses() as $name => $classes) {
$this->exampleDrupal
->getSystemTable()
->moduleSetEnabled($name);
}
$this->exampleDrupal
->getSystemTable()
->moduleSetWeight('xautoload', -90);
}
private function prepareInitialModules($initialModules) {
foreach ($initialModules as $name => $state) {
if (TRUE === $state) {
$this->exampleDrupal
->getSystemTable()
->moduleSetEnabled($name);
$this->exampleDrupal
->getSystemTable()
->moduleSetSchemaVersion($name, 7000);
}
elseif (FALSE === $state) {
$this->exampleDrupal
->getSystemTable()
->moduleSetSchemaVersion($name, 7000);
}
elseif (NULL === $state) {
}
else {
throw new \Exception("Unexpected state.");
}
}
if (isset($initialModules['xautoload'])) {
$this->exampleDrupal
->getSystemTable()
->moduleSetWeight('xautoload', -90);
}
}
protected abstract function prepare();
private function unprepare() {
stream_wrapper_unregister('test');
StaticCallLog::unsetCallLog();
}
public function assertLoadClass($class) {
$this
->assertFalse(class_exists($class, FALSE), "Class '{$class}' is not defined yet.");
$this
->assertTrue(class_exists($class), "Class '{$class}' successfully loaded.");
}
public function assertClassExists($class) {
$this
->assertTrue(class_exists($class), "Class '{$class}' exists.");
}
public function assertClassIsDefined($class) {
$this
->assertTrue(class_exists($class, FALSE), "Class '{$class}' is defined.");
}
public function assertClassIsUndefined($class) {
$this
->assertFalse(class_exists($class, FALSE), "Class '{$class}' is undefined.");
}
protected abstract function getExpectedCallsForNormalRequest();
}