You are here

public function ExportTest::testPublishingUserProfile in Acquia Content Hub 8.2

Tests publishing of node and user profile.

Throws

\Exception

File

tests/src/Kernel/ExportTest.php, line 482

Class

ExportTest
Tests entity exports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function testPublishingUserProfile() {
  $this->contentHubQueue
    ->purgeQueues();

  // Create "user_picture" image field.
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'user_picture',
    'entity_type' => 'user',
    'type' => 'image',
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_name' => 'user_picture',
    'entity_type' => 'user',
    'bundle' => 'user',
  ]);
  $field
    ->save();
  $this
    ->processQueue(2);

  // Users.
  $cdf_expectations = [];
  [
    $uid,
  ] = $this
    ->createUsers($items_expected, $cdf_expectations);
  $this
    ->processQueue(2);

  // Node types.
  $cdf_expectations = [];
  $this
    ->createNodeTypes($items_expected, $cdf_expectations);
  $this
    ->processQueue(2);

  // Nodes.
  $cdf_expectations = [];
  [
    $nid,
  ] = $this
    ->createNodes($items_expected, $cdf_expectations, [
    $uid,
  ]);
  $this
    ->processQueue(1);

  // Create a dummy profile image file.
  $filename = 'avatar.jpg';
  $uri = 'public://avatar.jpg';
  $filemime = 'image/jpeg';
  $file = File::create();
  $file
    ->setOwnerId($uid);
  $file
    ->setFilename($filename);
  $file
    ->setMimeType($filemime);
  $file
    ->setFileUri($uri);
  $file
    ->set('status', FILE_STATUS_PERMANENT);
  $file
    ->save();
  $fid = $file
    ->id();
  $this->fieldUuids[] = $file
    ->uuid();

  // Update user profile image.
  $user = User::load($uid);
  $user
    ->set('user_picture', $fid);
  $user
    ->save();
  $this
    ->processQueue(2);

  // Update node authored by the user.
  $cdf_expectations = [];
  $this
    ->updateAuthoredNode($nid, $items_expected, $cdf_expectations);
  $this
    ->processQueue($items_expected, $cdf_expectations, [
    $this,
    'validateNodeCdfObject',
  ]);
}