assertCommand example


  protected static $modules = ['node', 'ajax_test', 'ajax_forms_test'];

  /** * Verifies the Ajax rendering of a command in the settings. */
  public function testAJAXRender() {
    // Verify that settings command is generated if JavaScript settings exist.     $commands = $this->drupalGetAjax('ajax-test/render');
    $expected = new SettingsCommand(['ajax' => 'test'], TRUE);
    $this->assertCommand($commands$expected->render());
  }

  /** * Tests AjaxResponse::prepare() AJAX commands ordering. */
  public function testOrder() {
    $expected_commands = [];

    // Expected commands, in a very specific order.     $asset_resolver = \Drupal::service('asset.resolver');
    $css_collection_renderer = \Drupal::service('asset.css.collection_renderer');
    
$subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
      $event = new ResponseEvent(
        \Drupal::service('http_kernel'),
        new Request(),
        HttpKernelInterface::MAIN_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.');
  }

  
Home | Imprint | This part of the site doesn't use cookies.