function UpdateContribTest::testUpdateBrokenFetchURL

Same name in other branches
  1. 9 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateBrokenFetchURL()
  2. 8.9.x core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateBrokenFetchURL()
  3. 10 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateBrokenFetchURL()

Makes sure that if we fetch from a broken URL, sane things happen.

File

core/modules/update/tests/src/Functional/UpdateContribTest.php, line 434

Class

UpdateContribTest
Tests how the Update Manager handles contributed modules and themes.

Namespace

Drupal\Tests\update\Functional

Code

public function testUpdateBrokenFetchURL() : void {
    $this->mockInstalledExtensionsInfo([
        'aaa_update_test' => [
            'project' => 'aaa_update_test',
            'version' => '8.x-1.0',
            'hidden' => FALSE,
        ],
        'bbb_update_test' => [
            'project' => 'bbb_update_test',
            'version' => '8.x-1.0',
            'hidden' => FALSE,
        ],
        'ccc_update_test' => [
            'project' => 'ccc_update_test',
            'version' => '8.x-1.0',
            'hidden' => FALSE,
        ],
    ]);
    $this->mockDefaultExtensionsInfo([
        'version' => '8.0.0',
    ]);
    // Ensure that the update information is correct before testing.
    $this->drupalGet('admin/reports/updates');
    $xml_mapping = [
        'drupal' => '8.0.0',
        'aaa_update_test' => '1_0',
        'bbb_update_test' => 'does-not-exist',
        'ccc_update_test' => '1_0',
    ];
    $this->refreshUpdateStatus($xml_mapping);
    $this->assertSession()
        ->pageTextContains('Up to date');
    // We're expecting the report to say most projects are up to date, so we
    // hope that 'Up to date' is not unique.
    $this->assertSession()
        ->pageTextMatchesCount(3, '/Up to date/');
    // It should say we failed to get data, not that we're missing an update.
    $this->assertSession()
        ->pageTextNotContains('Update available');
    // We need to check that this string is found as part of a project row, not
    // just in the "Failed to get available update data" message at the top of
    // the page.
    $this->assertSession()
        ->responseContains('<div class="project-update__status">Failed to get available update data');
    // We should see the output messages from fetching manually.
    $this->assertSession()
        ->pageTextContainsOnce('Checked available update data for 3 projects.');
    $this->assertSession()
        ->pageTextContainsOnce('Failed to get available update data for one project.');
    // The other two should be listed as projects.
    $this->assertSession()
        ->linkExists('AAA Update test');
    $this->assertSession()
        ->linkByHrefExists('http://example.com/project/aaa_update_test');
    $this->assertSession()
        ->linkNotExists('BBB Update test');
    $this->assertSession()
        ->linkByHrefNotExists('http://example.com/project/bbb_update_test');
    $this->assertSession()
        ->linkExists('CCC Update test');
    $this->assertSession()
        ->linkByHrefExists('http://example.com/project/ccc_update_test');
}

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