You are here

class VisualDiffThemeNegotiatorTest in Diff 8

Tests theme negotiator.

@coversDefaultClass \Drupal\diff\VisualDiffThemeNegotiator @group diff

Hierarchy

Expanded class hierarchy of VisualDiffThemeNegotiatorTest

File

tests/src/Unit/VisualDiffThemeNegotiatorTest.php, line 17

Namespace

Drupal\Tests\diff\Unit
View source
class VisualDiffThemeNegotiatorTest extends UnitTestCase {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
   */
  protected $configFactory;

  /**
   * The class under test.
   *
   * @var \Drupal\diff\VisualDiffThemeNegotiator
   */
  protected $themeNegotiator;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->configFactory = $this
      ->prophesize(ConfigFactoryInterface::class);
    $this->themeNegotiator = new VisualDiffThemeNegotiator($this->configFactory
      ->reveal());
  }

  /**
   * @covers ::determineActiveTheme
   */
  public function testDetermineActiveTheme() {
    $config = $this
      ->prophesize(ImmutableConfig::class);
    $config
      ->get('default')
      ->willReturn('the_default_theme');
    $this->configFactory
      ->get('system.theme')
      ->willReturn($config
      ->reveal());
    $route_match = $this
      ->prophesize(RouteMatchInterface::class);
    $result = $this->themeNegotiator
      ->determineActiveTheme($route_match
      ->reveal());
    $this
      ->assertSame('the_default_theme', $result);
  }

  /**
   * Tests if the theme negotiator applies under correct conditions.
   *
   * @param string $filter_parameter
   *   The filter parameter.
   * @param string $route_name
   *   The route name.
   * @param string $config_value
   *   The configuration value of the element taken from the form values.
   * @param bool $expected
   *   The expected result.
   *
   * @covers ::applies
   * @covers ::isDiffRoute
   *
   * @dataProvider providerTestApplies
   */
  public function testApplies($filter_parameter, $route_name, $config_value, $expected) {
    $route_match = $this
      ->prophesize(RouteMatchInterface::class);
    $route_match
      ->getParameter('filter')
      ->willReturn($filter_parameter);
    if ($route_name) {
      $route_match
        ->getRouteName()
        ->willReturn($route_name);
    }
    else {
      $route_match
        ->getRouteName()
        ->shouldNotBeCalled();
    }
    if ($config_value) {
      $diff_config = $this
        ->prophesize(ImmutableConfig::class);
      $diff_config
        ->get('general_settings.visual_inline_theme')
        ->willReturn($config_value);
      $this->configFactory
        ->get('diff.settings')
        ->willReturn($diff_config
        ->reveal());
    }
    else {
      $this->configFactory
        ->get('diff.settings')
        ->shouldNotBeCalled();
    }
    $this
      ->assertSame($expected, $this->themeNegotiator
      ->applies($route_match
      ->reveal()));
  }

  /**
   * Provides test data to ::testApplies().
   */
  public function providerTestApplies() {
    $data = [];
    $data[] = [
      'unexpected_filter_parameter',
      NULL,
      NULL,
      FALSE,
    ];
    $data[] = [
      'visual_inline',
      'unexpected_route_name',
      NULL,
      FALSE,
    ];
    $data[] = [
      'visual_inline',
      'diff.revisions_diff',
      'unexpected_config_value',
      FALSE,
    ];
    $data[] = [
      'visual_inline',
      'diff.revisions_diff',
      'default',
      TRUE,
    ];
    $data[] = [
      'visual_inline',
      'entity.foo.revisions_diff',
      'default',
      TRUE,
    ];
    return $data;
  }

}

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.
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.
VisualDiffThemeNegotiatorTest::$configFactory protected property The config factory.
VisualDiffThemeNegotiatorTest::$themeNegotiator protected property The class under test.
VisualDiffThemeNegotiatorTest::providerTestApplies public function Provides test data to ::testApplies().
VisualDiffThemeNegotiatorTest::setUp protected function Overrides UnitTestCase::setUp
VisualDiffThemeNegotiatorTest::testApplies public function Tests if the theme negotiator applies under correct conditions.
VisualDiffThemeNegotiatorTest::testDetermineActiveTheme public function @covers ::determineActiveTheme