assertFileDoesNotExist example

$request = new Request([][][][][][]$content);
        $request->query->set('extension', 'png');
        $request->request->set('url', $url);

        $fileFetcher = new FileFetcher(new FileUrlValidator(), true, false, 5000);

        $this->expectException(MediaException::class);
        $this->expectExceptionMessage('Source file exceeds maximum file size limit.');

        $mediaFile = $fileFetcher->fetchFileFromURL($request$tempFile);
        static::assertEquals(0, $mediaFile->getFileSize());
        static::assertFileDoesNotExist($tempFile);
    }

    public function testUrlUploadLimitDoesNotAffectRequestUpload(): void
    {
        $tempFile = (string) tempnam(sys_get_temp_dir(), '');

        $content = fopen(self::TEST_IMAGE, 'rb');
        static::assertIsResource($content);

        $request = new Request([][][][][][]$content);
        $request->query->set('extension', 'png');

        
// Test directory permission modification.       $this->setSetting('file_chmod_directory', 0777);
      $this->assertTrue($file_system->prepareDirectory($directory, FileSystemInterface::MODIFY_PERMISSIONS), 'No error reported when making directory writable.');
    }

    // Test that the directory has the correct permissions.     $this->assertDirectoryPermissions($directory, 0777, 'file_chmod_directory setting is respected.');

    // Remove .htaccess file to then test that it gets re-created.     @$file_system->unlink($default_scheme . '://.htaccess');
    $this->assertFileDoesNotExist($default_scheme . '://.htaccess');
    $this->container->get('file.htaccess_writer')->ensure();
    $this->assertFileExists($default_scheme . '://.htaccess');

    // Remove .htaccess file again to test that it is re-created by a cron run.     @$file_system->unlink($default_scheme . '://.htaccess');
    $this->assertFileDoesNotExist($default_scheme . '://.htaccess');
    system_cron();
    $this->assertFileExists($default_scheme . '://.htaccess');

    // Verify contents of .htaccess file.     $file = file_get_contents($default_scheme . '://.htaccess');
    
class AppendOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());

    // Create a file.     file_put_contents($destination->fullPath(), "# This is a test\n");

    $prepend = $fixtures->sourcePath('drupal-drupal-test-append', 'prepend-to-robots.txt');
    $append = $fixtures->sourcePath('drupal-drupal-test-append', 'append-to-robots.txt');
    $sut = new AppendOp($prepend$append, TRUE);
    $sut->scaffoldAtNewLocation($destination);

    $expected = <<<EOT # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture. # This content is prepended to the top of the existing robots.txt fixture. # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This is a test # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This content is appended to the bottom of the existing robots.txt fixture. # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture.

    public function testCommandFailsWithInvalidInput(array $input, string $expectedMessage): void
    {
        $commandTester = $this->getCommandTester();

        $commandTester->execute($input);

        static::assertFileDoesNotExist($this->appDir . '/TestApp/manifest.xml');

        static::assertStringContainsString(
            $expectedMessage,
            (string) preg_replace('/\s+/', ' ', trim($commandTester->getDisplay(true)))
        );
    }

    public static function invalidInputProvider(): \Generator
    {
        yield 'invalid_name' => [
            [
                
    $this->fixtures->runComposer("install --no-ansi --no-scripts --no-plugins", $sut);
    return $sut;
  }

  /** * Tests scaffold command correctly manages the .gitignore file. */
  public function testManageGitIgnore() {
    // Note that the drupal-composer-drupal-project fixture does not     // have any configuration settings related to .gitignore management.     $sut = $this->createSutWithGit('drupal-composer-drupal-project');
    $this->assertFileDoesNotExist($sut . '/docroot/autoload.php');
    $this->assertFileDoesNotExist($sut . '/docroot/index.php');
    $this->assertFileDoesNotExist($sut . '/docroot/sites/.gitignore');
    // Run the scaffold command.     $this->fixtures->runScaffold($sut);
    $this->assertFileExists($sut . '/docroot/autoload.php');
    $this->assertFileExists($sut . '/docroot/index.php');
    $expected = <<<EOT /build /.csslintrc /.editorconfig /.eslintignore /.eslintrc.json /.gitattributes /.ht.router.php /autoload.php /index.php /robots.txt /update.php /web.config
// Assert the file is available in the file storage.     $files = $file_storage->loadByProperties(['filename' => $filenames[1]]);
    $this->assertCount(1, $files);
    $file_1_uri = reset($files)->getFileUri();
    // Remove the second file and assert the focus is shifted to the container     // of the next media item and field values are still correct.     $page->pressButton('media-1-remove-button');
    $this->assertTrue($assert_session->waitForText('The media item ' . $filenames[1] . ' has been removed.'));
    $this->assertJsCondition('jQuery("[data-media-library-added-delta=2]").is(":focus")');
    // Assert the file was deleted.     $this->assertEmpty($file_storage->loadByProperties(['filename' => $filenames[1]]));
    $this->assertFileDoesNotExist($file_1_uri);

    // When a file is already in usage, it should not be deleted. To test,     // let's add a usage for $filenames[3] (now in the third position).     $files = $file_storage->loadByProperties(['filename' => $filenames[3]]);
    $this->assertCount(1, $files);
    $target_file = reset($files);
    Media::create([
      'bundle' => 'type_three',
      'name' => 'Disturbing',
      'field_media_test_image' => [
        ['target_id' => $target_file->id()],
      ],


  /** * Tests that AJAX elements with invalid callbacks return error code 500. */
  public function testSimpleInvalidCallbacksAjaxFormValue() {
    $this->drupalGet('ajax_forms_test_get_form');

    $session = $this->getSession();

    // Ensure the test error log is empty before these tests.     $this->assertFileDoesNotExist(DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');

    // We're going to do some invalid requests. The JavaScript errors thrown     // whilst doing so are expected. Do not interpret them as a test failure.     $this->failOnJavascriptConsoleErrors = FALSE;

    // We don't need to check for the X-Drupal-Ajax-Token header with these     // invalid requests.     foreach (['null', 'empty', 'nonexistent'] as $key) {
      $element_name = 'select_' . $key . '_callback';
      // Updating the field will trigger an AJAX request/response.       $session->getPage()->selectFieldOption($element_name, 'green');

      
->fields([
        'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
      ])
      ->condition('fid', $file->id())
      ->execute();
    \Drupal::service('cron')->run();

    // Verify that the image has been deleted.     $this->assertNull(File::load($file->id()), 'File was removed from the database.');
    // Clear out PHP's file stat cache so we see the current value.     clearstatcache(TRUE, $file->getFileUri());
    $this->assertFileDoesNotExist($file->getFileUri());
  }

  /** * Tests embedded users on node pages. */
  public function testPictureOnNodeComment() {
    $this->drupalLogin($this->webUser);

    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
    $this->addDefaultCommentField('node', 'article');

    
$io = $this->prophesize(IOInterface::class);
    $ref_io = new \ReflectionProperty($plugin, 'io');
    $ref_io->setValue($plugin$io->reveal());

    $this->assertFileExists(vfsStream::url('vendor/drupal/package/tests/SomeTest.php'));

    $package = $this->prophesize(PackageInterface::class);
    $package->getName()->willReturn('drupal/package');

    $plugin->cleanPackage($package->reveal());

    $this->assertFileDoesNotExist(vfsStream::url('vendor/drupal/package/tests'));
  }

  /** * @covers ::cleanPathsForPackage */
  public function testCleanPathsForPackage() {
    $plugin = $this->getMockBuilder(VendorHardeningPlugin::class)
      ->onlyMethods(['getInstallPathForPackage'])
      ->getMock();
    $plugin->expects($this->once())
      ->method('getInstallPathForPackage')
      

    ]);
    $this->assertEquals(SAVED_UPDATED, $image_style->save());

    // Create a copy of a test image file in root.     $test_uri = 'public://image-test-do.png';
    \Drupal::service('file_system')->copy('core/tests/fixtures/files/image-test.png', $test_uri, FileSystemInterface::EXISTS_REPLACE);
    $this->assertFileExists($test_uri);

    // Execute the image style on the test image via a GET request.     $derivative_uri = 'public://styles/image_effect_test/public/image-test-do.png.jpeg';
    $this->assertFileDoesNotExist($derivative_uri);
    $url = \Drupal::service('file_url_generator')->transformRelative($image_style->buildUrl($test_uri));
    $this->drupalGet($this->getAbsoluteUrl($url));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertFileExists($derivative_uri);
  }

}
foreach ($files as $file) {
      $invalid_image_files[$file->filename] = $file;
    }

    // Try uploading a zero-byte image.     $zero_size_image = $invalid_image_files['invalid-img-zero-size.png'];
    $edit = [
      'files[' . $field_name . '_0]' => $file_system->realpath($zero_size_image->uri),
    ];
    $this->drupalGet('node/' . $node . '/edit');
    $this->submitForm($edit, 'Upload');
    $this->assertFileDoesNotExist($expected_path . '/' . $zero_size_image->filename);

    // Try uploading an invalid image.     $invalid_image = $invalid_image_files['invalid-img-test.png'];
    $edit = [
      'files[' . $field_name . '_0]' => $file_system->realpath($invalid_image->uri),
    ];
    $this->drupalGet('node/' . $node . '/edit');
    $this->submitForm($edit, 'Upload');
    $this->assertFileDoesNotExist($expected_path . '/' . $invalid_image->filename);

    // Upload a valid image again.
public function testNormal() {
    $contents = $this->randomMachineName(10);
    $source = $this->createFile(NULL, $contents);
    $desired_filepath = 'public://' . $this->randomMachineName();

    // Clone the object so we don't have to worry about the function changing     // our reference copy.     $result = $this->fileRepository->move(clone $source$desired_filepath, FileSystemInterface::EXISTS_ERROR);

    // Check the return status and that the contents changed.     $this->assertNotFalse($result, 'File moved successfully.');
    $this->assertFileDoesNotExist($source->getFileUri());
    $this->assertEquals($contentsfile_get_contents($result->getFileUri()), 'Contents of file correctly written.');

    // Check that the correct hooks were called.     $this->assertFileHooksCalled(['move', 'load', 'update']);

    // Make sure we got the same file back.     $this->assertEquals($source->id()$result->id()new FormattableMarkup("Source file id's' %fid is unchanged after move.", ['%fid' => $source->id()]));

    // Reload the file from the database and check that the changes were     // actually saved.     $loaded_file = File::load($result->id());
    
$file = array_shift($files);
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $original_uri = $file_system->copy($file->uri, $scheme . '://', FileSystemInterface::EXISTS_RENAME);
    // Let the image_module_test module know about this file, so it can claim     // ownership in hook_file_download().     \Drupal::state()->set('image.test_file_download', $original_uri);
    $this->assertNotFalse($original_uri, 'Created the generated image file.');

    // Get the URL of a file that has not been generated and try to create it.     $generated_uri = $this->style->buildUri($original_uri);
    $this->assertFileDoesNotExist($generated_uri);
    $generate_url = $this->style->buildUrl($original_uri$clean_url);

    // Make sure that language prefix is never added to the image style URL.     if ($langcode) {
      $this->assertStringNotContainsString("/$langcode/", $generate_url, 'Langcode was not found in the image style URL.');
    }

    // Ensure that the tests still pass when the file is generated by accessing     // a poorly constructed (but still valid) file URL that has an extra slash     // in it.     if ($extra_slash) {
      
    // project is "allowed" in our main fixture project, but not required.     // We expect that requiring this library should re-scaffold, resulting     // in a changed default.settings.php file.     $stdout = $this->mustExec("composer require --no-ansi --no-interaction fixtures/drupal-assets-fixture:dev-main fixtures/scaffold-override-fixture:dev-main", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture');
    // Make sure that the appropriate notice informing us that scaffolding     // is allowed was printed.     $this->assertStringContainsString('Package fixtures/scaffold-override-fixture has scaffold operations, and is already allowed in the root-level composer.json file.', $stdout);
    // Delete one scaffold file, just for test purposes, then run     // 'composer update' and see if the scaffold file is replaced.     @unlink($sut . '/sites/default/default.settings.php');
    $this->assertFileDoesNotExist($sut . '/sites/default/default.settings.php');
    $this->mustExec("composer update --no-ansi", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture');
    // Delete the same test scaffold file again, then run     // 'composer drupal:scaffold' 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 install --no-ansi", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture');
    // Delete the same test scaffold file yet again, then run     // 'composer install' and see if the scaffold file is re-scaffolded.
use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new SkipOp();
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was not created.     $this->assertFileDoesNotExist($destination->fullPath());
    // Confirm that expected output was written to our io fixture.     $output = $fixtures->getOutput();
    $this->assertStringContainsString('Skip [web-root]/robots.txt: disabled', $output);
  }

}
Home | Imprint | This part of the site doesn't use cookies.