You are here

class FreelinkingPrepopulateTest in Freelinking 8.3

Same name in this branch
  1. 8.3 modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Functional\FreelinkingPrepopulateTest
  2. 8.3 modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest
Same name and namespace in other branches
  1. 4.0.x modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest

Tests FreelinkingPrepopulate freelinking plugin.

@group freelinking_prepopulate

Hierarchy

Expanded class hierarchy of FreelinkingPrepopulateTest

File

modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php, line 14

Namespace

Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking
View source
class FreelinkingPrepopulateTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {

    // Mocks returning content types.
    $nodeTypeProphet = $this
      ->prophesize('\\Drupal\\Core\\Entity\\EntityInterface');
    $nodeTypeProphet
      ->id()
      ->willReturn('page');
    $nodeTypeStorageProphet = $this
      ->prophesize('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
    $nodeTypeStorageProphet
      ->loadMultiple()
      ->willReturn([
      'page' => $nodeTypeProphet
        ->reveal(),
    ]);

    // Mocks the entity type manager.
    $entityTypeManagerProphet = $this
      ->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
    $entityTypeManagerProphet
      ->getStorage('node_type')
      ->willReturn($nodeTypeStorageProphet
      ->reveal());
    $entityTypeManager = $entityTypeManagerProphet
      ->reveal();

    // Mocks the entity field manager.
    $entityFieldManagerProphet = $this
      ->prophesize('\\Drupal\\Core\\Entity\\EntityFieldManagerInterface');
    $entityFieldManagerProphet
      ->getFieldDefinitions('node', 'page');

    // Mocks the module handler interface.
    $moduleHandlerProphet = $this
      ->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $container = new ContainerBuilder();
    $container
      ->set('entity_type.manager', $entityTypeManager);
    $container
      ->set('entity_field.manager', $entityFieldManagerProphet
      ->reveal());
    $container
      ->set('module_handler', $moduleHandlerProphet
      ->reveal());
    \Drupal::setContainer($container);
  }

  /**
   * Asserts that the configuration is returned based on initial state.
   *
   * @param array $configuration
   *   The initial plugin configuration.
   * @param array $expected
   *   The expected return value.
   *
   * @dataProvider configurationProvider
   */
  public function testGetConfiguration(array $configuration, array $expected) {
    $definition = [
      'id' => 'freelinking_prepopulate',
      'title' => 'Prepopulate',
      'settings' => [
        'default_node_type' => 'page',
        'advanced' => [
          'title' => '0',
        ],
        'failover' => 'search',
      ],
    ];
    $plugin = FreelinkingPrepopulate::create(\Drupal::getContainer(), $configuration, 'freelinking_prepopulate', $definition);
    $this
      ->assertEquals($expected, $plugin
      ->getConfiguration());
  }

  /**
   * Gets test arguments for testGetConfiguration.
   *
   * @return array
   *   An array of test arguments.
   */
  public function configurationProvider() {
    return [
      'empty configuration provided' => [
        [],
        [
          'settings' => [
            'default_node_type' => 'page',
            'advanced' => [
              'title' => FALSE,
            ],
            'failover' => 'search',
          ],
        ],
      ],
      'empty settings provided' => [
        [
          'settings' => [],
        ],
        [
          'settings' => [
            'default_node_type' => 'page',
            'advanced' => [
              'title' => FALSE,
            ],
            'failover' => 'search',
          ],
        ],
      ],
      'failover setting provided' => [
        [
          'settings' => [
            'failover' => 'error',
          ],
        ],
        [
          'settings' => [
            'default_node_type' => 'page',
            'advanced' => [
              'title' => FALSE,
            ],
            'failover' => 'error',
          ],
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FreelinkingPrepopulateTest::configurationProvider public function Gets test arguments for testGetConfiguration.
FreelinkingPrepopulateTest::setUp protected function Overrides UnitTestCase::setUp
FreelinkingPrepopulateTest::testGetConfiguration public function Asserts that the configuration is returned based on initial state.
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.