You are here

public function MinisiteTestBase::createFieldAndNode in Mini site 8

Create Minisite field through UI and upload a fixture archive.

Parameters

string $node_type: Node type (bundle).

string $node_title: Node title to set.

string $description: (optional) Minisite field description to set.

array $edit: (optional) Additional node form elements to set before the node is created.

Return value

string Created field name.

4 calls to MinisiteTestBase::createFieldAndNode()
UploadBrowseAliasPathautoTest::testUploadAndBrowsingAlias in tests/src/Functional/UploadBrowseAliasPathautoTest.php
Tests ZIP file upload and browsing minisite pages with Pathauto alias.
UploadBrowseAliasTest::testUploadAndBrowsingAlias in tests/src/Functional/UploadBrowseAliasTest.php
Tests ZIP file upload and browsing minisite pages with alias.
UploadBrowseTest::testUploadAndBrowsing in tests/src/Functional/UploadBrowseTest.php
Tests ZIP file upload and browsing minisite pages.
UploadBrowseTest::testUploadAndRemoval in tests/src/Functional/UploadBrowseTest.php
Tests ZIP file upload and removal, without removing a node.

File

tests/src/Functional/MinisiteTestBase.php, line 390

Class

MinisiteTestBase
Provides methods specifically for testing Minisite module's field handling.

Namespace

Drupal\Tests\minisite\Functional

Code

public function createFieldAndNode($node_type, $node_title, $description = NULL, array $edit = []) {
  $field_name = 'ms_fn_' . strtolower($this
    ->randomMachineName(4));
  $field_label = 'ms_fl_' . strtolower($this
    ->randomMachineName(4));

  // Create field through UI.
  // Note that config schema is also validated when field is created.
  $storage_edit = [
    'settings[uri_scheme]' => 'public',
  ];
  $this
    ->fieldUIAddNewField("admin/structure/types/manage/{$node_type}", $field_name, $field_label, 'minisite', $storage_edit);

  // Create valid fixture archive.
  // All files must reside in the top-level directory and archive must contain
  // index.html file.
  $test_archive = $this
    ->getTestArchiveValid();

  // Manually clear cache on the tester side.
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();

  // Create node and upload fixture file.
  // Note that in order to reveal field fields available only after file
  // is uploaded, we submitting a form with a file and without a title.
  $edit1 = [
    'files[field_' . $field_name . '_' . 0 . ']' => $test_archive
      ->getFileUri(),
  ];
  $this
    ->drupalPostForm("node/add/{$node_type}", $edit1, $this
    ->t('Save'));
  $edit2 = [
    'title[0][value]' => $node_title,
    'field_' . $field_name . '[' . 0 . '][options][alias_status]' => TRUE,
  ];
  $edit = $edit2 + $edit;
  if (!empty($description)) {
    $edit['field_' . $field_name . '[' . 0 . '][description]'] = $description;
  }
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->t('Save'));
  return $field_name;
}