Chris@0: getConfigFactoryStub(['update.settings' => ['fetch_url' => 'http://www.example.com']]); Chris@12: $http_client_mock = $this->createMock('\GuzzleHttp\ClientInterface'); Chris@0: $this->updateFetcher = new UpdateFetcher($config_factory, $http_client_mock); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that buildFetchUrl() builds the URL correctly. Chris@0: * Chris@0: * @param array $project Chris@0: * A keyed array of project information matching results from Chris@0: * \Drupal\Update\UpdateManager::getProjects(). Chris@0: * @param string $site_key Chris@0: * A string to mimic an anonymous site key hash. Chris@0: * @param string $expected Chris@0: * The expected url returned from UpdateFetcher::buildFetchUrl() Chris@0: * Chris@0: * @dataProvider providerTestUpdateBuildFetchUrl Chris@0: * Chris@0: * @see \Drupal\update\UpdateFetcher::buildFetchUrl() Chris@0: */ Chris@0: public function testUpdateBuildFetchUrl(array $project, $site_key, $expected) { Chris@0: $url = $this->updateFetcher->buildFetchUrl($project, $site_key); Chris@0: $this->assertEquals($url, $expected); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provide test data for self::testUpdateBuildFetchUrl(). Chris@0: * Chris@0: * @return array Chris@0: * An array of arrays, each containing: Chris@0: * - 'project' - An array matching a project's .info file structure. Chris@0: * - 'site_key' - An arbitrary site key. Chris@0: * - 'expected' - The expected url from UpdateFetcher::buildFetchUrl(). Chris@0: */ Chris@0: public function providerTestUpdateBuildFetchUrl() { Chris@0: $data = []; Chris@0: Chris@0: // First test that we didn't break the trivial case. Chris@0: $project['name'] = 'update_test'; Chris@0: $project['project_type'] = ''; Chris@0: $project['info']['version'] = ''; Chris@0: $project['info']['project status url'] = 'http://www.example.com'; Chris@0: $project['includes'] = ['module1' => 'Module 1', 'module2' => 'Module 2']; Chris@0: $site_key = ''; Chris@0: $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; Chris@0: Chris@0: $data[] = [$project, $site_key, $expected]; Chris@0: Chris@0: // For disabled projects it shouldn't add the site key either. Chris@0: $site_key = 'site_key'; Chris@0: $project['project_type'] = 'disabled'; Chris@0: $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; Chris@0: Chris@0: $data[] = [$project, $site_key, $expected]; Chris@0: Chris@0: // For enabled projects, test adding the site key. Chris@0: $project['project_type'] = ''; Chris@0: $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; Chris@0: $expected .= '?site_key=site_key'; Chris@0: $expected .= '&list=' . rawurlencode('module1,module2'); Chris@0: Chris@0: $data[] = [$project, $site_key, $expected]; Chris@0: Chris@0: // Test when the URL contains a question mark. Chris@0: $project['info']['project status url'] = 'http://www.example.com/?project='; Chris@0: $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; Chris@0: $expected .= '&site_key=site_key'; Chris@0: $expected .= '&list=' . rawurlencode('module1,module2'); Chris@0: Chris@0: $data[] = [$project, $site_key, $expected]; Chris@0: Chris@0: return $data; Chris@0: } Chris@0: Chris@0: }