class FieldConfigEditFormTest

Same name and namespace in other branches
  1. 10 core/modules/field_ui/tests/src/Unit/FieldConfigEditFormTest.php \Drupal\Tests\field_ui\Unit\FieldConfigEditFormTest

@coversDefaultClass \Drupal\field_ui\Form\FieldConfigEditForm

@group field_ui

Hierarchy

Expanded class hierarchy of FieldConfigEditFormTest

File

core/modules/field_ui/tests/src/Unit/FieldConfigEditFormTest.php, line 18

Namespace

Drupal\Tests\field_ui\Unit
View source
class FieldConfigEditFormTest extends UnitTestCase {
    
    /**
     * The field config edit form.
     *
     * @var \Drupal\field_ui\Form\FieldConfigEditForm|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $fieldConfigEditForm;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $entity_type_bundle_info = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeBundleInfoInterface');
        $typed_data = $this->createMock('\\Drupal\\Core\\TypedData\\TypedDataManagerInterface');
        $temp_store = $this->createMock(PrivateTempStore::class);
        $element_info_manager = $this->createMock(ElementInfoManagerInterface::class);
        $entity_display_repository = $this->createMock(EntityDisplayRepositoryInterface::class);
        $this->fieldConfigEditForm = new FieldConfigEditForm($entity_type_bundle_info, $typed_data, $entity_display_repository, $temp_store, $element_info_manager);
    }
    
    /**
     * @covers ::hasAnyRequired
     *
     * @dataProvider providerRequired
     */
    public function testHasAnyRequired(array $element, bool $result) : void {
        $reflection = new \ReflectionClass('\\Drupal\\field_ui\\Form\\FieldConfigEditForm');
        $method = $reflection->getMethod('hasAnyRequired');
        $this->assertEquals($result, $method->invoke($this->fieldConfigEditForm, $element));
    }
    
    /**
     * Provides test cases with required and optional elements.
     */
    public static function providerRequired() : \Generator {
        (yield 'required' => [
            [
                [
                    '#required' => TRUE,
                ],
            ],
            TRUE,
        ]);
        (yield 'optional' => [
            [
                [
                    '#required' => FALSE,
                ],
            ],
            FALSE,
        ]);
        (yield 'required and optional' => [
            [
                [
                    '#required' => TRUE,
                ],
                [
                    '#required' => FALSE,
                ],
            ],
            TRUE,
        ]);
        (yield 'empty' => [
            [
                [],
                [],
            ],
            FALSE,
        ]);
        (yield 'multiple required' => [
            [
                [
                    [
                        '#required' => TRUE,
                    ],
                ],
                [
                    [
                        '#required' => TRUE,
                    ],
                ],
            ],
            TRUE,
        ]);
        (yield 'multiple optional' => [
            [
                [
                    [
                        '#required' => FALSE,
                    ],
                ],
                [
                    [
                        '#required' => FALSE,
                    ],
                ],
            ],
            FALSE,
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
FieldConfigEditFormTest::$fieldConfigEditForm protected property The field config edit form.
FieldConfigEditFormTest::providerRequired public static function Provides test cases with required and optional elements.
FieldConfigEditFormTest::setUp protected function Overrides UnitTestCase::setUp
FieldConfigEditFormTest::testHasAnyRequired public function @covers ::hasAnyRequired
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
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::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.