createFile example

$i = 0;
            while ($i++ < $count) {
                $groups[$name]->addNotice();
            }
        }

        return $groups;
    }

    public function testBaselineGenerationEmptyFile()
    {
        $filename = $this->createFile();
        $configuration = Configuration::fromUrlEncodedString('generateBaseline=true&baselineFile='.urlencode($filename));
        $this->assertTrue($configuration->isGeneratingBaseline());
        $trace = debug_backtrace();
        $this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 1', $trace, '')));
        $this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 2', $trace, '')));
        $this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 1', $trace, '')));
        $configuration->writeBaseline();
        $this->assertEquals($filename$configuration->getBaselineFile());
        $expected = [
            [
                'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest',
                
$this->fileUrlGenerator = $this->container->get('file_url_generator');
    // Clear out any hook calls.     file_test_reset();
  }

  /** * Tests the public file transfer system. */
  public function testPublicFileTransfer() {
    // Test generating a URL to a created file.     $file = $this->createFile();
    $url = $this->fileUrlGenerator->generateAbsoluteString($file->getFileUri());
    // URLs can't contain characters outside the ASCII set so $filename has to be     // encoded.     $filename = $GLOBALS['base_url'] . '/' . \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename());
    $this->assertEquals($filename$url, 'Correctly generated a URL for a created file.');
    $http_client = $this->getHttpClient();
    $response = $http_client->head($url);
    $this->assertEquals(200, $response->getStatusCode(), 'Confirmed that the generated URL is correct by downloading the created file.');

    // Test generating a URL to a shipped file (i.e. a file that is part of     // Drupal core, a module or a theme, for example a JavaScript file).
/** * Tests the file delete function. * * @group file */
class DeleteTest extends FileManagedUnitTestBase {

  /** * Tries deleting a normal file (as opposed to a directory, symlink, etc). */
  public function testUnused() {
    $file = $this->createFile();

    // Check that deletion removes the file and database record.     $this->assertFileExists($file->getFileUri());
    $file->delete();
    $this->assertFileHooksCalled(['delete']);
    $this->assertFileDoesNotExist($file->getFileUri());
    $this->assertNull(File::load($file->id()), 'File was removed from the database.');
  }

  /** * Tries deleting a file that is in use. */
parent::setUp();
    $this->fileRepository = $this->container->get('file.repository');
  }

  /** * Move a normal file. * * @covers ::move */
  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.');

    
'administer views',
      'administer languages',
    ]);
    $this->drupalLogin($web_user);
  }

  /** * Tests plural formatting setting on a numeric views handler. */
  public function testNumericFormatPlural() {
    // Create a file.     $file = $this->createFile();

    // Assert that the starting configuration is correct.     $config = $this->config('views.view.numeric_test');
    $field_config_prefix = 'display.default.display_options.fields.count.';
    $this->assertTrue($config->get($field_config_prefix . 'format_plural'));
    $this->assertEquals('1' . PoItem::DELIMITER . '@count', $config->get($field_config_prefix . 'format_plural_string'));

    // Assert that the value is displayed.     $this->drupalGet('numeric-test');
    $this->assertSession()->responseContains('<span class="field-content">0</span>');

    
/** * Tests file usage functions. * * @group file */
class UsageTest extends FileManagedUnitTestBase {

  /** * Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage(). */
  public function testGetUsage() {
    $file = $this->createFile();
    $connection = Database::getConnection();
    $connection->insert('file_usage')
      ->fields([
        'fid' => $file->id(),
        'module' => 'testing',
        'type' => 'foo',
        'id' => 1,
        'count' => 1,
      ])
      ->execute();
    $connection->insert('file_usage')
      

class XliffLintCommandTest extends TestCase
{
    private array $files;

    public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile();

        $tester->execute(
            ['filename' => $filename],
            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
        );

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('OK', trim($tester->getDisplay()));
    }

    public function testLintCorrectFiles()
    {
/** @var ProductExportCollection $productExports */
        $productExports = $this->productExportRepository->search($criteria$context->getContext());

        if ($productExports->count() === 0) {
            $exportNotFoundException = new ExportNotFoundException($productExportId);
            $this->logException($context->getContext()$exportNotFoundException);

            throw $exportNotFoundException;
        }

        foreach ($productExports as $productExport) {
            $this->createFile($productExport$context$behavior);
        }
    }

    private function createFile(
        ProductExportEntity $productExport,
        SalesChannelContext $context,
        ExportBehavior $exportBehavior
    ): void {
        $filePath = $this->productExportFileHandler->getFilePath($productExport);

        if ($this->productExportFileHandler->isValidFile(
            
for ($i = 0; $i < 5; $i++) {
      $nodes[] = $this->drupalCreateNode(['type' => 'article']);
    }

    $this->drupalGet('admin/content/files');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('No files available.');
    $this->drupalGet('admin/content/files');
    $this->assertSession()->statusCodeEquals(200);

    // Create a file with no usage.     $file = $this->createFile();

    $this->drupalGet('admin/content/files/usage/' . $file->id());
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->titleEquals('File usage information for ' . $file->getFilename() . ' | Drupal');

    foreach ($nodes as &$node) {
      $this->drupalGet('node/' . $node->id() . '/edit');
      $file = $this->getTestFile('image');

      $edit = [
        'files[file_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
      ];
public function testLoadInvalidStatus() {
    $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['status' => -99]);
    $this->assertFalse(reset($files), 'Trying to load a file with an invalid status fails.');
    $this->assertFileHooksCalled([]);
  }

  /** * Load a single file and ensure that the correct values are returned. */
  public function testSingleValues() {
    // Create a new file entity from scratch so we know the values.     $file = $this->createFile('druplicon.txt', NULL, 'public');
    $by_fid_file = File::load($file->id());
    $this->assertFileHookCalled('load');
    $this->assertIsObject($by_fid_file);
    $this->assertEquals($file->id()$by_fid_file->id(), 'Loading by fid got the same fid.');
    $this->assertEquals($file->getFileUri()$by_fid_file->getFileUri(), 'Loading by fid got the correct filepath.');
    $this->assertEquals($file->getFilename()$by_fid_file->getFilename(), 'Loading by fid got the correct filename.');
    $this->assertEquals($file->getMimeType()$by_fid_file->getMimeType(), 'Loading by fid got the correct MIME type.');
    $this->assertEquals($file->isPermanent()$by_fid_file->isPermanent(), 'Loading by fid got the correct status.');
    $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
  }

  

class YamlLintCommandTest extends TestCase
{
    private array $files;

    public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile('foo: bar');

        $tester->execute(
            ['filename' => $filename],
            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
        );

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('OK', trim($tester->getDisplay()));
    }

    public function testLintIncorrectFile()
    {
class FileUrlTest extends FileManagedUnitTestBase {

  /** * Tests public files with a different host name from settings. */
  public function testFilesUrlWithDifferentHostName() {
    $test_base_url = 'http://www.example.com/cdn';
    $this->setSetting('file_public_base_url', $test_base_url);
    $filepath = \Drupal::service('file_system')->createFilename('test.txt', '');
    $directory_uri = 'public://' . dirname($filepath);
    \Drupal::service('file_system')->prepareDirectory($directory_uri, FileSystemInterface::CREATE_DIRECTORY);
    $file = $this->createFile($filepath, NULL, 'public');
    $url = $file->createFileUrl(FALSE);
    $expected_url = $test_base_url . '/' . basename($filepath);
    $this->assertSame($url$expected_url);
  }

}
parent::setUp();
    $this->fileRepository = $this->container->get('file.repository');
  }

  /** * Tests file copying in the normal, base case. * * @covers ::copy */
  public function testNormal() {
    $contents = $this->randomMachineName(10);
    $source = $this->createFile(NULL, $contents);
    $desired_uri = 'public://' . $this->randomMachineName();

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

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

    // Check that the correct hooks were called.


    protected function tearDown(): void
    {
        parent::tearDown();
        putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
    }

    public function testPullNewXlf12Messages()
    {
        $arrayLoader = new ArrayLoader();
        $filenameEn = $this->createFile();
        $filenameEnIcu = $this->createFile(['say_hello' => 'Welcome, {firstname}!'], 'en', 'messages+intl-icu.%locale%.xlf');
        $filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
        $filenameFrIcu = $this->createFile(['say_hello' => 'Bonjour, {firstname}!'], 'fr', 'messages+intl-icu.%locale%.xlf');
        $locales = ['en', 'fr'];
        $domains = ['messages', 'messages+intl-icu'];

        $providerReadTranslatorBag = new TranslatorBag();
        $providerReadTranslatorBag->addCatalogue($arrayLoader->load([
            'note' => 'NOTE',
            'new.foo' => 'newFoo',
        ], 'en'));
        
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;

class LintCommandTest extends TestCase
{
    private array $files;

    public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile('{{ foo }}');

        $ret = $tester->execute(['filename' => [$filename]]['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);

        $this->assertEquals(0, $ret, 'Returns 0 in case of success');
        $this->assertStringContainsString('OK in', trim($tester->getDisplay()));
    }

    public function testLintIncorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile('{{ foo');

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