-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add WooCommerce password change action. #585
Conversation
tests/testProfileChangePassword.php
Outdated
|
||
// Call should fail because of a missing password. | ||
// Test core WP password field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like part of another test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First part is just setup to show that it's succeeding. Then we remove pieces and show that it's failing. Each failure case kicks back false
regardless of how it fails so this is the best way to make sure that what we're actually doing is causing the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First part is just setup to show that it's succeeding
This does sound like overkill. No need to add a success scenario before each failure case. Have a test asserting the success use case, have others asserting the failure cases (without repeating what you're already testing on other tests). If the test says "fails when password property is not provided" just call unset("password_field")
and that will suffice.
@lbalmaceda - Responded and changes made. Thank you! |
Codecov Report
@@ Coverage Diff @@
## master #585 +/- ##
============================================
+ Coverage 28.51% 28.52% +0.01%
- Complexity 1306 1308 +2
============================================
Files 51 51
Lines 4202 4203 +1
============================================
+ Hits 1198 1199 +1
Misses 3004 3004
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with how the tests are written. You're writting 1 test like this:
1. prepare config
2. make method work fine / succeed
3. change something in the config
4. test that method now fails
5. repeat (3) and (5) for each property under test
while it should be
1. prepare successful config
2. test method works fine
1. prepare failure config A
2. test method fails with err a
1. prepare failure config B
2. test method fails with err b
etc.. I'm leaving a general comment because I found many tests like this on this PR. All marked as "belongs to some other test case". Please correct those.
tests/testProfileChangePassword.php
Outdated
|
||
// Call should fail because of a missing password. | ||
// Test core WP password field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First part is just setup to show that it's succeeding
This does sound like overkill. No need to add a success scenario before each failure case. Have a test asserting the success use case, have others asserting the failure cases (without repeating what you're already testing on other tests). If the test says "fails when password property is not provided" just call unset("password_field")
and that will suffice.
tests/testProfileChangePassword.php
Outdated
$this->assertFalse( $change_password->validate_new_password( $errors, false ) ); | ||
|
||
$_POST['pass1'] = uniqid(); | ||
$_POST['password_1'] = uniqid(); | ||
$this->assertTrue( $change_password->validate_new_password( $errors, false ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify if this returns true
when the password was changed or when the password was not changed. I'm confused with this line and the 3 above.
tests/testProfileChangePassword.php
Outdated
/** | ||
* Test that empty user data will skip the password update. | ||
*/ | ||
public function testThatMissingUserDataSkipsUpdate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test is called "test that <condition> skips (the 'password' I suppose) update"
. How do you know when it was or wasn't changed?
$this->storeAuth0Data( $user->ID, 'auth0' ); | ||
|
||
$this->assertTrue( $change_password->validate_new_password( $errors, $user ) ); | ||
$this->assertEquals( $password, $_POST['pass1'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this change in anyway when validate_new_password
is called? If that doesn't happen, what I see is:
var a = 1;
assert(a).equals(1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this change in anyway when validate_new_password is called?
Yes, alters the global var
$this->assertFalse( $change_password->validate_new_password( $errors, false ) ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to do $this->assertEmpty( $errors->get_error_messages() );
here, as done on the test above? applies to other tests as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to make sure in some cases. I added it where I thought it was needed.
$_POST['user_id'] = $user_id; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should you call something more explicit like $this->storeAuth0Data( null );
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
/** | ||
* Test that a user without Auth0 data skips update. | ||
*/ | ||
public function testThatNonAuth0UserSkipsUpdate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sug. rename to testThatMissingAuth0UserDataSkipsUpdate
// Provide everything except a user record. | ||
$change_password = $this->getStub( true ); | ||
$_POST['pass1'] = uniqid(); | ||
$this->storeAuth0Data( $user_id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"missing user record" but here you're passing a user id, from a user that was created right at the beginning of the test. What I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I am missing?
A lot 😆 ... $this->storeAuth0Data()
creates meta data for some user, $_POST['user_id']
is a global POST var that clues the method in that there is a user to change.
Changes
Add Auth0 password change functionality to WooCommerce edit account + tests.
References
Reported on the WP support forums.
Testing
This PR adds unit tests. It can also be tested manually by:
Checklist