function UpdateFetcherTest::providerTestUpdateBuildFetchUrl

Same name and namespace in other branches
  1. 9 core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest::providerTestUpdateBuildFetchUrl()
  2. 8.9.x core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest::providerTestUpdateBuildFetchUrl()
  3. 11.x core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest::providerTestUpdateBuildFetchUrl()

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 120

Class

UpdateFetcherTest
Tests update functionality unrelated to the database.

Namespace

Drupal\Tests\update\Unit

Code

public static 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 uninstalled 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 installed 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.