function NavigationLogoTest::testSettingsLogoOptionsForm

Tests Navigation logo configuration base options.

File

core/modules/navigation/tests/src/Functional/NavigationLogoTest.php, line 68

Class

NavigationLogoTest
Tests for \Drupal\navigation\Form\SettingsForm.

Namespace

Drupal\Tests\navigation\Functional

Code

public function testSettingsLogoOptionsForm() : void {
    $test_files = $this->getTestFiles('image');
    // Navigate to the settings form.
    $this->drupalGet('/admin/config/user-interface/navigation/settings');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Option 1. Check the default logo provider.
    $this->assertSession()
        ->fieldValueEquals('logo_provider', 'default');
    $this->assertSession()
        ->elementExists('css', 'a.admin-toolbar__logo > svg');
    // Option 2: Set the logo provider to hide and check.
    $edit = [
        'logo_provider' => 'hide',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()
        ->pageTextContains('The configuration options have been saved.');
    $this->assertSession()
        ->elementNotExists('css', 'a.admin-toolbar__logo');
    // Option 3: Set the logo provider to custom and upload a logo.
    $file = reset($test_files);
    $logo_file = File::create((array) $file + [
        'status' => 1,
    ]);
    $logo_file->save();
    $this->assertNotEmpty($logo_file, 'File entity is not empty.');
    $edit = [
        'logo_provider' => 'custom',
        'logo_path' => $logo_file->getFileUri(),
    ];
    $this->submitForm($edit, $this->t('Save configuration'));
    // Refresh the page to verify custom logo is placed.
    $this->drupalGet('/admin/config/user-interface/navigation/settings');
    $this->assertSession()
        ->elementExists('css', 'a.admin-toolbar__logo > img');
    $this->assertSession()
        ->elementAttributeContains('css', 'a.admin-toolbar__logo > img', 'src', $logo_file->getFilename());
    // Option 4: Set the custom logo to an image in the source code.
    $edit = [
        'logo_provider' => 'custom',
        'logo_path' => 'core/misc/logo/drupal-logo.svg',
    ];
    $this->submitForm($edit, $this->t('Save configuration'));
    // Refresh the page to verify custom logo is placed.
    $this->drupalGet('/admin/config/user-interface/navigation/settings');
    $this->assertSession()
        ->elementExists('css', 'a.admin-toolbar__logo > img');
    $this->assertSession()
        ->elementAttributeContains('css', 'a.admin-toolbar__logo > img', 'src', 'drupal-logo.svg');
    // Option 5: Upload custom logo.
    $file = end($test_files);
    $edit = [
        'logo_provider' => 'custom',
        'files[logo_upload]' => $this->fileSystem
            ->realpath($file->uri),
    ];
    $this->submitForm($edit, $this->t('Save configuration'));
    $this->assertSession()
        ->statusMessageContains('The image was resized to fit within the navigation logo expected dimensions of 40x40 pixels. The new dimensions of the resized image are 40x27 pixels.');
    // Refresh the page to verify custom logo is placed.
    $this->drupalGet('/admin/config/user-interface/navigation/settings');
    $this->assertSession()
        ->elementExists('css', 'a.admin-toolbar__logo > img');
    $this->assertSession()
        ->elementAttributeContains('css', 'a.admin-toolbar__logo > img', 'src', $file->name);
}

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