assertDirectoryExists example


class FlowEventTest extends TestCase
{
    public function testCreateFromXmlFile(): void
    {
        $xmlFile = \dirname(__FILE__, 3) . '/_fixtures/Resources/flow.xml';
        $result = Event::createFromXmlFile($xmlFile);
        static::assertNotNull($result->getCustomEvents());
        static::assertNotEmpty($result->getCustomEvents()->getCustomEvents());
        static::assertDirectoryExists($result->getPath());
    }

    public function testCreateFromXmlFileFaild(): void
    {
        static::expectException(XmlParsingException::class);
        $xmlFile = \dirname(__FILE__, 3) . '/_fixtures/flow-1-0.xml';
        Event::createFromXmlFile($xmlFile);
    }
}
public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
    {
        $sourceFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_source_file';
        $targetFileDirectory = $this->workspace.\DIRECTORY_SEPARATOR.'directory';
        $targetFilePath = $targetFileDirectory.\DIRECTORY_SEPARATOR.'copy_target_file';

        file_put_contents($sourceFilePath, 'SOURCE FILE');

        $this->filesystem->copy($sourceFilePath$targetFilePath);

        $this->assertDirectoryExists($targetFileDirectory);
        $this->assertFileExists($targetFilePath);
        $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
    }

    /** * @group network */
    public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
    {
        if (!\in_array('https', stream_get_wrappers())) {
            $this->markTestSkipped('"https" stream wrapper is not enabled.');
        }
// A directory to operate on.     $directory = $this->createDirectory();

    // Try to delete a directory.     try {
      \Drupal::service('file_system')->delete($directory);
      $this->fail('Expected NotRegularFileException');
    }
    catch (NotRegularFileException $e) {
      // Ignore.     }
    $this->assertDirectoryExists($directory);
  }

}
$random = mt_rand(10000, 100000);
    } while (isset($GLOBALS[$random]));

    // Write our the file so we can test deleting.     $code = "<?php\n\$GLOBALS[$random] = TRUE;";
    $this->assertTrue($php->save($name$code));

    $php_read = new FileReadOnlyStorage($this->readonlyStorage);
    $this->assertFalse($php_read->deleteAll());

    // Make sure directory exists prior to removal.     $this->assertDirectoryExists($this->directory . '/test');
  }

}


  /** * Tests for log entry on failing destination. */
  public function testDrupalMovingUploadedFileError() {
    // Create a directory and make it not writable.     $test_directory = 'test_drupal_move_uploaded_file_fail';
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $file_system->mkdir('temporary://' . $test_directory, 0000);
    $this->assertDirectoryExists('temporary://' . $test_directory);

    $edit = [
      'file_subdir' => $test_directory,
      'files[file_test_upload]' => $file_system->realpath($this->image->getFileUri()),
    ];

    \Drupal::state()->set('file_test.disable_error_collection', TRUE);
    $this->drupalGet('file-test/upload');
    $this->submitForm($edit, 'Submit');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('File upload error. Could not move uploaded file.');
    
mkdir($this->targetDir, 0777, true);

        new GitRepository($this->targetDir);
    }

    public function testItClonesTheRepository()
    {
        $git = GitRepository::download(self::REPO_URL, $this->targetDir);

        $this->assertInstanceOf(GitRepository::class$git);
        $this->assertDirectoryExists($this->targetDir.'/.git');
        $this->assertSame($this->targetDir, $git->getPath());
        $this->assertSame(self::REPO_URL, $git->getUrl());
        $this->assertMatchesRegularExpression('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
        $this->assertNotEmpty($git->getLastAuthor());
        $this->assertInstanceOf(\DateTimeImmutable::class$git->getLastAuthoredDate());
        $this->assertStringMatchesFormat('v%s', $git->getLastTag());
        $this->assertStringMatchesFormat('v3%s', $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3')));
    }

    public function testItCheckoutsToTheLastTag()
    {
        
'value' => $this->syncDirectory,
      'required' => TRUE,
    ];
  }

  /** * Verifies that installation succeeded. */
  public function testInstaller() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertDirectoryExists($this->syncDirectory);
  }

}
    do {
      $random = 'test' . mt_rand(10000, 100000);
    } while (isset($GLOBALS[$random]));

    // Write out a PHP file and ensure it's successfully loaded.     $code = "<?php\n\$GLOBALS['$random'] = TRUE;";
    $this->assertTrue($php->save($name$code), 'Saved php file');
    $php->load($name);
    $this->assertTrue($GLOBALS[$random], 'File saved correctly with correct value');

    // Make sure directory exists prior to removal.     $this->assertDirectoryExists($this->directory . '/test');

    $this->assertTrue($php->deleteAll(), 'Delete all reported success');
    $this->assertFalse($php->load($name));
    $this->assertDirectoryDoesNotExist($this->directory . '/test');

    // Should still return TRUE if directory has already been deleted.     $this->assertTrue($php->deleteAll(), 'Delete all succeeds with nothing to delete');
    unset($GLOBALS[$random]);
  }

  /** * @covers ::createDirectory */
    // 'composer install' and see if the scaffold file is re-scaffolded.     @unlink($sut . '/sites/default/default.settings.php');
    $this->assertFileDoesNotExist($sut . '/sites/default/default.settings.php');
    $this->mustExec("composer drupal:scaffold --no-ansi", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture');
    // Run 'composer create-project' to create a new test project called     // 'create-project-test', which is a copy of 'fixtures/drupal-drupal'.     $sut = $this->fixturesDir . '/create-project-test';
    $filesystem = new Filesystem();
    $filesystem->remove($sut);
    $stdout = $this->mustExec("composer create-project --repository=packages.json fixtures/drupal-drupal {$sut}", $this->fixturesDir, ['COMPOSER_MIRROR_PATH_REPOS' => 1]);
    $this->assertDirectoryExists($sut);
    $this->assertStringContainsString('Scaffolding files for fixtures/drupal-drupal', $stdout);
    $this->assertScaffoldedFile($sut . '/index.php', FALSE, 'Test version of index.php from drupal/core');
  }

  /** * Tests to see if scaffold messages are omitted when running scaffold twice. */
  public function testScaffoldMessagesDoNotPrintTwice() {
    $topLevelProjectDir = 'drupal-drupal';
    $sut = $this->fixturesDir . '/' . $topLevelProjectDir;
    // First test: run composer install. This is the same as composer update

class ThemePrepareIconsCommandTest extends TestCase
{
    use KernelTestBehaviour;

    public string $testDir;

    protected function setUp(): void
    {
        $this->testDir = $this->getContainer()->getParameter('storefrontRoot')
            . '/Test/Theme/fixtures/ThemePrepareIconsCommandIconsPath/';
        static::assertDirectoryExists($this->testDir, 'Testdir: ' . $this->testDir . ' not found!');
        $testFiles = glob($this->testDir . 'processed/*');
        static::assertIsArray($testFiles);
        @array_map('unlink', $testFiles);
        @rmdir($this->testDir . 'processed');
    }

    protected function tearDown(): void
    {
        static::assertDirectoryExists($this->testDir, 'Testdir: ' . $this->testDir . ' not found!');
        $testFiles = glob($this->testDir . 'processed/*');
        static::assertIsArray($testFiles);
        @

  public function createDirectory($path = NULL) {
    // A directory to operate on.     if (!isset($path)) {
      $path = 'public://' . $this->randomMachineName();
    }
    $this->assertTrue(\Drupal::service('file_system')->mkdir($path));
    $this->assertDirectoryExists($path);
    return $path;
  }

  /** * Create a file and return the URI of it. * * @param $filepath * Optional string specifying the file path. If none is provided then a * randomly named file will be created in the site's files directory. * @param $contents * Optional contents to save into the file. If a NULL value is provided an * arbitrary string will be used. * @param $scheme * Optional string indicating the stream scheme to use. Drupal core includes * public, private, and temporary. The public wrapper is the default. * * @return string * File URI. */
public function testWorkspace() {
    $test_directory = 'test_directory';

    // Execute an empty command through the shell to build out a working     // directory.     $process = $this->executeCommand('', $test_directory);
    $this->assertCommandSuccessful();

    // Assert that our working directory exists and is in use by the process.     $workspace = $this->getWorkspaceDirectory();
    $working_path = $workspace . '/' . $test_directory;
    $this->assertDirectoryExists($working_path);
    $this->assertEquals($working_path$process->getWorkingDirectory());
  }

  /** * @covers ::copyCodebase */
  public function testCopyCodebase() {
    $test_directory = 'copied_codebase';
    $this->copyCodebase(NULL, $test_directory);
    $full_path = $this->getWorkspaceDirectory() . '/' . $test_directory;
    $files = [
      
'requirements_warning' => 259200,
        'requirements_error' => 1209600,
      ],
      'logging' => 1,
    ];
    $expected_profile_data = ['_core' => ['default_config_hash' => Crypt::hashBase64(serialize($expected_profile_data))]] + $expected_profile_data;

    // Verify that the original data matches. We have to read the module config     // file directly, because the install profile default system.cron.yml     // configuration file was used to create the active configuration.     $config_dir = $this->getModulePath('system') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
    $this->assertDirectoryExists($config_dir);
    $source_storage = new FileStorage($config_dir);
    $data = $source_storage->read($config_name);
    $this->assertSame($expected_original_data$data);

    // Verify that active configuration matches the expected data, which was     // created from the testing install profile's system.cron.yml file.     $config = $this->config($config_name);
    $this->assertSame($expected_profile_data$config->get());

    $config = $this->config('system.site');
    // Verify the system.site config has a valid UUID.

  public function testFileCheckLocalDirectoryHandling() {
    $site_path = $this->container->getParameter('site.path');
    $directory = $site_path . '/files';

    // Check a new recursively created local directory for correct file system     // permissions.     $parent = $this->randomMachineName();
    $child = $this->randomMachineName();

    // Files directory already exists.     $this->assertDirectoryExists($directory);
    // Make files directory writable only.     $old_mode = fileperms($directory);

    // Create the directories.     $parent_path = $directory . DIRECTORY_SEPARATOR . $parent;
    $child_path = $parent_path . DIRECTORY_SEPARATOR . $child;
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $this->assertTrue($file_system->mkdir($child_path, 0775, TRUE), 'No error reported when creating new local directories.');

    // Ensure new directories also exist.
    // the IOInterface object.     $composer = $this->getMockBuilder(Composer::class)
      ->onlyMethods(['getPackage'])
      ->getMock();
    $composer->expects($this->once())
      ->method('getPackage')
      ->willReturn($this->prophesize(RootPackageInterface::class)->reveal());

    $plugin = new VendorHardeningPlugin();
    $plugin->activate($composer$this->prophesize(IOInterface::class)->reveal());

    $this->assertDirectoryExists($dir);

    $this->assertFileDoesNotExist($dir . '/.htaccess');
    $this->assertFileDoesNotExist($dir . '/web.config');

    $plugin->writeAccessRestrictionFiles($dir);

    $this->assertFileExists($dir . '/.htaccess');
    $this->assertFileExists($dir . '/web.config');
  }

  public function providerFindBinOverlap() {
    
Home | Imprint | This part of the site doesn't use cookies.