You are here

class ComponentSectionFormHandlerTest in Module Builder 8.3

Tests the ComponentSectionFormHandler entity handler.

@group module_builder

Hierarchy

Expanded class hierarchy of ComponentSectionFormHandlerTest

File

tests/src/Unit/ComponentSectionFormHandlerTest.php, line 12

Namespace

Drupal\Tests\module_builder\Unit
View source
class ComponentSectionFormHandlerTest extends UnitTestCase {

  /**
   * The modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'system',
    'module_builder',
  ];

  /**
   * Tests the ComponentSectionFormHandler entity handler.
   */
  public function testComponentSectionFormHandler() {
    $entity_code_builder_annotation_data = [
      "section_forms" => [
        "name" => [
          "title" => "Edit basic properties",
          "tab_title" => "Name",
          "properties" => [
            "name_1",
            "name_2",
            "name_3",
          ],
        ],
        "hooks" => [
          "title" => "Edit hooks",
          "tab_title" => "Hooks",
          "properties" => [
            "hooks_1",
          ],
        ],
      ],
    ];
    $entity_type = $this
      ->prophesize(\Drupal\Core\Entity\EntityTypeInterface::class);
    $entity_type
      ->id()
      ->willReturn('test');
    $entity_type
      ->get('code_builder')
      ->willReturn($entity_code_builder_annotation_data);

    // Create the handler, with mock passed in.
    $component_sections_handler = new \Drupal\module_builder\EntityHandler\ComponentSectionFormHandler($entity_type
      ->reveal());
    $form_operations_expected = [
      'hooks',
      'misc',
      'generate',
    ];
    $this
      ->assertEquals($form_operations_expected, $component_sections_handler
      ->getFormOperations());
    $form_tab_routes_expected = [
      'hooks' => "Edit hooks",
      'misc' => "Edit %label miscellaneous components",
      'generate' => 'Generate code for %label',
    ];
    $this
      ->assertEquals($form_tab_routes_expected, $component_sections_handler
      ->getFormTabRoutePaths());
    $form_tab_tasks_expected = [
      'hooks' => "Hooks",
      'misc' => "Misc",
      'generate' => 'Generate code',
    ];
    $this
      ->assertEquals($form_tab_tasks_expected, $component_sections_handler
      ->getFormTabLocalTasksData());
    $this
      ->assertEquals([
      "name_1",
      "name_2",
      "name_3",
    ], $component_sections_handler
      ->getSectionFormComponentProperties('name'));
    $this
      ->assertEquals([
      "hooks_1",
    ], $component_sections_handler
      ->getSectionFormComponentProperties('hooks'));
    $this
      ->assertEquals([
      "name_1",
      "name_2",
      "name_3",
      "hooks_1",
    ], $component_sections_handler
      ->getUsedComponentProperties());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ComponentSectionFormHandlerTest::$modules public static property The modules to enable.
ComponentSectionFormHandlerTest::testComponentSectionFormHandler public function Tests the ComponentSectionFormHandler entity handler.
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