Snapshot of main at 9f39a6e1e (2026-11-02)
This commit is contained in:
commit
6ccf1792d7
2580 files changed
+1040202
No files matched your search
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Livewire\AcceptPrinciples;
|
||||
use App\Http\Middleware\EnsurePrinciplesAccepted;
|
||||
use App\Models\Category;
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* A member who must (re)accept the principles first is sent on to the page they were going
|
||||
* to after accepting, e.g. a poll opened from a mailing on their first login.
|
||||
*/
|
||||
class PrinciplesIntendedUrlTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// phpunit.xml configures Redis, which is the dev site's cache too
|
||||
config(['cache.default' => 'array', 'scout.driver' => null]);
|
||||
|
||||
$category = Category::firstOrCreate(['type' => 'SiteContents\Static\Principles']);
|
||||
$post = Post::withoutSyncingToSearch(fn () => Post::create(['postable_id' => 1, 'postable_type' => \App\Models\Admin::class, 'category_id' => $category->id]));
|
||||
DB::table('post_translations')->insert([
|
||||
'post_id' => $post->id, 'locale' => 'en', 'slug' => 'principles-intended-test-' . $post->id, 'title' => 'Principles',
|
||||
'status' => 1, 'from' => now()->subDay(), 'created_at' => now(), 'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_the_requested_page_is_remembered_before_the_principles(): void
|
||||
{
|
||||
$user = User::factory()->create(['principles_terms_accepted' => null]);
|
||||
$this->actingAs($user, 'web');
|
||||
$request = Request::create(url('/en/poll/some-poll?switch=1'));
|
||||
$request->setLaravelSession($this->app['session.store']);
|
||||
|
||||
$response = (new EnsurePrinciplesAccepted())->handle($request, fn () => response('passed'));
|
||||
|
||||
$this->assertTrue($response->isRedirect());
|
||||
$this->assertStringContainsString('principles', $response->headers->get('Location'));
|
||||
$this->assertSame(url('/en/poll/some-poll?switch=1'), session('principles_intended_url'));
|
||||
}
|
||||
|
||||
public function test_livewire_requests_are_not_remembered(): void
|
||||
{
|
||||
$user = User::factory()->create(['principles_terms_accepted' => null]);
|
||||
$this->actingAs($user, 'web');
|
||||
$request = Request::create(url('/livewire/update'), 'POST');
|
||||
$request->headers->set('X-Livewire', 'true');
|
||||
$request->setLaravelSession($this->app['session.store']);
|
||||
|
||||
(new EnsurePrinciplesAccepted())->handle($request, fn () => response('passed'));
|
||||
|
||||
$this->assertNull(session('principles_intended_url'));
|
||||
}
|
||||
|
||||
public function test_accepting_continues_to_the_remembered_page(): void
|
||||
{
|
||||
$user = User::factory()->create(['principles_terms_accepted' => null]);
|
||||
$this->actingAs($user, 'web');
|
||||
session(['principles_intended_url' => url('/en/poll/some-poll?switch=1')]);
|
||||
|
||||
Livewire::test(AcceptPrinciples::class)
|
||||
->set('agreed', true)
|
||||
->call('accept')
|
||||
->assertRedirect(url('/en/poll/some-poll?switch=1'));
|
||||
|
||||
$this->assertNotNull($user->fresh()->principles_terms_accepted);
|
||||
$this->assertNull(session('principles_intended_url'));
|
||||
}
|
||||
|
||||
public function test_accepting_without_a_remembered_page_stays(): void
|
||||
{
|
||||
$user = User::factory()->create(['principles_terms_accepted' => null]);
|
||||
$this->actingAs($user, 'web');
|
||||
|
||||
Livewire::test(AcceptPrinciples::class)
|
||||
->set('agreed', true)
|
||||
->call('accept')
|
||||
->assertNoRedirect();
|
||||
|
||||
$this->assertNotNull($user->fresh()->principles_terms_accepted);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user