You are here

class ParseBooleanFlagsTest in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x tests/src/Unit/LinkManipulator/ParseBooleanFlagsTest.php \Drupal\Tests\fillpdf\Unit\LinkManipulator\ParseBooleanFlagsTest

@coversDefaultClass \Drupal\fillpdf\Service\FillPdfLinkManipulator

@group fillpdf

Hierarchy

Expanded class hierarchy of ParseBooleanFlagsTest

File

tests/src/Unit/LinkManipulator/ParseBooleanFlagsTest.php, line 13

Namespace

Drupal\Tests\fillpdf\Unit\LinkManipulator
View source
class ParseBooleanFlagsTest extends UnitTestCase {

  /**
   * Tests &sample=, &download= and &flatten= query parameters.
   *
   * @covers ::parseBooleanFlags
   *
   * @dataProvider providerTestBooleanFlags
   */
  public function testBooleanFlags($input, $expected) {
    $context = FillPdfLinkManipulator::parseBooleanFlags($this
      ->buildQuery($input));
    $this
      ->assertEquals(is_null($expected) ? FALSE : $expected, $context['sample']);
    $this
      ->assertEquals(is_null($expected) ? FALSE : $expected, $context['force_download']);
    $this
      ->assertEquals(is_null($expected) ? TRUE : $expected, $context['flatten']);
  }

  /**
   * Input helper for testBooleanFlags().
   */
  public function buildQuery($input) {
    return [
      'fid' => 1,
      'entity_type' => 'node',
      'entity_id' => 1,
      'sample' => $input,
      'download' => $input,
      'flatten' => $input,
    ];
  }

  /**
   * Data provider for testBooleanFlags().
   */
  public function providerTestBooleanFlags() {
    return [
      [
        '1',
        TRUE,
      ],
      [
        'true',
        TRUE,
      ],
      [
        'True',
        TRUE,
      ],
      [
        'TRUE',
        TRUE,
      ],
      [
        'on',
        TRUE,
      ],
      [
        'On',
        TRUE,
      ],
      [
        'ON',
        TRUE,
      ],
      [
        'yes',
        TRUE,
      ],
      [
        'Yes',
        TRUE,
      ],
      [
        'YES',
        TRUE,
      ],
      [
        '0',
        FALSE,
      ],
      [
        'false',
        FALSE,
      ],
      [
        'False',
        FALSE,
      ],
      [
        'FALSE',
        FALSE,
      ],
      [
        'off',
        FALSE,
      ],
      [
        'Off',
        FALSE,
      ],
      [
        'OFF',
        FALSE,
      ],
      [
        'no',
        FALSE,
      ],
      [
        'No',
        FALSE,
      ],
      [
        'NO',
        FALSE,
      ],
      // These three are important, so should always be obeyed:
      [
        '',
        NULL,
      ],
      [
        'foo',
        NULL,
      ],
      [
        'bar',
        NULL,
      ],
      // The following ones are less fortunate, so may be refactored:
      [
        '-1',
        NULL,
      ],
      [
        '2',
        NULL,
      ],
      [
        'y',
        NULL,
      ],
      [
        'Y',
        NULL,
      ],
      [
        'n',
        NULL,
      ],
      [
        'N',
        NULL,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParseBooleanFlagsTest::buildQuery public function Input helper for testBooleanFlags().
ParseBooleanFlagsTest::providerTestBooleanFlags public function Data provider for testBooleanFlags().
ParseBooleanFlagsTest::testBooleanFlags public function Tests &sample=, &download= and &flatten= query parameters.
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.
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.
UnitTestCase::setUp protected function 340