forge/tests/Feature/ModTest.php
Refringe 593b44150c
Resolves Mod Detail Page Version Issue
The latest version on the mod detail page was being selected by created date instead of highest version number. This has been resolved. Also adds a test for this issue.
2024-08-09 12:35:46 -04:00

43 lines
1.1 KiB
PHP

<?php
use App\Models\Mod;
use App\Models\ModVersion;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('shows the latest version on the mod detail page', function () {
// Create a mod instance
$mod = Mod::factory()->create();
// Create 5 mod versions with specified versions
$versions = [
'1.0.0',
'1.1.0',
'1.2.0',
'2.0.0',
'2.1.0',
];
// get the highest version in the array
$latestVersion = max($versions);
foreach ($versions as $version) {
ModVersion::factory()->create([
'mod_id' => $mod->id,
'version' => $version,
]);
}
// Make a request to the mod's detail URL
$response = $this->get($mod->detailUrl());
$this->assertEquals('2.1.0', $latestVersion);
// Assert the latest version is next to the mod's name
$response->assertSeeInOrder(explode(' ', "$mod->name $latestVersion"));
// Assert the latest version is in the latest download button
$response->assertSeeText(__('Download Latest Version')." ($latestVersion)");
});