CorsResponseEventSubscriberTest.php in CORS 8
File
tests/src/Unit/EventSubscriber/CorsResponseEventSubscriberTest.php
View source
<?php
namespace Drupal\Tests\cors\Unit\EventSubscriber;
use Drupal\Tests\UnitTestCase;
use Drupal\cors\EventSubscriber\CorsResponseEventSubscriber;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class CorsResponseEventSubscriberTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'CORS Response Event Subscriber',
'description' => 'Tests the CORS response event subscriber',
'group' => 'CORS',
);
}
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));
$subscriber = new CorsResponseEventSubscriber($config_factory, $alias_manager, $path_matcher);
$http_kernel = $this
->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$request = new Request();
$response = new Response();
$event = new FilterResponseEvent($http_kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$subscriber
->addCorsHeaders($event);
$this
->assertEquals('*', $response->headers
->get('access-control-allow-origin'), "The access-control-allow-origin header was set");
}
}