Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Livewire/Web/Recipes/RecipeIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ protected function getDefaultSort(): string

/**
* Get the current page number for sharing.
* Cast required: getPage() returns string in production (URL params are always strings).
*/
protected function getSharePage(): int
{
return $this->getPage();
return (int) $this->getPage();
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/Feature/FilterShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,50 @@ public function filter_share_page_enum_returns_correct_route_names(): void
$this->assertSame('localized.recipes.random', FilterSharePageEnum::Random->routeName());
$this->assertSame('localized.menus.index', FilterSharePageEnum::Menus->routeName());
}

#[Test]
public function filter_share_includes_page_number_in_url_params(): void
{
$this->get(localized_route('localized.recipes.index', ['page' => 2]))
->assertSeeLivewire(RecipeIndex::class);

Livewire::test(RecipeIndex::class)
->set('filterHasPdf', true)
->call('prepareShareUrl');

$filterShare = FilterShare::latest('created_at')->first();
$this->assertNotNull($filterShare);
}

#[Test]
public function get_share_page_returns_integer(): void
{
$component = Livewire::test(RecipeIndex::class);

$reflection = new \ReflectionClass($component->instance());
$method = $reflection->getMethod('getSharePage');

$result = $method->invoke($component->instance());

$this->assertIsInt($result, 'getSharePage() must return an integer, not a string');
}

#[Test]
public function get_share_page_handles_string_page_parameter(): void
{
$mock = $this->getMockBuilder(RecipeIndex::class)
->onlyMethods(['getPage'])
->getMock();

$mock->method('getPage')
->willReturn('2');

$reflection = new \ReflectionClass($mock);
$method = $reflection->getMethod('getSharePage');

$result = $method->invoke($mock);

$this->assertIsInt($result, 'getSharePage() must cast string to integer');
$this->assertSame(2, $result);
}
}
Loading