function TaxonomyImageTest::testTaxonomyImageUpload

Same name in other branches
  1. 10 core/modules/taxonomy/tests/src/Functional/TaxonomyImageTest.php \Drupal\Tests\taxonomy\Functional\TaxonomyImageTest::testTaxonomyImageUpload()

Tests that a file can be uploaded before the taxonomy term has a name.

File

core/modules/taxonomy/tests/src/Functional/TaxonomyImageTest.php, line 74

Class

TaxonomyImageTest
Tests image upload on taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTaxonomyImageUpload() : void {
    $user = $this->drupalCreateUser([
        'administer taxonomy',
    ]);
    $this->drupalLogin($user);
    $files = $this->drupalGetTestFiles('image');
    $image = array_pop($files);
    // Ensure that a file can be uploaded before taxonomy term has a name.
    $edit = [
        'files[field_test_0]' => \Drupal::service('file_system')->realpath($image->uri),
    ];
    $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
        ->id() . '/add');
    $this->submitForm($edit, 'Upload');
    $edit = [
        'name[0][value]' => $this->randomMachineName(),
        'field_test[0][alt]' => $this->randomMachineName(),
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('Created new term');
}

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