You are here

class ParseEntityIdsTest in FillPDF 8.4

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

@coversDefaultClass \Drupal\fillpdf\Service\FillPdfLinkManipulator

@group fillpdf

Hierarchy

Expanded class hierarchy of ParseEntityIdsTest

File

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

Namespace

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

  /**
   * Tests parsing entity IDs from query parameters and back.
   *
   * @param array $input
   *   Input query parameters.
   * @param array $expected
   *   Expected output query parameters.
   *
   * @covers ::parseEntityIds
   * @covers ::prepareEntityIds
   *
   * @dataProvider providerTestEntityIds
   */
  public function testEntityIds(array $input, array $expected) {

    // Parse query parameters, creating a context.
    $context = FillPdfLinkManipulator::parseEntityIds($input);

    // Turn the context back into query parameters.
    $actual = FillPdfLinkManipulator::prepareEntityIds($context);
    $this
      ->assertEquals($expected, $actual);
  }

  /**
   * Data provider for testEntityIds().
   *
   * @return array[]
   *   Array of test cases.
   */
  public function providerTestEntityIds() {
    $cases = [];
    $cases[0] = [
      [],
      [],
    ];
    $cases[1] = [
      [
        'entity_ids' => [
          'node:1',
        ],
      ],
      [
        'entity_id' => 'node:1',
      ],
    ];
    $cases[2] = [
      [
        'entity_ids' => [
          'term:5',
        ],
      ],
      [
        'entity_id' => 'term:5',
      ],
    ];
    $cases[3] = [
      [
        'entity_ids' => [
          'node:1',
          'node:2',
        ],
      ],
      [
        'entity_ids' => [
          'node:1',
          'node:2',
        ],
      ],
    ];
    $cases[4] = [
      [
        'entity_ids' => [
          'node:1',
          'node:1',
        ],
      ],
      [
        'entity_id' => 'node:1',
      ],
    ];
    $cases[5] = [
      [
        'entity_ids' => [
          'user:3',
          'term:5',
        ],
      ],
      [
        'entity_ids' => [
          'user:3',
          'term:5',
        ],
      ],
    ];
    $cases[6] = [
      [
        'entity_ids' => [],
        'entity_type' => '',
        'entity_id' => 1,
      ],
      [
        'entity_id' => 'node:1',
      ],
    ];
    $cases[7] = [
      [
        'entity_id' => 1,
      ],
      [
        'entity_id' => 'node:1',
      ],
    ];
    $cases[8] = [
      [
        'entity_type' => 'term',
        'entity_id' => 5,
      ],
      [
        'entity_id' => 'term:5',
      ],
    ];
    $cases[9] = [
      [
        'entity_ids' => [
          '1',
        ],
        'entity_type' => 'node',
      ],
      [
        'entity_id' => 'node:1',
      ],
    ];
    $cases[10] = [
      [
        'entity_ids' => [
          '1',
          '2',
        ],
        'entity_type' => 'node',
      ],
      [
        'entity_ids' => [
          'node:1',
          'node:2',
        ],
      ],
    ];
    $cases[11] = [
      [
        'entity_ids' => [
          '3',
          '4',
        ],
        'entity_type' => 'user',
      ],
      [
        'entity_ids' => [
          'user:3',
          'user:4',
        ],
      ],
    ];
    $cases[12] = [
      [
        'entity_ids' => [
          '3',
          '4',
        ],
        'entity_type' => 'user',
        'entity_id' => '5',
      ],
      [
        'entity_id' => 'user:5',
      ],
    ];
    return $cases;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParseEntityIdsTest::providerTestEntityIds public function Data provider for testEntityIds().
ParseEntityIdsTest::testEntityIds public function Tests parsing entity IDs from query parameters and back.
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