class CorsResponseEventSubscriberTest in CORS 8
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cors\Unit\EventSubscriber\CorsResponseEventSubscriberTest
Expanded class hierarchy of CorsResponseEventSubscriberTest
File
- tests/
src/ Unit/ EventSubscriber/ CorsResponseEventSubscriberTest.php, line 20 - Contains Drupal\Tests\cors\Unit\EventSubscriber\CorsResponseEventSubscriberTest.
Namespace
Drupal\Tests\cors\Unit\EventSubscriberView source
class CorsResponseEventSubscriberTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'CORS Response Event Subscriber',
'description' => 'Tests the CORS response event subscriber',
'group' => 'CORS',
);
}
/**
* Tests adding CORS headers to the response.
*/
public function testAddCorsHeaders() {
$config_factory = $this
->getConfigFactoryStub(array(
"cors.settings" => array(
"domains" => array(
"* | http://example.com",
),
),
));
$alias_manager = $this
->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
$path_matcher = $this
->getMock('Drupal\\Core\\Path\\PathMatcherInterface');
$path_matcher
->expects($this
->any())
->method('matchPath')
->withAnyParameters()
->will($this
->returnValue(TRUE));
// Create the response event subscriber.
$subscriber = new CorsResponseEventSubscriber($config_factory, $alias_manager, $path_matcher);
// Create the response event.
$http_kernel = $this
->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$request = new Request();
$response = new Response();
$event = new FilterResponseEvent($http_kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
// Call the event handler.
$subscriber
->addCorsHeaders($event);
$this
->assertEquals('*', $response->headers
->get('access-control-allow-origin'), "The access-control-allow-origin header was set");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CorsResponseEventSubscriberTest:: |
public static | function | ||
CorsResponseEventSubscriberTest:: |
public | function | Tests adding CORS headers to the response. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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:: |
protected | function | 340 |