Commit 53fb20e1 authored by Marcin Grabias's avatar Marcin Grabias
Browse files

Fixed UI AJAX for updated Symphony; updated and improved automated tests.

parent b4592464
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -340,9 +340,13 @@ class ViewsBulkOperationsCommands extends DrushCommands {
  /**
  /**
   * Message method.
   * Message method.
   *
   *
   * Overrides the one from the trait amd uses Drush logger.
   * Overrides the one from the trait and uses Drush logger.
   */
   */
  public static function message($message = NULL, $type = 'status', $repeat = TRUE) {
  public static function message($message = NULL, $type = 'status', $repeat = TRUE) {
    // Status type no longer exists, mapping required.
    if ($type === 'status') {
      $type = 'info';
    }
    Drush::logger()->log($type, $message, []);
    Drush::logger()->log($type, $message, []);
  }
  }


+9 −9
Original line number Original line Diff line number Diff line
@@ -111,22 +111,22 @@ class ViewsBulkOperationsController extends ControllerBase implements ContainerI
      throw new NotFoundHttpException();
      throw new NotFoundHttpException();
    }
    }


    $list = $request->request->get('list');
    //$list = json_decode($request->request->get('list'));
    $parameters = $request->request->all();


    $op = $request->request->get('op', 'check');
    // Reverse operation when in exclude mode.
    // Reverse operation when in exclude mode.
    if (!empty($tempstore_data['exclude_mode'])) {
    if (!empty($tempstore_data['exclude_mode'])) {
      if ($op === 'add') {
      if ($parameters['op'] === 'add') {
        $op = 'remove';
        $parameters['op'] = 'remove';
      }
      }
      elseif ($op === 'remove') {
      elseif ($parameters['op'] === 'remove') {
        $op = 'add';
        $parameters['op'] = 'add';
      }
      }
    }
    }


    switch ($op) {
    switch ($parameters['op']) {
      case 'add':
      case 'add':
        foreach ($list as $bulkFormKey) {
        foreach ($parameters['list'] as $bulkFormKey) {
          if (!isset($tempstore_data['list'][$bulkFormKey])) {
          if (!isset($tempstore_data['list'][$bulkFormKey])) {
            $tempstore_data['list'][$bulkFormKey] = $this->getListItem($bulkFormKey);
            $tempstore_data['list'][$bulkFormKey] = $this->getListItem($bulkFormKey);
          }
          }
@@ -134,7 +134,7 @@ class ViewsBulkOperationsController extends ControllerBase implements ContainerI
        break;
        break;


      case 'remove':
      case 'remove':
        foreach ($list as $bulkFormKey) {
        foreach ($parameters['list'] as $bulkFormKey) {
          if (isset($tempstore_data['list'][$bulkFormKey])) {
          if (isset($tempstore_data['list'][$bulkFormKey])) {
            unset($tempstore_data['list'][$bulkFormKey]);
            unset($tempstore_data['list'][$bulkFormKey]);
          }
          }
+1 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@ class DrushCommandsTest extends BrowserTestBase {
  /**
  /**
   * {@inheritdoc}
   * {@inheritdoc}
   */
   */
  protected $defaultTheme = 'stark';
  protected $defaultTheme = 'stable9';


  /**
  /**
   * Modules to install.
   * Modules to install.
+1 −1
Original line number Original line Diff line number Diff line
@@ -15,7 +15,7 @@ abstract class ViewsBulkOperationsFunctionalTestBase extends BrowserTestBase {
  /**
  /**
   * {@inheritdoc}
   * {@inheritdoc}
   */
   */
  protected $defaultTheme = 'stable';
  protected $defaultTheme = 'stable9';


  /**
  /**
   * Modules to install.
   * Modules to install.
+17 −10
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ class ViewsBulkOperationsBulkFormTest extends WebDriverTestBase {
  /**
  /**
   * {@inheritdoc}
   * {@inheritdoc}
   */
   */
  protected $defaultTheme = 'stable';
  protected $defaultTheme = 'stable9';




  /**
  /**
@@ -80,9 +80,10 @@ class ViewsBulkOperationsBulkFormTest extends WebDriverTestBase {
    // Create some nodes for testing.
    // Create some nodes for testing.
    $this->drupalCreateContentType(['type' => 'page']);
    $this->drupalCreateContentType(['type' => 'page']);
    for ($i = 0; $i <= self::TEST_NODE_COUNT; $i++) {
    for ($i = 0; $i <= self::TEST_NODE_COUNT; $i++) {
      $this->drupalCreateNode([
      $this->testNodes[] = $this->drupalCreateNode([
        'type' => 'page',
        'type' => 'page',
        'title' => 'Title ' . $i,
        'title' => 'Title ' . $i,
        'created' => 1000 + self::TEST_NODE_COUNT - $i,
      ]);
      ]);
    }
    }
    $admin_user = $this->drupalCreateUser(
    $admin_user = $this->drupalCreateUser(
@@ -145,10 +146,10 @@ class ViewsBulkOperationsBulkFormTest extends WebDriverTestBase {
    // Assert if only the selected nodes were processed.
    // Assert if only the selected nodes were processed.
    foreach ($this->testNodes as $delta => $node) {
    foreach ($this->testNodes as $delta => $node) {
      if (\in_array($delta, $this->selectedIndexes, TRUE)) {
      if (\in_array($delta, $this->selectedIndexes, TRUE)) {
        $this->assertSession->pageTextContains(\sprintf('Test action (preconfig: Test setting, label: %s)', $node->label()));
        $this->assertSession->pageTextContains(\sprintf('Test action (label: %s)', $node->label()));
      }
      }
      else {
      else {
        $this->assertSession->pageTextNotContains(\sprintf('Test action (preconfig: Test setting, label: %s)', $node->label()));
        $this->assertSession->pageTextNotContains(\sprintf('Test action (label: %s)', $node->label()));
      }
      }
    }
    }
    $this->assertSession->pageTextContains(\sprintf('Action processing results: Test (%s)', \count($this->selectedIndexes)));
    $this->assertSession->pageTextContains(\sprintf('Action processing results: Test (%s)', \count($this->selectedIndexes)));
@@ -168,21 +169,27 @@ class ViewsBulkOperationsBulkFormTest extends WebDriverTestBase {
      $this->page->checkField('views_bulk_operations_bulk_form[' . $selected_index . ']');
      $this->page->checkField('views_bulk_operations_bulk_form[' . $selected_index . ']');
    }
    }


    // Insert nodes.
    // Insert nodes that .
    $nodes = [];
    for ($i = 0; $i < self::TEST_NODE_COUNT; $i++) {
    for ($i = 100; $i < 100 + self::TEST_NODE_COUNT; $i++) {
      $this->drupalCreateNode([
      $nodes[] = $this->drupalCreateNode([
        'type' => 'page',
        'type' => 'page',
        'title' => 'Title ' . $i,
        'title' => 'Title added ' . $i,
        'created' => 2000 + self::TEST_NODE_COUNT - $i,
      ]);
      ]);
    }
    }


    $this->page->pressButton('Simple test action');
    $this->page->pressButton('Simple test action');


    foreach ($this->selectedIndexes as $index) {
    foreach ($this->selectedIndexes as $index) {
      $this->assertSession->pageTextContains(\sprintf('Test action (label: Title %s)', self::TEST_NODE_COUNT - $index));
      $this->assertSession->pageTextContains(\sprintf('Test action (label: Title %s)', $index));
    }
    }
    $this->assertSession->pageTextContains(\sprintf('Action processing results: Test (%s)', \count($this->selectedIndexes)));
    $this->assertSession->pageTextContains(\sprintf('Action processing results: Test (%s)', \count($this->selectedIndexes)));

    // Check that the view now actually contains the new nodes in place of the
    // previously displayed ones.
    for ($i = 0; $i < $this->testViewParams['items_per_page']; $i++) {
      $this->assertSession->pageTextContains(\sprintf('Title added %s', $i));
    }
  }
  }


}
}
Loading