You are here

public function BarcodeBlockTest::testShowValue in Barcodes 2.0.x

Tests the "Show value" functionality.

@covers ::build

File

tests/src/Functional/BarcodeBlockTest.php, line 55

Class

BarcodeBlockTest
Tests the Barcodes module block functionality.

Namespace

Drupal\Tests\barcodes\Functional

Code

public function testShowValue() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  // Test with "Show value" set to TRUE.
  // PNG is used for output because the default SVG output will always contain
  // the value in a <desc> tag, making it difficult to test.
  $this->block
    ->getPlugin()
    ->setConfigurationValue('format', 'PNG');
  $this->block
    ->getPlugin()
    ->setConfigurationValue('value', '01234567890123456789');
  $this->block
    ->getPlugin()
    ->setConfigurationValue('show_value', TRUE);
  $this->block
    ->save();
  $this
    ->drupalGet('');

  // QRCODE is the default barcode format.
  $assert
    ->responseContains('barcode-qrcode');
  $assert
    ->pageTextContains($this->block
    ->label());
  $assert
    ->pageTextContains('01234567890123456789');

  // Now test with "Show value" set to FALSE.
  $this->block
    ->getPlugin()
    ->setConfigurationValue('show_value', FALSE);
  $this->block
    ->save();
  $this
    ->drupalGet('');
  $assert
    ->responseContains('barcode-qrcode');
  $assert
    ->pageTextContains($this->block
    ->label());
  $assert
    ->pageTextNotContains('01234567890123456789');
}