90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\User\IncentiveController;
|
|
use App\Models\Incentive;
|
|
use App\Models\IncentiveParticipant;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('collectGalleryImages returns an array of image paths excluding the hero image', function () {
|
|
$incentive = Incentive::factory()->active()->create([
|
|
'image' => 'nikki-beach.jpg',
|
|
]);
|
|
|
|
$controller = new IncentiveController;
|
|
|
|
$method = new ReflectionMethod($controller, 'collectGalleryImages');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($controller, $incentive);
|
|
|
|
expect($result)->toBeArray();
|
|
expect($result)->not->toContain('img/incentive/nikki-beach.jpg');
|
|
|
|
foreach ($result as $path) {
|
|
expect($path)->toStartWith('img/incentive/');
|
|
}
|
|
});
|
|
|
|
it('collectGalleryImages returns empty array when directory does not exist', function () {
|
|
$incentive = Incentive::factory()->active()->create([
|
|
'image' => 'nonexistent-hero.jpg',
|
|
]);
|
|
|
|
$controller = new IncentiveController;
|
|
|
|
$method = new ReflectionMethod($controller, 'collectGalleryImages');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($controller, $incentive);
|
|
|
|
expect($result)->toBeArray();
|
|
});
|
|
|
|
it('collectGalleryImages returns sorted results', function () {
|
|
$incentive = Incentive::factory()->active()->create([
|
|
'image' => 'nikki-beach.jpg',
|
|
]);
|
|
|
|
$controller = new IncentiveController;
|
|
|
|
$method = new ReflectionMethod($controller, 'collectGalleryImages');
|
|
$method->setAccessible(true);
|
|
|
|
$result = $method->invoke($controller, $incentive);
|
|
|
|
$sorted = $result;
|
|
sort($sorted);
|
|
|
|
expect($result)->toBe($sorted);
|
|
});
|
|
|
|
it('teaser view receives galleryImages and participant data', function () {
|
|
$incentive = Incentive::factory()->active()->create();
|
|
|
|
$user = User::forceCreate([
|
|
'email' => 'teaser-' . uniqid('', true) . '@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
'active' => 1,
|
|
]);
|
|
|
|
$participant = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $user->id,
|
|
'accepted_terms_at' => now(),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$controller = new IncentiveController;
|
|
$response = $controller->teaser($incentive->slug);
|
|
|
|
$data = $response->getData();
|
|
expect($data)->toHaveKeys(['incentive', 'participant', 'galleryImages'])
|
|
->and($data['incentive']->id)->toBe($incentive->id)
|
|
->and($data['participant']->id)->toBe($participant->id)
|
|
->and($data['galleryImages'])->toBeArray();
|
|
});
|