You are here

trait ParagraphsCoreVersionUiTestTrait in Paragraphs 8

Provides helper methods for Drupal 8.3.x and 8.4.x versions.

Hierarchy

5 files declare their use of ParagraphsCoreVersionUiTestTrait
ParagraphsAddWidgetTest.php in tests/src/FunctionalJavascript/ParagraphsAddWidgetTest.php
ParagraphsClientsideButtonsTest.php in tests/src/FunctionalJavascript/ParagraphsClientsideButtonsTest.php
ParagraphsDemoTest.php in modules/paragraphs_demo/tests/src/Functional/ParagraphsDemoTest.php
ParagraphsTestBase.php in tests/src/Functional/WidgetLegacy/ParagraphsTestBase.php
ParagraphsTypePermissionsTest.php in modules/paragraphs_type_permissions/tests/src/Functional/ParagraphsTypePermissionsTest.php

File

tests/src/Traits/ParagraphsCoreVersionUiTestTrait.php, line 8

Namespace

Drupal\Tests\paragraphs\Traits
View source
trait ParagraphsCoreVersionUiTestTrait {

  /**
   * An adapter for 8.3 > 8.4 Save (and (un)publish) node button change.
   *
   * Arguments are the same as WebTestBase::drupalPostForm.
   *
   * @see \Drupal\simpletest\WebTestBase::drupalPostForm
   * @see https://www.drupal.org/node/2847274
   *
   * @param \Drupal\Core\Url|string $path
   *   Location of the post form.
   * @param array $edit
   *   Field data in an associative array.
   * @param mixed $submit
   *   Value of the submit button whose click is to be emulated. For example,
   * @param array $options
   *   (optional) Options to be forwarded to the url generator.
   * @param array $headers
   *   (optional) An array containing additional HTTP request headers.
   * @param string $form_html_id
   *   (optional) HTML ID of the form to be submitted.
   * @param string $extra_post
   *   (optional) A string of additional data to append to the POST submission.
   */
  protected function paragraphsPostNodeForm($path, $edit, $submit, array $options = [], array $headers = [], $form_html_id = NULL, $extra_post = NULL) {
    $drupal_version = (double) substr(\Drupal::VERSION, 0, 3);
    if ($drupal_version > 8.300000000000001) {
      switch ($submit) {
        case t('Save and unpublish'):
          $submit = 'Save';
          $edit['status[value]'] = FALSE;
          break;
        case 'Save and publish':
          $submit = 'Save';
          $edit['status[value]'] = TRUE;
          break;
        case 'Save and keep published (this translation)':
          $submit = 'Save (this translation)';
          break;
        default:
          $submit = 'Save';
      }
    }
    parent::drupalPostForm($path, $edit, $submit, $options, $headers, $form_html_id, $extra_post);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsCoreVersionUiTestTrait::paragraphsPostNodeForm protected function An adapter for 8.3 > 8.4 Save (and (un)publish) node button change.