You are here

public function UpdateFetcherTest::providerTestUpdateBuildFetchUrl in Drupal 8

Provide test data for self::testUpdateBuildFetchUrl().

Return value

array An array of arrays, each containing:

  • 'project' - An array matching a project's .info file structure.
  • 'site_key' - An arbitrary site key.
  • 'expected' - The expected url from UpdateFetcher::buildFetchUrl().

File

core/modules/update/tests/src/Unit/UpdateFetcherTest.php, line 60

Class

UpdateFetcherTest
Tests update functionality unrelated to the database.

Namespace

Drupal\Tests\update\Unit

Code

public function providerTestUpdateBuildFetchUrl() {
  $data = [];

  // First test that we didn't break the trivial case.
  $project['name'] = 'update_test';
  $project['project_type'] = '';
  $project['info']['version'] = '';
  $project['info']['project status url'] = 'http://www.example.com';
  $project['includes'] = [
    'module1' => 'Module 1',
    'module2' => 'Module 2',
  ];
  $site_key = '';
  $expected = "http://www.example.com/{$project['name']}/current";
  $data[] = [
    $project,
    $site_key,
    $expected,
  ];

  // For disabled projects it shouldn't add the site key either.
  $site_key = 'site_key';
  $project['project_type'] = 'disabled';
  $expected = "http://www.example.com/{$project['name']}/current";
  $data[] = [
    $project,
    $site_key,
    $expected,
  ];

  // For enabled projects, test adding the site key.
  $project['project_type'] = '';
  $expected = "http://www.example.com/{$project['name']}/current";
  $expected .= '?site_key=site_key';
  $expected .= '&list=' . rawurlencode('module1,module2');
  $data[] = [
    $project,
    $site_key,
    $expected,
  ];

  // Test when the URL contains a question mark.
  $project['info']['project status url'] = 'http://www.example.com/?project=';
  $expected = "http://www.example.com/?project=/{$project['name']}/current";
  $expected .= '&site_key=site_key';
  $expected .= '&list=' . rawurlencode('module1,module2');
  $data[] = [
    $project,
    $site_key,
    $expected,
  ];
  return $data;
}