You are here

public function AdminTest::testListAddEdit in Background Image 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/AdminTest.php \Drupal\Tests\background_image\Functional\AdminTest::testListAddEdit()
  2. 2.0.x tests/src/Functional/AdminTest.php \Drupal\Tests\background_image\Functional\AdminTest::testListAddEdit()

Tests view builder functionality.

File

tests/src/Functional/AdminTest.php, line 49

Class

AdminTest
Tests adding image and viewing them through UI.

Namespace

Drupal\Tests\background_image\Functional

Code

public function testListAddEdit() {
  $collection = 'admin/config/media/background_image';

  // Login as admin user.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet($collection);
  $this
    ->assertSession()
    ->pageTextContains('There are no background images to display.');

  // Create first valid global image.
  $label = 'Global label';
  $this
    ->addImageForm(-1, $label);
  $files = $this
    ->drupalGetTestFiles('image');
  $file = \Drupal::service('file_system')
    ->realpath($files[0]->uri);
  $edit = [
    'files[image_0]' => $file,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains("The background image {$label} has been added.");
  $session
    ->pageTextContains("Global: {$label}");
  $this
    ->drupalGet('admin/config/media/background_image/1/edit');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(200);
  $session
    ->pageTextContains("Global: {$label}");
}