class RenderElementTest in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest
@coversDefaultClass \Drupal\Core\Render\Element\RenderElement @group Render
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Render\Element\RenderElementTest
Expanded class hierarchy of RenderElementTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ Element/ RenderElementTest.php, line 17
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() {
$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 = RenderElement::preRenderAjaxForm($element);
$this
->assertTrue($element['#ajax_processed']);
$this
->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
}
/**
* @covers ::preRenderAjaxForm
*/
public function testPreRenderAjaxFormWithQueryOptions() {
$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 = RenderElement::preRenderAjaxForm($element);
$this
->assertTrue($element['#ajax_processed']);
$this
->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
RenderElementTest:: |
protected | property | The container. | |
RenderElementTest:: |
protected | property | The request stack. | |
RenderElementTest:: |
protected | function |
Overrides UnitTestCase:: |
|
RenderElementTest:: |
public | function | @covers ::preRenderAjaxForm | |
RenderElementTest:: |
public | function | @covers ::preRenderAjaxForm | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |