getDrupalRoot example

    // current core stability. For example, if we've already released a beta on     // the branch, ensure that we no longer allow alpha dependencies.     $this->assertGreaterThanOrEqual(array_search($this->getCoreStability()static::STABILITY_ORDER)array_search(static::MINIMUM_STABILITY, static::STABILITY_ORDER));

    // Ensure that static::MINIMUM_STABILITY is the same as the least stable     // dependency.     // - We can't set it stricter than our least stable dependency.     // - We don't want to set it looser than we need to, because we don't want     // to in the future accidentally commit a dependency that regresses our     // actual stability requirement without us explicitly changing this     // constant.     $root = $this->getDrupalRoot();
    $process = $this->executeCommand("composer --working-dir=$root info --format=json");
    $this->assertCommandSuccessful();
    $installed = json_decode($process->getOutput(), TRUE);

    // A lookup of the numerical position of each of the stability terms.     $stability_order_indexes = array_flip(static::STABILITY_ORDER);

    $minimum_stability_order_index = $stability_order_indexes[static::MINIMUM_STABILITY];

    $exclude = [
      'drupal/core',
      
$this->container->get('config.factory')->getEditable('system.theme')->set('default', 'stark')->save();
  }

  /** * {@inheritdoc} */
  public static function setUpBeforeClass(): void {
    parent::setUpBeforeClass();

    // @todo Once block_rebuild() is refactored to auto-loadable code, remove     // this require statement.     require_once static::getDrupalRoot() . '/core/modules/block/block.module';
  }

  /** * @covers ::block_rebuild */
  public function testRebuildNoBlocks() {
    block_rebuild();
    $messages = \Drupal::messenger()->all();
    \Drupal::messenger()->deleteAll();
    $this->assertEquals([]$messages);
  }

  

  public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL) {
    $working_path = $this->getWorkingPath($working_dir);

    if ($iterator === NULL) {
      $iterator = $this->getCodebaseFinder()->getIterator();
    }

    $fs = new SymfonyFilesystem();
    $options = ['override' => TRUE, 'delete' => FALSE];
    $fs->mirror($this->getDrupalRoot()$working_path$iterator$options);
  }

  /** * Get a default Finder object for a Drupal codebase. * * This method can be used two ways: * - Override this method and provide your own default Finder object for * copyCodebase(). * - Call the method to get a default Finder object which can then be * modified for other purposes. * * @return \Symfony\Component\Finder\Finder * A Finder object ready to iterate over core codebase. */
/** * @group Composer * @requires externalCommand composer */
class ComposerValidateTest extends BuildTestBase {

  use ComposerIntegrationTrait;

  public function provideComposerJson() {
    $data = [];
    $composer_json_finder = $this->getComposerJsonFinder($this->getDrupalRoot());
    foreach ($composer_json_finder->getIterator() as $composer_json) {
      $data[] = [$composer_json->getPathname()];
    }
    return $data;
  }

  /** * @dataProvider provideComposerJson */
  public function testValidateComposer($path) {
    $this->executeCommand('composer validate --strict --no-check-all ' . $path);
    


    $missingRequirements = Test::getMissingRequirements(
      static::class,
      $this->getName(FALSE)
    );

    if (!empty($missingRequirements)) {
      $this->markTestSkipped(implode(PHP_EOL, $missingRequirements));
    }

    $root = static::getDrupalRoot();

    // Check if required dependencies exist.     $annotations = Test::parseTestMethodAnnotations(
      static::class,
      $this->getName()
    );
    if (!empty($annotations['class']['requires'])) {
      $this->checkModuleRequirements($root$annotations['class']['requires']);
    }
    if (!empty($annotations['method']['requires'])) {
      $this->checkModuleRequirements($root$annotations['method']['requires']);
    }
/** * Provides an array with relative paths to the component paths. * * @return array * An array with relative paths to the component paths. */
  public function provideComponentPaths(): array {
    $data = [];
    // During the dataProvider phase, there is not a workspace directory yet.     // So we will find relative paths and assemble them with the workspace     // path later.     $drupal_root = $this->getDrupalRoot();
    $composer_json_finder = $this->getComponentPathsFinder($drupal_root);

    /** @var \Symfony\Component\Finder\SplFileInfo $path */
    foreach ($composer_json_finder->getIterator() as $path) {
      $data[] = ['/' . $path->getRelativePath()];
    }
    return $data;
  }

