You are here

class PrintEngineExceptionTest in Entity Print 8.2

Test print engine exceptions.

@group entity_print

Hierarchy

Expanded class hierarchy of PrintEngineExceptionTest

File

tests/src/Unit/PrintEngineExceptionTest.php, line 14

Namespace

Drupal\Tests\entity_print\Unit
View source
class PrintEngineExceptionTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $container = new ContainerBuilder();
    $container
      ->set('string_translation', $this
      ->getStringTranslationStub());
    \Drupal::setContainer($container);
  }

  /**
   * Tests the pretty error messages for authorisation failures.
   *
   * @dataProvider authorisationExceptions
   */
  public function testAuthorisationException($message) {
    $exception = new PrintEngineException($message);
    $this
      ->assertEquals('Authorisation failed, are your resources behind HTTP authentication? Check the admin page to set credentials.', $exception
      ->getPrettyMessage());
  }

  /**
   * Gets the exception messages for the providers for authorisation failures.
   *
   * @return array
   *   An array of possible exception messages.
   */
  public function authorisationExceptions() {
    return [
      'Dompdf' => [
        'Failed to generate PDF: file_get_contents(http://d8.dev/sites/default/files/css/css_qm-4SpSW1uLvtwb-T4OPS48NMb2DSFqwLd5C3MLRLuY.css?om2pmk): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized , Unable to load css file http://d8.dev/sites/default/files/css/css_qm-4SpSW1uLvtwb-T4OPS48NMb2DSFqwLd5C3MLRLuY.css?om2pmk',
      ],
      'wkhtmltopdf' => [
        'Failed to generate PDF: Loading pages (1/6) [> ] 0% [======> ] 10% [==========> ] 18% Error: Invalid username or password [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) Printing pages (6/6) [> ] Preparing [============================================================] Page 1 of 1 Done Exit with code 1 due to network error: AuthenticationRequiredError',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
PrintEngineExceptionTest::authorisationExceptions public function Gets the exception messages for the providers for authorisation failures.
PrintEngineExceptionTest::setUp public function Overrides UnitTestCase::setUp
PrintEngineExceptionTest::testAuthorisationException public function Tests the pretty error messages for authorisation failures.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.