function UpdateContribTest::testUpdateContribOrder
Same name in other branches
- 9 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateContribOrder()
- 10 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateContribOrder()
- 11.x core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateContribOrder()
Tests that contrib projects are ordered by project name.
If a project contains multiple modules, we want to make sure that the available updates report is sorted by the parent project names, not by the names of the modules included in each project. In this test case, we have two contrib projects, "BBB Update test" and "CCC Update test". However, we have a module called "aaa_update_test" that's part of the "CCC Update test" project. We need to make sure that we see the "BBB" project before the "CCC" project, even though "CCC" includes a module that's processed first if you sort alphabetically by module name (which is the order we see things inside \Drupal\Core\Extension\ExtensionList::getList() for example).
File
-
core/
modules/ update/ tests/ src/ Functional/ UpdateContribTest.php, line 148
Class
- UpdateContribTest
- Tests how the Update Manager module handles contributed modules and themes in a series of functional tests using mock XML data.
Namespace
Drupal\Tests\update\FunctionalCode
public function testUpdateContribOrder() {
// We want core to be version 8.0.0.
$system_info = [
'#all' => [
'version' => '8.0.0',
],
// All the rest should be visible as contrib modules at version 8.x-1.0.
// aaa_update_test needs to be part of the "CCC Update test" project,
// which would throw off the report if we weren't properly sorting by
// the project names.
'aaa_update_test' => [
'project' => 'ccc_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
],
// This should be its own project, and listed first on the report.
'bbb_update_test' => [
'project' => 'bbb_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
],
// This will contain both aaa_update_test and ccc_update_test, and
// should come after the bbb_update_test project.
'ccc_update_test' => [
'project' => 'ccc_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
],
];
$this->config('update_test.settings')
->set('system_info', $system_info)
->save();
$this->refreshUpdateStatus([
'drupal' => '0.0',
'#all' => '1_0',
]);
$this->standardTests();
// We're expecting the report to say all projects are up to date.
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
// We want to see all 3 module names listed, since they'll show up either
// as project names or as modules under the "Includes" listing.
$this->assertText(t('AAA Update test'));
$this->assertText(t('BBB Update test'));
$this->assertText(t('CCC Update test'));
// We want aaa_update_test included in the ccc_update_test project, not as
// its own project on the report.
$this->assertNoRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString(), 'Link to aaa_update_test project does not appear.');
// The other two should be listed as projects.
$this->assertRaw(Link::fromTextAndUrl(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test'))->toString(), 'Link to bbb_update_test project appears.');
$this->assertRaw(Link::fromTextAndUrl(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test'))->toString(), 'Link to bbb_update_test project appears.');
// We want to make sure we see the BBB project before the CCC project.
// Instead of just searching for 'BBB Update test' or something, we want
// to use the full markup that starts the project entry itself, so that
// we're really testing that the project listings are in the right order.
$bbb_project_link = '<div class="project-update__title"><a href="http://example.com/project/bbb_update_test">BBB Update test</a>';
$ccc_project_link = '<div class="project-update__title"><a href="http://example.com/project/ccc_update_test">CCC Update test</a>';
$this->assertTrue(strpos($this->getSession()
->getPage()
->getContent(), $bbb_project_link) < strpos($this->getSession()
->getPage()
->getContent(), $ccc_project_link), "'BBB Update test' project is listed before the 'CCC Update test' project");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.