  /** * Test whether components' composer.json can be installed in isolation. * * @dataProvider provideComponentPaths */
clearstatcache(TRUE, $destination_path);
    $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
    $this->assertGreaterThan($timestamp$modified_timestamp);
  }

  /** * Provides the source and destination path files. */
  public function providerSuccessfulReuse() {
    return [
      [
        'local_source_path' => static::getDrupalRoot() . '/core/tests/fixtures/files/image-test.jpg',
        'local_destination_path' => 'public://file1.jpg',
      ],
      [
        'remote_source_path' => 'https://www.drupal.org/favicon.ico',
        'remote_destination_path' => 'public://file2.jpg',
      ],
    ];
  }

  /** * Tests successful moves. */


    // Mock the resource fetcher so that it will return our fake resource.     $resource_fetcher = $this->prophesize(ResourceFetcherInterface::class);
    $resource_fetcher->fetchResource(Argument::any())
      ->willReturn($resource);
    $this->container->set('media.oembed.resource_fetcher', $resource_fetcher->reveal());

    // The source plugin will try to fetch the remote thumbnail, so mock the     // HTTP client to ensure that request returns a response with some valid     // image data.     $data = Utils::tryFopen($this->getDrupalRoot() . '/core/misc/druplicon.png', 'r');
    $response = new Response(200, $thumbnail_headers, Utils::streamFor($data));
    $handler = new MockHandler([$response]);
    $client = new Client([
      'handler' => new HandlerStack($handler),
    ]);
    $this->container->set('http_client', $client);

    $media_type = $this->createMediaType('oembed:video');
    $source = $media_type->getSource();

    // Add some HTML to the global site slogan, and use the site:slogan token in
$files = @scandir($full_path)) && count($files) <= 2,
      'Directory is not empty: ' . implode(', ', $files)
    );

    $base->tearDown();
  }

  /** * @covers ::findAvailablePort */
  public function testPortMany() {
    $iterator = (new Finder())->in($this->getDrupalRoot())
      ->ignoreDotFiles(FALSE)
      ->exclude(['sites/simpletest'])
      ->path('/^.ht.router.php$/')
      ->getIterator();
    $this->copyCodebase($iterator);
    /** @var \Symfony\Component\Process\Process[] $processes */
    $processes = [];
    $count = 15;
    for ($i = 0; $i <= $count$i++) {
      $port = $this->findAvailablePort();
      $this->assertArrayNotHasKey($port$processes, 'Port ' . $port . ' was already in use by a process.');
      

class DrupalKernelTest extends KernelTestBase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    // Do not invoke KernelTestBase::setUp(), since that would set up further     // environment aspects, which would distort this test, because it tests the     // DrupalKernel (re-)building itself.     $this->root = static::getDrupalRoot();
    $this->bootEnvironment();
  }

  /** * Build a kernel for testings. * * Because the bootstrap is in DrupalKernel::boot and that involved loading * settings from the filesystem we need to go to extra lengths to build a kernel * for testing. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object to use in booting the kernel. * @param array $modules_enabled * A list of modules to enable on the kernel. * * @return \Drupal\Core\DrupalKernel * New kernel for testing. */
    'config_test.dynamic.system',
  ];

  /** * {@inheritdoc} */
  public static function setUpBeforeClass(): void {
    parent::setUpBeforeClass();
    VarDumper::setHandler(TestVarDumper::class D '::cliHandler');

    // Change the current dir to DRUPAL_ROOT.     chdir(static::getDrupalRoot());
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Allow tests to compare MarkupInterface objects via assertEquals().     $this->registerComparator(new MarkupInterfaceComparator());

    

  protected Connection $connection;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    // Find the current SUT database driver from the connection info. If that     // is not the one the test requires, skip before test database     // initialization so to save cycles.     $this->root = static::getDrupalRoot();
    $connectionInfo = $this->getDatabaseConnectionInfo();
    $test_class_parts = explode('\\', get_class($this));
    $expected_provider = $test_class_parts[2] ?? '';
    for ($i = 3; $i < count($test_class_parts)$i++) {
      if ($test_class_parts[$i] === 'Kernel') {
        $expected_driver = $test_class_parts[$i + 1] ?? '';
        break;
      }
    }
    if ($connectionInfo['default']['driver'] !== $expected_driver) {
      $this->markTestSkipped("This test only runs for the database driver '$expected_driver'. Current database driver is '{$connectionInfo['default']['driver']}'.");
    }
Home | Imprint | This part of the site doesn't use cookies.