You are here

class BlockDisplayVariantTest in Chaos Tool Suite (ctools) 8.3

Same name in this branch
  1. 8.3 tests/src/Unit/BlockDisplayVariantTest.php \Drupal\Tests\ctools\Unit\BlockDisplayVariantTest
  2. 8.3 tests/src/Kernel/BlockDisplayVariantTest.php \Drupal\Tests\ctools\Kernel\BlockDisplayVariantTest

Tests the block display variant plugin.

@coversDefaultClass \Drupal\ctools\Plugin\DisplayVariant\BlockDisplayVariant

@group CTools

Hierarchy

Expanded class hierarchy of BlockDisplayVariantTest

File

tests/src/Unit/BlockDisplayVariantTest.php, line 22

Namespace

Drupal\Tests\ctools\Unit
View source
class BlockDisplayVariantTest extends UnitTestCase {

  /**
   * Tests the submitConfigurationForm() method.
   *
   * @covers ::submitConfigurationForm
   *
   * @dataProvider providerTestSubmitConfigurationForm
   */
  public function testSubmitConfigurationForm($values) {
    $account = $this
      ->prophesize(AccountInterface::class);
    $context_handler = $this
      ->prophesize(ContextHandlerInterface::class);
    $uuid_generator = $this
      ->prophesize(UuidInterface::class);
    $token = $this
      ->prophesize(Token::class);
    $block_manager = $this
      ->prophesize(BlockManager::class);
    $condition_manager = $this
      ->prophesize(ConditionManager::class);
    $display_variant = new class([], '', [], $context_handler
      ->reveal(), $account
      ->reveal(), $uuid_generator
      ->reveal(), $token
      ->reveal(), $block_manager
      ->reveal(), $condition_manager
      ->reveal()) extends BlockDisplayVariant {

      /**
       * {@inheritdoc}
       */
      public function build() {
        return [];
      }
      public function getRegionNames() {
        return [
          'top' => 'Top',
          'bottom' => 'Bottom',
        ];
      }

    };
    $form = [];
    $form_state = (new FormState())
      ->setValues($values);
    $display_variant
      ->submitConfigurationForm($form, $form_state);
    $this
      ->assertSame($values['label'], $display_variant
      ->label());
  }

  /**
   * Provides data for testSubmitConfigurationForm().
   */
  public function providerTestSubmitConfigurationForm() {
    $data = [];
    $data[] = [
      [
        'label' => 'test_label1',
      ],
    ];
    $data[] = [
      [
        'label' => 'test_label2',
        'blocks' => [
          'foo1' => [],
        ],
      ],
    ];
    $data[] = [
      [
        'label' => 'test_label3',
        'blocks' => [
          'foo1' => [],
          'foo2' => [],
        ],
      ],
    ];
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockDisplayVariantTest::providerTestSubmitConfigurationForm public function Provides data for testSubmitConfigurationForm().
BlockDisplayVariantTest::testSubmitConfigurationForm public function Tests the submitConfigurationForm() method.
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