class AjaxResponseTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php \Drupal\Tests\Core\Ajax\AjaxResponseTest
@coversDefaultClass \Drupal\Core\Ajax\AjaxResponse @group Ajax
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Ajax\AjaxResponseTest
Expanded class hierarchy of AjaxResponseTest
File
- core/
tests/ Drupal/ Tests/ Core/ Ajax/ AjaxResponseTest.php, line 21 - Contains \Drupal\Tests\Core\Ajax\AjaxResponseTest.
Namespace
Drupal\Tests\Core\AjaxView source
class AjaxResponseTest extends UnitTestCase {
/**
* The tested ajax response object.
*
* @var \Drupal\Core\Ajax\AjaxResponse
*/
protected $ajaxResponse;
protected function setUp() {
$this->ajaxResponse = new AjaxResponse();
}
/**
* Tests the add and getCommands method.
*
* @see \Drupal\Core\Ajax\AjaxResponse::addCommand()
* @see \Drupal\Core\Ajax\AjaxResponse::getCommands()
*/
public function testCommands() {
$command_one = $this
->getMock('Drupal\\Core\\Ajax\\CommandInterface');
$command_one
->expects($this
->once())
->method('render')
->will($this
->returnValue(array(
'command' => 'one',
)));
$command_two = $this
->getMock('Drupal\\Core\\Ajax\\CommandInterface');
$command_two
->expects($this
->once())
->method('render')
->will($this
->returnValue(array(
'command' => 'two',
)));
$command_three = $this
->getMock('Drupal\\Core\\Ajax\\CommandInterface');
$command_three
->expects($this
->once())
->method('render')
->will($this
->returnValue(array(
'command' => 'three',
)));
$this->ajaxResponse
->addCommand($command_one);
$this->ajaxResponse
->addCommand($command_two);
$this->ajaxResponse
->addCommand($command_three, TRUE);
// Ensure that the added commands are in the right order.
$commands =& $this->ajaxResponse
->getCommands();
$this
->assertSame($commands[1], array(
'command' => 'one',
));
$this
->assertSame($commands[2], array(
'command' => 'two',
));
$this
->assertSame($commands[0], array(
'command' => 'three',
));
// Remove one and change one element from commands and ensure the reference
// worked as expected.
unset($commands[2]);
$commands[0]['class'] = 'test-class';
$commands = $this->ajaxResponse
->getCommands();
$this
->assertSame($commands[1], array(
'command' => 'one',
));
$this
->assertFalse(isset($commands[2]));
$this
->assertSame($commands[0], array(
'command' => 'three',
'class' => 'test-class',
));
}
/**
* Tests the support for IE specific headers in file uploads.
*
* @cover ::prepareResponse
*/
public function testPrepareResponseForIeFormRequestsWithFileUpload() {
$request = Request::create('/example', 'POST');
$request->headers
->set('Accept', 'text/html');
$response = new AjaxResponse([]);
$response->headers
->set('Content-Type', 'application/json; charset=utf-8');
$ajax_response_attachments_processor = $this
->getMock('\\Drupal\\Core\\Render\\AttachmentsResponseProcessorInterface');
$subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
$event = new FilterResponseEvent($this
->getMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST, $response);
$subscriber
->onResponse($event);
$this
->assertEquals('text/html; charset=utf-8', $response->headers
->get('Content-Type'));
$this
->assertEquals($response
->getContent(), '<textarea>[]</textarea>');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxResponseTest:: |
protected | property | The tested ajax response object. | |
AjaxResponseTest:: |
protected | function |
Overrides UnitTestCase:: |
|
AjaxResponseTest:: |
public | function | Tests the add and getCommands method. | |
AjaxResponseTest:: |
public | function | Tests the support for IE specific headers in file uploads. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |