You are here

class ConfigEntityNormalizerTest in JSON:API 8

@coversDefaultClass \Drupal\jsonapi\Normalizer\ConfigEntityNormalizer @group jsonapi

@internal

Hierarchy

Expanded class hierarchy of ConfigEntityNormalizerTest

File

tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php, line 20

Namespace

Drupal\Tests\jsonapi\Unit\Normalizer
View source
class ConfigEntityNormalizerTest extends UnitTestCase {

  /**
   * The normalizer under test.
   *
   * @var \Drupal\jsonapi\Normalizer\ConfigEntityNormalizer
   */
  protected $normalizer;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $link_manager = $this
      ->prophesize(LinkManager::class);
    $resource_type = new ResourceType('dolor', 'sid', NULL);
    $resource_type
      ->setRelatableResourceTypes([]);
    $resource_type_repository = $this
      ->prophesize(ResourceTypeRepository::class);
    $resource_type_repository
      ->get(Argument::type('string'), Argument::type('string'))
      ->willReturn($resource_type);
    $this->normalizer = new ConfigEntityNormalizer($link_manager
      ->reveal(), $resource_type_repository
      ->reveal(), $this
      ->prophesize(EntityTypeManagerInterface::class)
      ->reveal());
  }

  /**
   * @covers ::normalize
   * @dataProvider normalizeProvider
   */
  public function testNormalize($input, $expected) {
    $entity = $this
      ->prophesize(ConfigEntityInterface::class);
    $entity
      ->toArray()
      ->willReturn([
      'amet' => $input,
    ]);
    $entity
      ->getCacheContexts()
      ->willReturn([]);
    $entity
      ->getCacheTags()
      ->willReturn([]);
    $entity
      ->getCacheMaxAge()
      ->willReturn(-1);
    $entity
      ->getEntityTypeId()
      ->willReturn('');
    $entity
      ->bundle()
      ->willReturn('');
    $normalized = $this->normalizer
      ->normalize($entity
      ->reveal(), 'api_json', []);
    $first = $normalized
      ->getValues();
    $first = reset($first);
    $this
      ->assertSame($expected, $first
      ->rasterizeValue());
  }

  /**
   * Data provider for the normalize test.
   *
   * @return array
   *   The data for the test method.
   */
  public function normalizeProvider() {
    return [
      [
        'lorem',
        'lorem',
      ],
      [
        [
          'ipsum' => 'dolor',
          'ra' => 'foo',
        ],
        [
          'ipsum' => 'dolor',
          'ra' => 'foo',
        ],
      ],
      [
        [
          'ipsum' => 'dolor',
        ],
        [
          'ipsum' => 'dolor',
        ],
      ],
      [
        [
          'lorem' => [
            'ipsum' => [
              'dolor' => 'sid',
              'amet' => 'ra',
            ],
          ],
        ],
        [
          'lorem' => [
            'ipsum' => [
              'dolor' => 'sid',
              'amet' => 'ra',
            ],
          ],
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigEntityNormalizerTest::$normalizer protected property The normalizer under test.
ConfigEntityNormalizerTest::normalizeProvider public function Data provider for the normalize test.
ConfigEntityNormalizerTest::setUp public function Overrides UnitTestCase::setUp
ConfigEntityNormalizerTest::testNormalize public function @covers ::normalize @dataProvider normalizeProvider
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.