class MediaLibrarySelectFormTest

Same name in other branches
  1. 11.x core/modules/media_library/tests/src/Unit/MediaLibrarySelectFormTest.php \Drupal\Tests\media_library\Unit\MediaLibrarySelectFormTest

@coversDefaultClass \Drupal\media_library\Plugin\views\field\MediaLibrarySelectForm @group media_library

Hierarchy

Expanded class hierarchy of MediaLibrarySelectFormTest

File

core/modules/media_library/tests/src/Unit/MediaLibrarySelectFormTest.php, line 24

Namespace

Drupal\Tests\media_library\Unit
View source
class MediaLibrarySelectFormTest extends UnitTestCase {
    
    /**
     * {@inheritdoc}
     */
    protected function tearDown() : void {
        parent::tearDown();
        $container = new ContainerBuilder();
        \Drupal::setContainer($container);
    }
    
    /**
     * @covers ::viewsForm
     */
    public function testViewsForm() : void {
        $row = new ResultRow();
        $field = $this->getMockBuilder(MediaLibrarySelectForm::class)
            ->onlyMethods([
            'getEntity',
        ])
            ->disableOriginalConstructor()
            ->getMock();
        $field->expects($this->any())
            ->method('getEntity')
            ->willReturn(NULL);
        $container = new ContainerBuilder();
        $container->set('string_translation', $this->createMock(TranslationInterface::class));
        \Drupal::setContainer($container);
        $request = $this->getMockBuilder(Request::class)
            ->disableOriginalConstructor()
            ->getMock();
        $request->query = new InputBag();
        $view = $this->getMockBuilder(ViewExecutable::class)
            ->onlyMethods([
            'getRequest',
            'initStyle',
            'getDisplay',
        ])
            ->disableOriginalConstructor()
            ->getMock();
        $view->expects($this->any())
            ->method('getRequest')
            ->willReturn($request);
        $view->expects($this->any())
            ->method('initStyle')
            ->willReturn(TRUE);
        $display = $this->getMockBuilder(DefaultDisplay::class)
            ->disableOriginalConstructor()
            ->getMock();
        $display->display['id'] = 'foo';
        $view->expects($this->any())
            ->method('getDisplay')
            ->willReturn($display);
        $view_entity = $this->getMockBuilder(View::class)
            ->disableOriginalConstructor()
            ->getMock();
        $view_entity->expects($this->any())
            ->method('get')
            ->willReturn([]);
        $view->storage = $view_entity;
        $display_manager = $this->getMockBuilder(ViewsPluginManager::class)
            ->disableOriginalConstructor()
            ->getMock();
        $display = $this->getMockBuilder(DefaultDisplay::class)
            ->disableOriginalConstructor()
            ->getMock();
        $display_manager->expects($this->any())
            ->method('createInstance')
            ->willReturn($display);
        $container->set('plugin.manager.views.display', $display_manager);
        \Drupal::setContainer($container);
        $form_state = $this->createMock(FormStateInterface::class);
        $view->result = [
            $row,
        ];
        $field->view = $view;
        $field->options = [
            'id' => 'bar',
        ];
        $form = [];
        $field->viewsForm($form, $form_state);
        $this->assertNotEmpty($form);
        $this->assertNotEmpty($field->view->result);
        $this->assertIsArray($form[$field->options['id']][0]);
        $this->assertEmpty($form[$field->options['id']][0]);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
MediaLibrarySelectFormTest::tearDown protected function
MediaLibrarySelectFormTest::testViewsForm public function @covers ::viewsForm
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
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.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 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::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 358
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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