/**
  * Test hook_registry_files_alter() wildcard replacement.
  */
 public function testWildcardClassmap()
 {
     $this->filesystem->addClass('test://lib/xy/z.php', 'Foo\\Bar');
     $this->assertFalse(class_exists('Foo\\Bar', FALSE), 'Class Foo\\Bar must not exist yet.');
     xautoload()->adapter->addClassmapSources(array('test://lib/**/*.php'));
     $this->assertTrue(class_exists('Foo\\Bar'), 'Class Foo\\Bar must exist.');
 }
 /**
  * Tests a simulated regular request.
  */
 function testNormalRequest()
 {
     // Create virtual class files.
     $this->filesystem->addClass('test://modules/testmod_psr0/lib/Drupal/testmod_psr0/Foo.php', 'Drupal\\testmod_psr0\\Foo');
     $this->filesystem->addClass('test://modules/testmod_psr4/lib/Foo.php', 'Drupal\\testmod_psr4\\Foo');
     $this->filesystem->addClass('test://modules/testmod_pearflat/lib/Foo.php', 'testmod_pearflat_Foo');
     $this->assertTrue(file_exists('test://modules/testmod_psr0/lib/Drupal/testmod_psr0/Foo.php'), 'Stream wrapper file exists.');
     $services = xautoload()->getServiceContainer();
     // Mock out DrupalSystem in the service container.
     $extensions = $this->getExampleExtensions();
     $system = new MockDrupalSystem(array(), $extensions);
     $services->set('system', $system);
     // Simulate _xautoload_register_drupal().
     // No cache is active.
     // Initialize the finder, to fire scheduled operations.
     $services->proxyFinder->getFinder();
     // Register prefixes and namespaces for enabled extensions.
     $operation = new FinderOperation\BootPhase($extensions);
     $services->proxyFinder->onFinderInit($operation);
     // Simulate inclusion of other module files.
     // The testmod_psr4.module must contain an equivalent to the following line,
     // to tell xautoload that PSR-4 is in action:
     $services->main->registerModulePsr4('test://modules/testmod_psr4/testmod_psr4.module', 'lib');
     // Boot modules use their classes.
     $this->assertLoadClass('Drupal\\testmod_psr0\\Foo');
     $this->assertLoadClass('Drupal\\testmod_psr4\\Foo');
     $this->assertLoadClass('testmod_pearflat_Foo');
 }
Пример #3
0
 /**
  * Assert that inclusions are done in the expected order.
  *
  * @param \Drupal\xautoload\ClassLoader\ClassLoaderInterface $loader
  * @param string $class
  * @param string[] $expectedCandidates
  */
 protected function assertFileInclusions($loader, $class, array $expectedCandidates)
 {
     // Register the class file in the virtual filesystem.
     $this->filesystem->addClass(end($expectedCandidates), $class);
     $this->filesystem->resetReportedOperations();
     // Check that the class is not already defined.
     $this->assertFalse(class_exists($class, FALSE), "Class '{$class}' is not defined before loadClass().");
     // Trigger the class loader.
     $loader->loadClass($class);
     $expectedOperations = array();
     foreach ($expectedCandidates as $file) {
         $expectedOperations[] = $file . ' - stat';
     }
     $expectedOperations[] = end($expectedCandidates) . ' - include';
     $this->assertSame($expectedOperations, $this->filesystem->getReportedOperations());
     // Check that the class is defined after the class loader has done its job.
     $this->assertTrue(class_exists($class, FALSE), "Class is defined after loadClass().");
 }