有没有办法让 assertPathIs() 忽略 url 的一部分?
Is there a way to have assertPathIs() ignore part of the url?
在制作 Laravel Dusk 测试功能时,我正在尝试检查我的应用程序中的路径。但是,我的应用程序中的 URL 会发生变化,具体取决于用户或他们正在查看的内容(例如 /Test/123/testing
:在这种情况下,123
可以是数字的任意组合。)
是否可以忽略中间部分?
$this->browse(function (Browser $browser) {
$browser->loginAs('email@email.com')
->visit('/test')
->assertPathIs('/test')
->assertSee('LinkText')
->clickLink('LinkText')
->assertPathIs('/test/(CanBeAnything)/testing');
});
看看the code we can see a regular expression match is actually being performed, after the text is run through preg_quote()
:
$pattern = str_replace('\*', '.*', preg_quote($path, '/'));
这意味着您可以使用 *
进行通配符搜索,所以这应该有效:
$this->browse(function (Browser $browser) {
$browser->loginAs('email@email.com')
->visit('/test')
->assertPathIs('/test')
->assertSee('LinkText')
->clickLink('LinkText')
->assertPathIs('/test/*/testing');
});
在制作 Laravel Dusk 测试功能时,我正在尝试检查我的应用程序中的路径。但是,我的应用程序中的 URL 会发生变化,具体取决于用户或他们正在查看的内容(例如 /Test/123/testing
:在这种情况下,123
可以是数字的任意组合。)
是否可以忽略中间部分?
$this->browse(function (Browser $browser) {
$browser->loginAs('email@email.com')
->visit('/test')
->assertPathIs('/test')
->assertSee('LinkText')
->clickLink('LinkText')
->assertPathIs('/test/(CanBeAnything)/testing');
});
看看the code we can see a regular expression match is actually being performed, after the text is run through preg_quote()
:
$pattern = str_replace('\*', '.*', preg_quote($path, '/'));
这意味着您可以使用 *
进行通配符搜索,所以这应该有效:
$this->browse(function (Browser $browser) {
$browser->loginAs('email@email.com')
->visit('/test')
->assertPathIs('/test')
->assertSee('LinkText')
->clickLink('LinkText')
->assertPathIs('/test/*/testing');
});