У меня есть страница контактов, где в раскрывающемся списке select
указана необходимая помощь Раскрывающийся список заполняется правильно, если я перехожу на эту страницу через свой браузер (любой браузер: Firefox, Chrome, Edge ...), но при попытке просмотра страницы с помощью Laravel Dusk для целей тестирования раскрывающийся список пуст.
Это тестовый класс
class ContactTest extends DuskTestCase
{
use DatabaseMigrations, DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->artisan('db:seed');
}
/**
* @test
* @throws Throwable
*/
public function send_a_contact_message()
{
// check if the types' table is populated
// this test passes, then the table is populated
$this->assertDatabaseHas( 'contact_types', [
'name' => 'info'
] );
// fill and submit the form
$this->browse(function (Browser $browser) {
$browser->visit('/contact')
->select('type', 'info')
->type('#c_email', 'alhazred@local.test')
->type('object', 'Contact test')
->type('message', 'Contact test text message')
->click('#confirm_btn');
});
// check if an entry has been stored into the database
// this test fails saying that the table is empty
$this->assertDatabaseHas( 'contact_messages', [
'type' => 'info',
'email' => 'alhazred@local.test',
'object' => 'Contact test',
'message' => 'Contact test text message'
] );
}
}
Это create()
функция внутри ContactMessagesController
public function create()
{
$msg_types = ContactType::all()->sortBy('id');
$types = [];
foreach ($msg_types as $msg_type)
{
$types[$msg_type->name] = trans('contact.type_'.$msg_type->name);
}
return view('contact_us', compact('types'));
}
Так я создаю раскрывающийся список внутри вида
<select name="type" id="type" class="custom-select">
@foreach($types as $id => $text)
<option value="{{ $id }}">{{ $text }}</option>
@endforeach
</select>
Я уверен, что проблема в том, что раскрывающийся список не заполнен, потому что я поместил строку dd($types);
внутри функции create()
непосредственно перед return
, а на снимке экрана, сделанном Сумерками в случае неудачи, показан пустой массив, при просмотре вручную отображается заполненный массив.
Также это утверждение не выполняется
$browser->visit('/contact')
->assertSee('General Information');
где General Information
- текст, который должен отображаться для типа info
, который подтверждает, что раскрывающийся список не заполнен.
В чем может быть причина, по которой раскрывающийся список заполняется при достижении страницы обычным браузером, но без использования Dusk?
Laravel 5.8 - Сумерки 5 - PHP 7.2.14