function ProjectInfoTest::testNewProject

Tests a project that is not in the codebase.

File

core/modules/package_manager/tests/src/Kernel/ProjectInfoTest.php, line 132

Class

ProjectInfoTest
@coversDefaultClass \Drupal\package_manager\ProjectInfo[[api-linebreak]] @group auto_updates @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testNewProject() : void {
  $fixtures_directory = __DIR__ . '/../../fixtures/release-history/';
  $metadata_fixtures['drupal'] = $fixtures_directory . 'drupal.9.8.2.xml';
  $metadata_fixtures['package_manager_test_update'] = $fixtures_directory . 'package_manager_test_update.7.0.1.xml';
  $this->setReleaseMetadata($metadata_fixtures);
  $available = update_get_available(TRUE);
  $this->assertSame([
    'drupal',
  ], array_keys($available));
  $this->setReleaseMetadata($metadata_fixtures);
  $state = $this->container
    ->get('state');
  // Set the state that the Update Status module uses to store last checked
  // time ensure our calls do not affect it.
  $state->set('update.last_check', 123);
  $project_info = new ProjectInfo('package_manager_test_update');
  $project_data = $project_info->getProjectInfo();
  // Ensure the project information is correct.
  $this->assertSame('Package Manager Test Update', $project_data['title']);
  $all_releases = [
    '7.0.1',
    '7.0.0',
    '7.0.0-alpha1',
    '8.x-6.2',
    '8.x-6.1',
    '8.x-6.0',
    '8.x-6.0-alpha1',
    '7.0.x-dev',
    '8.x-6.x-dev',
    '8.x-5.x',
  ];
  $uninstallable_releases = [
    '7.0.x-dev',
    '8.x-6.x-dev',
    '8.x-5.x',
  ];
  $installable_releases = array_values(array_diff($all_releases, $uninstallable_releases));
  $this->assertSame($all_releases, array_keys($project_data['releases']));
  $this->assertSame($installable_releases, array_keys($project_info->getInstallableReleases()));
  $this->assertNull($project_info->getInstalledVersion());
  // Ensure we have not changed the state the Update Status module uses to
  // store the last checked time.
  $this->assertSame(123, $state->get('update.last_check'));
  $this->assertTrue($this->failureLogger
    ->hasRecordThatContains('Invalid project format: Array', (string) RfcLogLevel::ERROR));
  $this->assertTrue($this->failureLogger
    ->hasRecordThatContains('[name] => Package Manager Test Update 8.x-5.x', (string) RfcLogLevel::ERROR));
  // Prevent the logged errors from causing failures during tear-down.
  $this->failureLogger
    ->reset();
}

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