class UpdateFetcherTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest
Tests update functionality unrelated to the database.
@group update
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\update\Unit\UpdateFetcherTest
Expanded class hierarchy of UpdateFetcherTest
File
- core/
modules/ update/ tests/ src/ Unit/ UpdateFetcherTest.php, line 22 - Contains \Drupal\Tests\update\Unit\UpdateFetcherTest.
Namespace
Drupal\Tests\update\UnitView source
class UpdateFetcherTest extends UnitTestCase {
/**
* The update fetcher to use.
*
* @var \Drupal\update\UpdateFetcher
*/
protected $updateFetcher;
/**
* {@inheritdoc}
*/
protected function setUp() {
$config_factory = $this
->getConfigFactoryStub(array(
'update.settings' => array(
'fetch_url' => 'http://www.example.com',
),
));
$http_client_mock = $this
->getMock('\\GuzzleHttp\\ClientInterface');
$this->updateFetcher = new UpdateFetcher($config_factory, $http_client_mock);
}
/**
* Tests that buildFetchUrl() builds the URL correctly.
*
* @param array $project
* A keyed array of project information matching results from
* \Drupal\Update\UpdateManager::getProjects().
* @param string $site_key
* A string to mimic an anonymous site key hash.
* @param string $expected
* The expected url returned from UpdateFetcher::buildFetchUrl()
*
* @dataProvider providerTestUpdateBuildFetchUrl
*
* @see \Drupal\update\UpdateFetcher::buildFetchUrl()
*/
public function testUpdateBuildFetchUrl(array $project, $site_key, $expected) {
$url = $this->updateFetcher
->buildFetchUrl($project, $site_key);
$this
->assertEquals($url, $expected);
}
/**
* Provide test data for self::testUpdateBuildFetchUrl().
*
* @return 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().
*/
public function providerTestUpdateBuildFetchUrl() {
$data = array();
// 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'] = array(
'module1' => 'Module 1',
'module2' => 'Module 2',
);
$site_key = '';
$expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
$data[] = array(
$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'] . '/' . DRUPAL_CORE_COMPATIBILITY;
$data[] = array(
$project,
$site_key,
$expected,
);
// For enabled projects, test adding the site key.
$project['project_type'] = '';
$expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
$expected .= '?site_key=site_key';
$expected .= '&list=' . rawurlencode('module1,module2');
$data[] = array(
$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'] . '/' . DRUPAL_CORE_COMPATIBILITY;
$expected .= '&site_key=site_key';
$expected .= '&list=' . rawurlencode('module1,module2');
$data[] = array(
$project,
$site_key,
$expected,
);
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UpdateFetcherTest:: |
protected | property | The update fetcher to use. | |
UpdateFetcherTest:: |
public | function | Provide test data for self::testUpdateBuildFetchUrl(). | |
UpdateFetcherTest:: |
protected | function |
Overrides UnitTestCase:: |
|
UpdateFetcherTest:: |
public | function | Tests that buildFetchUrl() builds the URL correctly. |