diff --git b/core/modules/update/tests/Drupal/update/Tests/UpdateCoreTest.php a/core/modules/update/tests/Drupal/update/Tests/UpdateCoreUnitTest.php similarity index 55% rename from core/modules/update/tests/Drupal/update/Tests/UpdateCoreTest.php rename to core/modules/update/tests/Drupal/update/Tests/UpdateCoreUnitTest.php index 445906a..08badcb 100644 --- b/core/modules/update/tests/Drupal/update/Tests/UpdateCoreTest.php +++ a/core/modules/update/tests/Drupal/update/Tests/UpdateCoreUnitTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\update\Tests\UpdateCoreTest. + * Contains \Drupal\update\Tests\UpdateCoreUnitTest. */ namespace Drupal\update\Tests; @@ -13,56 +13,82 @@ /** * Tests update functionality unrelated to the database. */ -class UpdateCoreTest extends UnitTestCase { +class UpdateCoreUnitTest extends UnitTestCase { + + /** + * Mimic this constant from bootstrap.inc. + */ + const DRUPAL_CORE_COMPATIBILITY = '8.x'; + + /** + * The update fetcher to use. + * + * @var \Drupal\update\UpdateFetcher + */ + protected $updateFetcher; public static function getInfo() { return array( - 'name' => 'Unit tests', + 'name' => 'Core update tests', 'description' => 'Test update functionality unrelated to the database.', 'group' => 'Update', ); } + protected function setUp() { + $config_factory = $this->getConfigFactoryStub(array('update.settings' => array('fetch_url' => 'http://www.example.com'))); + $this->updateFetcher = new UpdateFetcher($config_factory); + } + /** * Tests that buildFetchUrl() builds the URL correctly. + * + * @dataProvider testUpdateBuildFetchUrlProvider */ - public function testUpdateBuildFetchUrl() { + public function testUpdateBuildFetchUrl(array $project, $site_key, $expected) { + $url = $this->updateFetcher->buildFetchUrl($project, $site_key); + $this->assertEquals($url, $expected); + } + + public function testUpdateBuildFetchUrlProvider() { + $data = array(); + // First test that we didn't break the trivial case. - $config_factory = $this->getConfigFactoryStub(array('update.settings' => array('fetch_url' => 'http://www.example.com'))); - $update_fetcher = new UpdateFetcher($config_factory); $project['name'] = 'update_test'; $project['project_type'] = ''; $project['info']['version'] = ''; $project['info']['project status url'] = 'http://www.example.com'; $project['includes'] = array('module1' => 'Module 1', 'module2' => 'Module 2'); $site_key = ''; - $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; - $url = $update_fetcher->buildFetchUrl($project, $site_key); - $this->assertEquals($url, $expected, "'$url' when no site_key provided should be '$expected'."); + $expected = 'http://www.example.com/' . $project['name'] . '/' . static::DRUPAL_CORE_COMPATIBILITY; + + $data[] = array($project, $site_key, $expected); - //For disabled projects it shouldn't add the site key either. + // 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'] . '/' . DRUPAL_CORE_COMPATIBILITY; - $url = $update_fetcher->buildFetchUrl($project, $site_key); - $this->assertEquals($url, $expected, "'$url' should be '$expected' for disabled projects."); + $expected = 'http://www.example.com/' . $project['name'] . '/' . static::DRUPAL_CORE_COMPATIBILITY; - //for enabled projects, adding the site key + $data[] = array($project, $site_key, $expected); + + // For enabled projects, adding the site key $project['project_type'] = ''; - $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $expected = 'http://www.example.com/' . $project['name'] . '/' . static::DRUPAL_CORE_COMPATIBILITY; $expected .= '?site_key=site_key'; $expected .= '&list=' . rawurlencode('module1,module2'); - $url = $update_fetcher->buildFetchUrl($project, $site_key); - $this->assertEquals($url, $expected, "When site_key provided, '$url' should be '$expected'."); + + $data[] = array($project, $site_key, $expected); // http://drupal.org/node/1481156 test incorrect logic when URL contains // a question mark. $project['info']['project status url'] = 'http://www.example.com/?project='; - $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . static::DRUPAL_CORE_COMPATIBILITY; $expected .= '&site_key=site_key'; $expected .= '&list=' . rawurlencode('module1,module2'); - $url = $update_fetcher->buildFetchUrl($project, $site_key); - $this->assertEquals($url, $expected, "When ? is present, '$url' should be '$expected'."); + + $data[] = array($project, $site_key, $expected); + + return $data; } }