I'm using Laravel Dusk to test all links on a page, these links are PDF files that are that are copied from resources/docs to public/docs with laravel mix.
The problem is that trying to access the URL of the docs using get(uri) method gives a 404, here is a simplified version of my Dusk:
protected function refreshApplicationWithLocale($locale)
{
self::tearDown();
putenv(LaravelLocalization::ENV_ROUTE_KEY . '=' . $locale);
self::setUp();
}
protected function setUp(): void
{
parent::setUp();
if(!File::copyDirectory( resource_path('docs'), public_path() . '/docs'))
throw new \Exception("couldn't copy the folder :(");
// Storage::assertExists(public_path() . '/docs/clothing/existing_file.pdf'); // this assertion fails, what's weird is the path in the exception message does actually exist
$this->artisan('storage:link');
}
protected function tearDown(): void
{
parent::tearDown();
foreach (static::$browsers as $browser) {
$browser->driver->manage()->deleteAllCookies();
}
}
public function testClothing()
{
$this->refreshApplicationWithLocale('fr');
$this->get('/test')->assertStatus(200); // passes
$this->get('/fr/vetements')->assertStatus(200); // passes
//usually I'd get the page urls dynamically with Dusk, but for simplicity sake I'm just testing with this link that I know it exists and can curl it from withing Homestead
$this->get('/docs/clothing/Hoodies.pdf')->assertStatus(200); //failes (404)
}
What am I missing ?
Thank you.
P.S.: I'm using laravel 8 and Homestead
EDIT:
After @steven7mwesigwa answer, here is my final code:
protected function refreshApplicationWithLocale($locale)
{
self::tearDown();
putenv(LaravelLocalization::ENV_ROUTE_KEY . '=' . $locale);
self::setUp();
}
protected function setUp(): void
{
parent::setUp();
if(!File::copyDirectory( resource_path('docs'), public_path() . '/docs'))
throw new \Exception("couldn't copy the documents folder :(");
}
protected function tearDown(): void
{
parent::tearDown();
foreach (static::$browsers as $browser) {
$browser->driver->manage()->deleteAllCookies();
}
}
public function testClothing()
{
$this->refreshApplicationWithLocale('fr');
$elements = [];
$this->browse(function (Browser $browser) use(&$elements){
$elements = $browser->visit('myroute')
->elements('.tmp_products_list a', 'href');
});
$this->assertGreaterThan(1, count($elements));
foreach($elements as $element) {
$response = Http::get($element->getAttribute('href'));
self::assertEquals($response->status(), 200);
}
}