public function RefreshPageElementsHelperTest::testAjaxResponseFormBuildId in Commerce Ajax Add to Cart 8
Tests ajax response when form build id is updated.
@covers ::updateFormBuildId
File
- tests/
src/ Kernel/ RefreshPageElementsHelperTest.php, line 249  
Class
- RefreshPageElementsHelperTest
 - Tests RefreshPageElementsHelper methods.
 
Namespace
Drupal\Tests\dc_ajax_add_cart\KernelCode
public function testAjaxResponseFormBuildId() {
  $form_build_id_old = $this
    ->randomMachineName();
  $form_build_id = $this
    ->randomMachineName();
  $refreshPageElements = $this->refreshPageElementsHelper
    ->updateFormBuildId([
    '#build_id_old' => $form_build_id_old,
    '#build_id' => $form_build_id,
  ]);
  $this
    ->assertInstanceOfRefreshPageElementsHelper($refreshPageElements);
  $response = $refreshPageElements
    ->getResponse();
  $this
    ->assertAjaxResponse($response);
  // Check if the returned response has the expected ajax commands.
  $ajax_commands = $response
    ->getCommands();
  $actual_ajax_command_names = array_map(function ($i) {
    return $i['command'];
  }, $ajax_commands);
  foreach ($this->expectedAjaxCommandNamesFormBuildIdUpdate as $ajax_command_name) {
    $this
      ->assertTrue(in_array($ajax_command_name, $actual_ajax_command_names), "{$ajax_command_name} is not present");
  }
}