class RenderElementTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest
- 8.9.x core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest
- 10 core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest
@coversDefaultClass \Drupal\Core\Render\Element\RenderElementBase @group Render
Hierarchy
- class \Drupal\Tests\Core\Render\Element\RenderElementTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RenderElementTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ Element/ RenderElementTest.php, line 19
Namespace
Drupal\Tests\Core\Render\ElementView source
class RenderElementTest extends UnitTestCase {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The container.
*
* @var \Drupal\Core\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->requestStack = new RequestStack();
$this->container = new ContainerBuilder();
$this->container
->set('request_stack', $this->requestStack);
\Drupal::setContainer($this->container);
}
/**
* @covers ::preRenderAjaxForm
*/
public function testPreRenderAjaxForm() : void {
$request = Request::create('/test');
$request->query
->set('foo', 'bar');
$this->requestStack
->push($request);
$prophecy = $this->prophesize('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$url = '/test?foo=bar&ajax_form=1';
$prophecy->generateFromRoute('<current>', [], [
'query' => [
'foo' => 'bar',
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
], TRUE)
->willReturn((new GeneratedUrl())->setCacheContexts([
'route',
])
->setGeneratedUrl($url));
$url_generator = $prophecy->reveal();
$this->container
->set('url_generator', $url_generator);
$element = [
'#type' => 'select',
'#id' => 'test',
'#ajax' => [
'wrapper' => 'foo',
'callback' => 'test-callback',
],
];
$element = RenderElementBase::preRenderAjaxForm($element);
$this->assertTrue($element['#ajax_processed']);
$this->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
}
/**
* @covers ::preRenderAjaxForm
*/
public function testPreRenderAjaxFormWithQueryOptions() : void {
$request = Request::create('/test');
$request->query
->set('foo', 'bar');
$this->requestStack
->push($request);
$prophecy = $this->prophesize('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$url = '/test?foo=bar&other=query&ajax_form=1';
$prophecy->generateFromRoute('<current>', [], [
'query' => [
'foo' => 'bar',
'other' => 'query',
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
], TRUE)
->willReturn((new GeneratedUrl())->setCacheContexts([
'route',
])
->setGeneratedUrl($url));
$url_generator = $prophecy->reveal();
$this->container
->set('url_generator', $url_generator);
$element = [
'#type' => 'select',
'#id' => 'test',
'#ajax' => [
'wrapper' => 'foo',
'callback' => 'test-callback',
'options' => [
'query' => [
'other' => 'query',
],
],
],
];
$element = RenderElementBase::preRenderAjaxForm($element);
$this->assertTrue($element['#ajax_processed']);
$this->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
}
}
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. | |
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. | |
RenderElementTest::$container | protected | property | The container. | |
RenderElementTest::$requestStack | protected | property | The request stack. | |
RenderElementTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
RenderElementTest::testPreRenderAjaxForm | public | function | @covers ::preRenderAjaxForm | |
RenderElementTest::testPreRenderAjaxFormWithQueryOptions | public | function | @covers ::preRenderAjaxForm | |
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.