Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -108,6 +108,20 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame($expected, $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testGetListenerPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
|
||||
$this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
|
||||
$this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
|
||||
}
|
||||
|
||||
public function testDispatch()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
||||
|
|
|
@ -59,6 +59,18 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
|
|||
->with($event)
|
||||
;
|
||||
|
||||
$service
|
||||
->expects($this->once())
|
||||
->method('onEventWithPriority')
|
||||
->with($event)
|
||||
;
|
||||
|
||||
$service
|
||||
->expects($this->once())
|
||||
->method('onEventNested')
|
||||
->with($event)
|
||||
;
|
||||
|
||||
$container = new Container();
|
||||
$container->set('service.subscriber', $service);
|
||||
|
||||
|
@ -66,6 +78,8 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
|
|||
$dispatcher->addSubscriberService('service.subscriber', 'Symfony\Component\EventDispatcher\Tests\SubscriberService');
|
||||
|
||||
$dispatcher->dispatch('onEvent', $event);
|
||||
$dispatcher->dispatch('onEventWithPriority', $event);
|
||||
$dispatcher->dispatch('onEventNested', $event);
|
||||
}
|
||||
|
||||
public function testPreventDuplicateListenerService()
|
||||
|
@ -92,6 +106,7 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
|
|||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTriggerAListenerServiceOutOfScope()
|
||||
{
|
||||
|
@ -111,6 +126,9 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
|
|||
$dispatcher->dispatch('onEvent');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testReEnteringAScope()
|
||||
{
|
||||
$event = new Event();
|
||||
|
@ -239,11 +257,21 @@ class SubscriberService implements EventSubscriberInterface
|
|||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onEvent' => array('onEvent'),
|
||||
'onEvent' => 'onEvent',
|
||||
'onEventWithPriority' => array('onEventWithPriority', 10),
|
||||
'onEventNested' => array(array('onEventNested')),
|
||||
);
|
||||
}
|
||||
|
||||
public function onEvent(Event $e)
|
||||
{
|
||||
}
|
||||
|
||||
public function onEventWithPriority(Event $e)
|
||||
{
|
||||
}
|
||||
|
||||
public function onEventNested(Event $e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
|
||||
$tdispatcher->addListener('foo', $listener = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener = function () {});
|
||||
$listeners = $dispatcher->getListeners('foo');
|
||||
$this->assertCount(1, $listeners);
|
||||
$this->assertSame($listener, $listeners[0]);
|
||||
|
@ -39,7 +39,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
|
||||
$tdispatcher->addListener('foo', $listener = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener = function () {});
|
||||
$this->assertSame($dispatcher->getListeners('foo'), $tdispatcher->getListeners('foo'));
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,28 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertFalse($dispatcher->hasListeners('foo'));
|
||||
$this->assertFalse($tdispatcher->hasListeners('foo'));
|
||||
|
||||
$tdispatcher->addListener('foo', $listener = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener = function () {});
|
||||
$this->assertTrue($dispatcher->hasListeners('foo'));
|
||||
$this->assertTrue($tdispatcher->hasListeners('foo'));
|
||||
}
|
||||
|
||||
public function testGetListenerPriority()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
|
||||
$tdispatcher->addListener('foo', function () {}, 123);
|
||||
|
||||
$listeners = $dispatcher->getListeners('foo');
|
||||
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
|
||||
|
||||
// Verify that priority is preserved when listener is removed and re-added
|
||||
// in preProcess() and postProcess().
|
||||
$tdispatcher->dispatch('foo', new Event());
|
||||
$listeners = $dispatcher->getListeners('foo');
|
||||
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
|
||||
}
|
||||
|
||||
public function testAddRemoveSubscriber()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
@ -76,14 +93,14 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
$tdispatcher->addListener('foo', $listener = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener = function () {});
|
||||
|
||||
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getNotCalledListeners());
|
||||
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => 0)), $tdispatcher->getNotCalledListeners());
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
|
||||
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure')), $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => null)), $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
|
||||
}
|
||||
|
||||
|
@ -107,8 +124,8 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
|
||||
$tdispatcher->addListener('foo', $listener1 = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener1 = function () {});
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
|
||||
$logger->expects($this->at(1))->method('debug')->with('Notified event "foo" to listener "closure".');
|
||||
|
@ -123,7 +140,7 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
|
||||
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {; });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->at(0))->method('debug')->with('Notified event "foo" to listener "closure".');
|
||||
$logger->expects($this->at(1))->method('debug')->with('Listener "closure" stopped propagation of the event "foo".');
|
||||
|
@ -138,12 +155,12 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
$tdispatcher->addListener('foo', $listener1 = function () use (&$called) { $called[] = 'foo1'; });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () use (&$called) { $called[] = 'foo2'; });
|
||||
$tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10);
|
||||
$tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
|
||||
$this->assertEquals(array('foo1', 'foo2'), $called);
|
||||
$this->assertSame(array('foo2', 'foo1'), $called);
|
||||
}
|
||||
|
||||
public function testDispatchNested()
|
||||
|
|
Reference in a new issue