function NavigationSettingsFormTest::testFormSettingsSubmissionHandler

Tests that submission handler works correctly.

File

core/modules/navigation/tests/src/FunctionalJavascript/NavigationSettingsFormTest.php, line 49

Class

NavigationSettingsFormTest
Tests that theme form settings works correctly.

Namespace

Drupal\Tests\navigation\FunctionalJavascript

Code

public function testFormSettingsSubmissionHandler() {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    $this->drupalGet("/admin/config/user-interface/navigation/settings");
    // Add a new managed file.
    $file = current($this->getTestFiles('image'));
    $image_file_path = \Drupal::service('file_system')->realpath($file->uri);
    $page->attachFileToField('files[logo_managed]', $image_file_path);
    $assert_session->waitForButton('logo_managed_remove_button');
    // Assert the new file is uploaded as temporary. This file should not be
    // saved as permanent if settings are not submitted.
    $image_field = $this->assertSession()
        ->hiddenFieldExists('logo_managed[fids]');
    $file = File::load($image_field->getValue());
    $this->assertFalse($file->isPermanent());
    $page->pressButton('Save configuration');
    \Drupal::entityTypeManager()->getStorage('file')
        ->resetCache();
    $this->drupalGet("/admin/config/user-interface/navigation/settings");
    // Assert the uploaded file is saved as permanent.
    $image_field = $this->assertSession()
        ->hiddenFieldExists('logo_managed[fids]');
    $file = File::load($image_field->getValue());
    $this->assertTrue($file->isPermanent());
    // Ensure that the image has been resized to fit in the expected container.
    $image = \Drupal::service('image.factory')->get($file->getFileUri());
    $this->assertLessThanOrEqual(10, $image->getHeight());
    $this->assertLessThanOrEqual(10, $image->getWidth());
}

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