You are here

protected function TextimageTestBase::createTextimageNode in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/TextimageTestBase.php \Drupal\Tests\textimage\Functional\TextimageTestBase::createTextimageNode()

Create a node.

Parameters

string $field_type: Type of the field formatted by Textimage.

string $field_name: Name of the field formatted by Textimage.

string $field_value: Value of the field formatted by Textimage.

string $bundle: The type of node to create.

string $node_title: The title of node to create.

5 calls to TextimageTestBase::createTextimageNode()
TextimageFieldFormatterTest::testTextimageCaching in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage caching.
TextimageFieldFormatterTest::testTextimageImageFieldFormatter in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage formatter on image fields.
TextimageFieldFormatterTest::testTextimageMultiValueTextFieldFormatter in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage formatter on multi-value text fields.
TextimageFieldFormatterTest::testTextimageTextFieldFormatter in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage formatter on node display and text field.
TextimageRedirectIntegrationTest::testTextimageWithRedirectInstalled in tests/src/Functional/TextimageRedirectIntegrationTest.php
Test integration of Textimage with the Redirect module.

File

tests/src/Functional/TextimageTestBase.php, line 127

Class

TextimageTestBase
Base test class for Textimage tests.

Namespace

Drupal\Tests\textimage\Functional

Code

protected function createTextimageNode($field_type, $field_name, $field_value, $bundle, $node_title) {
  switch ($field_type) {
    case 'text':
      if (!is_array($field_value)) {
        $field_value = [
          $field_value,
        ];
      }
      $edit = [
        'title[0][value]' => $node_title,
        'body[0][value]' => $field_value[0],
      ];
      for ($i = 0; $i < count($field_value); $i++) {
        $index = $field_name . '[' . $i . '][value]';
        $edit[$index] = $field_value[$i];
      }
      $this
        ->drupalGet('node/add/' . $bundle);
      $this
        ->submitForm($edit, 'Save');
      break;
    case 'image':
      $edit = [
        'title[0][value]' => $node_title,
      ];
      $edit['files[' . $field_name . '_0]'] = $this->fileSystem
        ->realpath($field_value->uri);
      $this
        ->drupalGet('node/add/' . $bundle);
      $this
        ->submitForm($edit, 'Save');

      // Add alt text.
      $this
        ->submitForm([
        $field_name . '[0][alt]' => 'test alt text',
      ], 'Save');
      break;
  }

  // Retrieve ID of the newly created node from the current URL.
  $matches = [];
  preg_match('/node\\/([0-9]+)/', $this
    ->getUrl(), $matches);
  return isset($matches[1]) ? $matches[1] : FALSE;
}