protected function setUp()
 {
     parent::setUp();
     module_load_install('system');
     $schema = system_schema();
     db_create_table('key_value_expire', $schema['key_value_expire']);
 }
예제 #2
0
 protected function setUp()
 {
     parent::setUp();
     // Install system tables to test the key/value storage without installing a
     // full Drupal environment.
     module_load_install('system');
     $schema = system_schema();
     db_create_table('semaphore', $schema['semaphore']);
     db_create_table('key_value_expire', $schema['key_value_expire']);
     // Create several objects for testing.
     for ($i = 0; $i <= 3; $i++) {
         $this->objects[$i] = $this->randomObject();
     }
 }
예제 #3
0
 protected function setUp()
 {
     parent::setUp();
     $this->container = new ContainerBuilder();
     $this->container->register('service_container', 'Symfony\\Component\\DependencyInjection\\ContainerBuilder')->setSynthetic(TRUE);
     $this->container->set('service_container', $this->container);
     $this->container->register('settings', 'Drupal\\Core\\Site\\Settings')->setFactoryClass('Drupal\\Core\\Site\\Settings')->setFactoryMethod('getInstance');
     $this->container->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')->addArgument(new Reference('service_container'))->addArgument(new Reference('settings'));
     $this->container->register('keyvalue.expirable', 'Drupal\\Core\\KeyValueStore\\KeyValueExpirableFactory')->addArgument(new Reference('service_container'))->addArgument(new Reference('settings'));
     // Define two data collections,
     $this->collections = array(0 => 'zero', 1 => 'one');
     // Create several objects for testing.
     for ($i = 0; $i <= 5; $i++) {
         $this->objects[$i] = $this->randomObject();
     }
 }
예제 #4
0
 function setUp()
 {
     parent::setUp();
     $this->key = 'default';
     $this->originalTarget = 'default';
     $this->target = 'DatabaseConnectionUnitTest';
     // Determine whether the database driver is MySQL. If it is not, the test
     // methods will not be executed.
     // @todo Make this test driver-agnostic, or find a proper way to skip it.
     // @see http://drupal.org/node/1273478
     $connection_info = Database::getConnectionInfo('default');
     $this->skipTest = (bool) ($connection_info['default']['driver'] != 'mysql');
     if ($this->skipTest) {
         // Insert an assertion to prevent Simpletest from interpreting the test
         // as failure.
         $this->pass('This test is only compatible with MySQL.');
     }
     // Create an additional connection to monitor the connections being opened
     // and closed in this test.
     // @see TestBase::changeDatabasePrefix()
     Database::addConnectionInfo('default', 'monitor', $connection_info['default']);
     $this->monitor = Database::getConnection('monitor');
 }
예제 #5
0
 function setUp()
 {
     parent::setUp();
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->keyValueFactory = new KeyValueMemoryFactory();
     // Allow for test-specific overrides.
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
         // Copy the testing-specific service overrides in place.
         copy($settings_services_file, DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml');
     }
     parent::setUp();
     // Create and set new configuration directories.
     $this->prepareConfigDirectories();
     // Add this test class as a service provider.
     // @todo Remove the indirection; implement ServiceProviderInterface instead.
     $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\\simpletest\\TestServiceProvider';
     // Back up settings from TestBase::prepareEnvironment().
     $settings = Settings::getAll();
     // Bootstrap a new kernel. Don't use createFromRequest so we don't mess with settings.
     $this->kernel = new DrupalKernel('testing', drupal_classloader(), FALSE);
     $request = Request::create('/');
     $this->kernel->setSitePath(DrupalKernel::findSitePath($request));
     $this->kernel->boot();
     // Restore and merge settings.
     // DrupalKernel::boot() initializes new Settings, and the containerBuild()
     // method sets additional settings.
     new Settings($settings + Settings::getAll());
     // Set the request scope.
     $this->container = $this->kernel->getContainer();
     $this->container->get('request_stack')->push($request);
     $this->container->get('state')->set('system.module.files', $this->moduleFiles);
     $this->container->get('state')->set('system.theme.files', $this->themeFiles);
     // Create a minimal core.extension configuration object so that the list of
     // enabled modules can be maintained allowing
     // \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() to work.
     // Write directly to active storage to avoid early instantiation of
     // the event dispatcher which can prevent modules from registering events.
     \Drupal::service('config.storage')->write('core.extension', array('module' => array(), 'theme' => array()));
     // Collect and set a fixed module list.
     $class = get_class($this);
     $modules = array();
     while ($class) {
         if (property_exists($class, 'modules')) {
             // Only add the modules, if the $modules property was not inherited.
             $rp = new \ReflectionProperty($class, 'modules');
             if ($rp->class == $class) {
                 $modules[$class] = $class::$modules;
             }
         }
         $class = get_parent_class($class);
     }
     // Modules have been collected in reverse class hierarchy order; modules
     // defined by base classes should be sorted first. Then, merge the results
     // together.
     $modules = array_reverse($modules);
     $modules = call_user_func_array('array_merge_recursive', $modules);
     if ($modules) {
         $this->enableModules($modules);
     }
     // In order to use theme functions default theme config needs to exist.
     \Drupal::config('system.theme')->set('default', 'stark');
     // Tests based on this class are entitled to use Drupal's File and
     // StreamWrapper APIs.
     // @todo Move StreamWrapper management into DrupalKernel.
     // @see https://drupal.org/node/2028109
     $this->streamWrappers = array();
     // The public stream wrapper only depends on the file_public_path setting,
     // which is provided by UnitTestBase::setUp().
     $this->registerStreamWrapper('public', 'Drupal\\Core\\StreamWrapper\\PublicStream');
     // The temporary stream wrapper is able to operate both with and without
     // configuration.
     $this->registerStreamWrapper('temporary', 'Drupal\\Core\\StreamWrapper\\TemporaryStream');
 }