function FormTestBase::setUp
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::setUp()
- 8.9.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::setUp()
- 10 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::setUp()
Overrides UnitTestCase::setUp
1 call to FormTestBase::setUp()
- FormBuilderTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php
1 method overrides FormTestBase::setUp()
- FormBuilderTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php
File
-
core/
tests/ Drupal/ Tests/ Core/ Form/ FormTestBase.php, line 158
Class
- FormTestBase
- Provides a base class for testing form functionality.
Namespace
Drupal\Tests\Core\FormCode
protected function setUp() : void {
parent::setUp();
// Add functions to the global namespace for testing.
require_once __DIR__ . '/fixtures/form_base_test.inc';
$this->moduleHandler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->formCache = $this->createMock('Drupal\\Core\\Form\\FormCacheInterface');
$this->cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->urlGenerator = $this->createMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$this->redirectResponseSubscriber = $this->createMock(RedirectResponseSubscriber::class);
$this->classResolver = $this->getClassResolverStub();
$this->elementInfo = $this->getMockBuilder('\\Drupal\\Core\\Render\\ElementInfoManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->elementInfo
->expects($this->any())
->method('getInfo')
->willReturnCallback([
$this,
'getInfo',
]);
$this->csrfToken = $this->getMockBuilder('Drupal\\Core\\Access\\CsrfTokenGenerator')
->disableOriginalConstructor()
->getMock();
$this->kernel = $this->getMockBuilder('\\Drupal\\Core\\DrupalKernel')
->disableOriginalConstructor()
->getMock();
$this->account = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
$this->themeManager = $this->createMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
$this->request = Request::createFromGlobals();
$this->request
->setSession(new Session(new MockArraySessionStorage()));
$this->eventDispatcher = $this->createMock('Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface');
$this->requestStack = new RequestStack();
$this->requestStack
->push($this->request);
$this->logger = $this->createMock('Drupal\\Core\\Logger\\LoggerChannelInterface');
$form_error_handler = $this->createMock('Drupal\\Core\\Form\\FormErrorHandlerInterface');
$this->formValidator = new FormValidator($this->requestStack, $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $form_error_handler);
$this->formSubmitter = $this->getMockBuilder('Drupal\\Core\\Form\\FormSubmitter')
->setConstructorArgs([
$this->requestStack,
$this->urlGenerator,
$this->redirectResponseSubscriber,
])
->onlyMethods([
'batchGet',
])
->getMock();
$this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
$this->formBuilder = new FormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->elementInfo, $this->themeManager, $this->csrfToken);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.