You are here

class MockDrupalGatherContentClient in GatherContent 8.5

Same name and namespace in other branches
  1. 8.4 tests/modules/gathercontent_test/src/MockDrupalGatherContentClient.php \Drupal\gathercontent_test\MockDrupalGatherContentClient

Class to mock GC client.

Hierarchy

Expanded class hierarchy of MockDrupalGatherContentClient

2 files declare their use of MockDrupalGatherContentClient
GcImportTestBase.php in tests/src/Kernel/GcImportTestBase.php
GcMigrateTestBase.php in tests/src/Kernel/GcMigrateTestBase.php

File

tests/modules/gathercontent_test/src/MockDrupalGatherContentClient.php, line 11

Namespace

Drupal\gathercontent_test
View source
class MockDrupalGatherContentClient extends DrupalGatherContentClient {

  /**
   * Chosen status.
   *
   * @var null|int
   */
  public static $chosenStatus = NULL;

  /**
   * Mock download.
   */
  public function downloadFiles(array $files, $directory, $language) {
    $importedFiles = [];
    foreach ($files as $file) {
      $importedFile = File::create([
        'filename' => $file->fileName,
        'uri' => $file->url,
        'status' => 1,
        'gc_id' => $file->id,
        'langcode' => $language,
        'filesize' => $file->size,
      ]);
      $importedFile
        ->save();
      $importedFiles[] = $importedFile
        ->id();
    }
    return $importedFiles;
  }

  /**
   * Mock files fetch.
   */
  public function itemFilesGet($itemId) {
    return [];
  }

  /**
   * Mock status fetch.
   */
  public function projectStatusGet($projectId, $statusId) {
    $statuses = MockData::getStatuses();
    return $statuses[$statusId];
  }

  /**
   * Mock status change.
   */
  public function itemChooseStatusPost($itemId, $statusId) {
    if (static::$chosenStatus !== NULL) {
      throw new \Exception("itemChooseStatusPost shouldn't be called twice");
    }
    static::$chosenStatus = $statusId;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalGatherContentClient::getAccountId public static function Retrieve the account id of the given account.
DrupalGatherContentClient::getActiveProjects public function Retrieve all the active projects.
DrupalGatherContentClient::getBody public function Returns the response body.
DrupalGatherContentClient::getTemplatesOptionArray public function Returns a formatted array with the template ID's as a key.
DrupalGatherContentClient::projectStatusesGet public function
DrupalGatherContentClient::reKeyArray protected function Create new assoc array with the key parameter as array key.
DrupalGatherContentClient::setCredentials public function Put the authentication config into client.
DrupalGatherContentClient::templateGet public function
DrupalGatherContentClient::__construct public function
MockDrupalGatherContentClient::$chosenStatus public static property Chosen status.
MockDrupalGatherContentClient::downloadFiles public function Mock download. Overrides DrupalGatherContentClient::downloadFiles
MockDrupalGatherContentClient::itemChooseStatusPost public function Mock status change.
MockDrupalGatherContentClient::itemFilesGet public function Mock files fetch.
MockDrupalGatherContentClient::projectStatusGet public function Mock status fetch.