8000 [#402] Fixed path trait failing on `<front>`. by AlexSkrypnyk · Pull Request #403 · drevops/behat-steps · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[#402] Fixed path trait failing on <front>. #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
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
2 changes: 2 additions & 0 deletions STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ Assert that the current page is a specified path

```gherkin
Then the path should be "/about-us"
Then the path should be "/"
Then the path should be "<front>"

```
Expand All @@ -1055,6 +1056,7 @@ Assert that the current page is not a specified path

```gherkin
Then the path should not be "/about-us"
Then the path should not be "/"
Then the path should not be "<front>"

```
Expand Down
14 changes: 9 additions & 5 deletions src/PathTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* @code
* Then the path should be "/about-us"
* Then the path should be "/"
* Then the path should be "<front>"
* @endcode
*
Expand All @@ -37,9 +38,10 @@
throw new \Exception('Current path is not a valid URL');
}

$current_path = $current_path === '' ? '<front>' : $current_path;
$normalized_current_path = ($current_path === '' || $current_path === '/') ? '<front>' : $current_path;
$normalized_path = ($path === '/' || $path === '<front>') ? '<front>' : $path;

if (ltrim((string) $current_path, '/') !== ltrim($path, '/')) {
if (ltrim((string) $normalized_current_path, '/') !== ltrim($normalized_path, '/')) {
throw new \Exception(sprintf('Current path is "%s", but expected is "%s"', $current_path, $path));
}
}
Expand All @@ -51,6 +53,7 @@
*
* @code
* Then the path should not be "/about-us"
* Then the path should not be "/"
* Then the path should not be "<front>"
* @endcode
*
Expand All @@ -69,10 +72,11 @@
throw new \Exception('Current path is not a valid URL');
}

$current_path = $current_path === '/' ? '<front>' : $current_path;
$normalized_current_path = ($current_path === '' || $current_path === '/') ? '<front>' : $current_path;
$normalized_path = ($path === '/' || $path === '<front>') ? '<front>' : $path;

if (ltrim((string) $current_path, '/') === ltrim($path, '/')) {
throw new \Exception(sprintf('Current path should not be "%s"', $current_path));
if (ltrim((string) $normalized_current_path, '/') === ltrim($normalized_path, '/')) {
throw new \Exception(sprintf('Current path should not be "%s"', $path));

Check warning on line 79 in src/PathTrait.php

View check run for this annotation

Codecov / codecov/patch

src/PathTrait.php#L79

Added line #L79 was not covered by tests
}

return TRUE;
Expand Down
103 changes: 82 additions & 21 deletions tests/behat/features/path.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ Feature: Check that PathTrait works
So that I can verify proper URL paths in my application

@api
Scenario: User is at the path without prefixed slash.
Scenario Outline: Assert that the path is the same as the given path
Given I am an anonymous user
When I go to "user/login"
Then the path should be "user/login"
When I go to "<src>"
Then the path should be "<dst>"
Examples:
| src | dst |
| / | / |
| / | <front> |
| <front> | / |
| <front> | <front> |
| /user/login | /user/login |
| user/login | user/login |

@api
Scenario: User is at the path with prefixed slash
Scenario Outline: Assert that the path is not the same as the given path
Given I am an anonymous user
When I go to "/user/login"
Then the path should be "/user/login"

@api
Scenario: User is at the '<front>' path.
Given I am an anonymous user
When I go to "/"
Then the path should be "/"

@api
Scenario: Current page is not specified path.
Given I am an anonymous user
When I go to "/user/login"
Then the path should be "/user/login"

When I go to "/"
Then the path should not be "/user/login"
When I go to "<src>"
Then the path should not be "<dst>"
Examples:
| src | dst |
| / | /user |
| /user | / |
| user | / |
| <front> | /user |
| /user | <front> |
| user | <front> |

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should be :path" fails
Expand All @@ -45,6 +46,36 @@ Feature: Check that PathTrait works
Current path is "/user/login", but expected is "/nonexisting"
"""

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should be :path" fails for "<front>"
Given some behat configuration
And scenario steps:
"""
Given I am an anonymous user
When I go to "/user/login"
Then the path should be "<front>"
"""
When I run "behat --no-colors"
Then it should fail with an error:
"""
Current path is "/user/login", but expected is "<front>"
"""

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should be :path" fails for "/"
Given some behat configuration
And scenario steps:
"""
Given I am an anonymous user
When I go to "/user/login"
Then the path should be "/"
"""
When I run "behat --no-colors"
Then it should fail with an error:
"""
Current path is "/user/login", but expected is "/"
"""

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should not be :path" fails
Given some behat configuration
Expand All @@ -60,6 +91,36 @@ Feature: Check that PathTrait works
Current path should not be "/user/login"
"""

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should not be :path" fails for "/"
Given some behat configuration
And scenario steps:
"""
Given I am an anonymous user
When I go to "/"
Then the path should not be "/"
"""
When I run "behat --no-colors"
Then it should fail with an error:
"""
Current path should not be "/"
"""

@trait:PathTrait
Scenario: Assert that negative assertion for "Then the path should not be :path" fails for "<front>"
Given some behat configuration
And scenario steps:
"""
Given I am an anonymous user
When I go to "/"
Then the path should not be "<front>"
"""
When I run "behat --no-colors"
Then it should fail with an error:
"""
Current path should not be "<front>"
"""

@api
Scenario: Assert "When the basic authentication with the username :username and the password :password"
Given users:
Expand Down
0