Skip to content

Commit

Permalink
GH #2526: Fix fail to update to new H5P content type version in CA (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrieinv authored Oct 2, 2023
1 parent 6281b75 commit 1dee085
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sourcecode/apis/contentauthor/app/H5PLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function getUpgrades($toArray = true)
return [
'id' => $id,
'version' => $version,
'name' => $library->getLibraryString(),
'name' => $library->getLibraryString(false),
'machineName' => $library->name,
'majorVersion' => $library->major_version,
'minorVersion' => $library->minor_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace Tests\Integration\Models;

use App\H5PLibrary;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Tests\TestCase;

class H5PLibraryTest extends TestCase
{
use RefreshDatabase;

/**
* @dataProvider provider_getLibraryString
*/
Expand Down Expand Up @@ -97,4 +101,29 @@ public function provider_libraryToString(): \Generator
yield 2 => [['name' => 'H5P.Foobar', 'majorVersion' => 2, 'minorVersion' => 1, 'patchVersion' => 4, 'patchVersionInFolderName' => true], false, 'H5P.Foobar 2.1'];
yield 3 => [['name' => 'H5P.Foobar', 'majorVersion' => 2, 'minorVersion' => 1, 'patchVersion' => 4, 'patchVersionInFolderName' => false], true, 'H5P.Foobar 2.1.4'];
}

public function test_getUpgrades()
{
$originalLib = H5PLibrary::factory()->create();
$noPatchLibrary = H5PLibrary::factory()->create([
'minor_version' => 3,
]);
$withPatchLibrary = H5PLibrary::factory()->create([
'minor_version' => 4,
'patch_version_in_folder_name' => true,
]);

/** @var Collection $availableUpdates */
$availableUpdates = $originalLib->getUpgrades(false);

$this->assertCount(2, $availableUpdates);

$noPatch = $availableUpdates->where('id', $noPatchLibrary->id)->first();
$this->assertSame('H5P.Foobar 1.3', $noPatch['name']);
$this->assertSame('1.3.3', $noPatch['version']);

$withPatch = $availableUpdates->where('id', $withPatchLibrary->id)->first();
$this->assertSame('H5P.Foobar 1.4', $withPatch['name']);
$this->assertSame('1.4.3', $withPatch['version']);
}
}

0 comments on commit 1dee085

Please sign in to comment.