You are here

public function ProjectReleaseTest::testCreateFromArray in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/update/tests/src/Unit/ProjectReleaseTest.php \Drupal\Tests\update\Unit\ProjectReleaseTest::testCreateFromArray()

Tests creating with valid data.

@covers ::createFromArray @covers ::isInsecure @covers ::isSecurityRelease @covers ::isPublished @covers ::isUnsupported @covers ::isUnsupported

@dataProvider providerCreateFromArray

Parameters

mixed[] $data: The data to test. It will be combined with ::getValidData() results.

mixed[] $expected: The values expected to be returned from the object methods.

File

core/modules/update/tests/src/Unit/ProjectReleaseTest.php, line 32

Class

ProjectReleaseTest
@coversDefaultClass \Drupal\update\ProjectRelease

Namespace

Drupal\Tests\update\Unit

Code

public function testCreateFromArray(array $data, array $expected = []) : void {
  $data += $this
    ->getValidData();
  $expected += $data;

  // If not set provide default values that match ::getValidData().
  $expected += [
    'is_published' => TRUE,
    'is_unsupported' => TRUE,
    'is_security_release' => TRUE,
    'is_insecure' => TRUE,
  ];
  $release = ProjectRelease::createFromArray($data);
  $this
    ->assertInstanceOf(ProjectRelease::class, $release);
  $this
    ->assertSame($expected['version'], $release
    ->getVersion());
  $this
    ->assertSame($expected['date'], $release
    ->getDate());
  $this
    ->assertSame($expected['download_link'], $release
    ->getDownloadUrl());
  $this
    ->assertSame($expected['release_link'], $release
    ->getReleaseUrl());
  $this
    ->assertSame($expected['core_compatibility_message'], $release
    ->getCoreCompatibilityMessage());
  $this
    ->assertSame($expected['core_compatible'], $release
    ->isCoreCompatible());
  $this
    ->assertSame($expected['is_published'], $release
    ->isPublished());
  $this
    ->assertSame($expected['is_unsupported'], $release
    ->isUnsupported());
  $this
    ->assertSame($expected['is_security_release'], $release
    ->isSecurityRelease());
  $this
    ->assertSame($expected['is_insecure'], $release
    ->isInsecure());
}