コード例 #1
0
ファイル: AjaxResponseTest.php プロジェクト: 318io/318-io
 /**
  * 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>');
 }
コード例 #2
0
 /**
  * Tests GetUntransformedTextCommand AJAX command.
  */
 public function testGetUntransformedTextCommand()
 {
     // Create an entity with values for the field.
     $entity = entity_create('entity_test');
     $entity->{$this->fieldName}->value = 'Test';
     $entity->{$this->fieldName}->format = 'full_html';
     $entity->save();
     $entity = entity_load('entity_test', $entity->id());
     // Verify AJAX response.
     $controller = new EditorController();
     $request = new Request();
     $response = $controller->getUntransformedText($entity, $this->fieldName, LanguageInterface::LANGCODE_NOT_SPECIFIED, 'default');
     $expected = array(array('command' => 'editorGetUntransformedText', 'data' => 'Test'));
     $ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
     $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
     $event = new FilterResponseEvent(\Drupal::service('http_kernel'), $request, HttpKernelInterface::MASTER_REQUEST, $response);
     $subscriber->onResponse($event);
     $this->assertEqual(Json::encode($expected), $response->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.');
 }
コード例 #3
0
ファイル: CommandsTest.php プロジェクト: papillon-cendre/d8
 /**
  * Regression test: Settings command exists regardless of JS aggregation.
  */
 public function testAttachedSettings()
 {
     $assert = function ($message) {
         $response = new AjaxResponse();
         $response->setAttachments(['library' => ['core/drupalSettings'], 'drupalSettings' => ['foo' => 'bar']]);
         $ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
         $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
         $event = new FilterResponseEvent(\Drupal::service('http_kernel'), new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
         $subscriber->onResponse($event);
         $expected = ['command' => 'settings'];
         $this->assertCommand($response->getCommands(), $expected, $message);
     };
     $config = $this->config('system.performance');
     $config->set('js.preprocess', FALSE)->save();
     $assert('Settings command exists when JS aggregation is disabled.');
     $config->set('js.preprocess', TRUE)->save();
     $assert('Settings command exists when JS aggregation is enabled.');
 }