use Drupal\Core\Form\FormAjaxException;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormState;
+use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
*/
protected $stringTranslation;
+ /**
+ * The mocked messenger.
+ *
+ * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $messenger;
+
/**
* {@inheritdoc}
*/
$this->httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$this->formAjaxResponseBuilder = $this->getMock('Drupal\Core\Form\FormAjaxResponseBuilderInterface');
$this->stringTranslation = $this->getStringTranslationStub();
- $this->subscriber = new FormAjaxSubscriber($this->formAjaxResponseBuilder, $this->stringTranslation);
+ $this->messenger = $this->createMock(MessengerInterface::class);
+ $this->subscriber = new FormAjaxSubscriber($this->formAjaxResponseBuilder, $this->stringTranslation, $this->messenger);
}
/**
public function testOnExceptionBrokenPostRequest() {
$this->formAjaxResponseBuilder->expects($this->never())
->method('buildResponse');
+
+ $this->messenger->expects($this->once())
+ ->method('addError');
+
$this->subscriber = $this->getMockBuilder('\Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber')
- ->setConstructorArgs([$this->formAjaxResponseBuilder, $this->getStringTranslationStub()])
- ->setMethods(['drupalSetMessage', 'formatSize'])
+ ->setConstructorArgs([
+ $this->formAjaxResponseBuilder,
+ $this->getStringTranslationStub(),
+ $this->messenger,
+ ])
+ ->setMethods(['formatSize'])
->getMock();
- $this->subscriber->expects($this->once())
- ->method('drupalSetMessage')
- ->willReturn('asdf');
+
$this->subscriber->expects($this->once())
->method('formatSize')
->with(32 * 1e6)