function FileFieldFileExtensionsUpdateTest::setAllowedExtensions

Sets the allowed extensions on the article image field.

Parameters

string $allowed_extensions: The list of allowed extensions.

3 calls to FileFieldFileExtensionsUpdateTest::setAllowedExtensions()
FileFieldFileExtensionsUpdateTest::testAllFileTypesAllowed in core/modules/file/tests/src/Functional/Update/FileFieldFileExtensionsUpdateTest.php
Tests file fields that permit all extensions.
FileFieldFileExtensionsUpdateTest::testInsecureUpdatesAllowed in core/modules/file/tests/src/Functional/Update/FileFieldFileExtensionsUpdateTest.php
Tests update when insecure uploads are allowed.
FileFieldFileExtensionsUpdateTest::testInsecureUpdatesNotAllowed in core/modules/file/tests/src/Functional/Update/FileFieldFileExtensionsUpdateTest.php
Tests adding txt extension to field that allow insecure extensions.

File

core/modules/file/tests/src/Functional/Update/FileFieldFileExtensionsUpdateTest.php, line 90

Class

FileFieldFileExtensionsUpdateTest
Tests file_post_update_add_txt_if_allows_insecure_extensions().

Namespace

Drupal\Tests\file\Functional\Update

Code

protected function setAllowedExtensions(string $allowed_extensions) {
    // Do direct database updates to avoid dependencies.
    $connection = Database::getConnection();
    $config = $connection->select('config')
        ->fields('config', [
        'data',
    ])
        ->condition('collection', '')
        ->condition('name', 'field.field.node.article.field_image')
        ->execute()
        ->fetchField();
    $config = unserialize($config);
    $this->assertArrayHasKey('file_extensions', $config['settings']);
    $config['settings']['file_extensions'] = $allowed_extensions;
    $connection->update('config')
        ->fields([
        'data' => serialize($config),
    ])
        ->condition('collection', '')
        ->condition('name', 'field.field.node.article.field_image')
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.