Make WordPress Core

Opened 9 years ago

Closed 15 months ago

#36476 closed enhancement (fixed)

Add tests for sign on related functions

Reported by: slimndap's profile slimndap Owned by: jorbin's profile jorbin
Milestone: 6.4 Priority: normal
Severity: normal Version: 2.5
Component: Login and Registration Keywords: good-first-bug needs-unit-tests has-patch
Focuses: administration Cc:

Description

I don't think that the login procedure and the underlying wp_signon() are covered by (php)unit tests.
Since this is something quite trivial, I believe this should be added.

I tried to add it myself, but failed. Keep running into Cannot modify header information - headers already sent errors.

Attachments (2)

36476.1.diff (4.7 KB) - added by johnregan3 2 years ago.
Test for wp_authenticate functions
36476.2.diff (5.1 KB) - added by JordanPak 15 months ago.
Unsets the AUTH_COOKIE and SECURE_AUTH_COOKIE so test_wp_authenticate_cookie_with_invalid_cookie() doesn't cause Tests_Auth::test_wp_signon_does_not_throw_deprecation_notices_with_default_parameters to fail

Download all attachments as: .zip

Change History (7)

#1 @desrosj
2 years ago

  • Keywords good-first-bug needs-unit-tests added
  • Milestone set to Future Release
  • Summary changed from The login form is not covered by a test to Add tests for sign on related functions
  • Version changed from 4.4.2 to 2.5

Hi @slimndap,

Welcome to Trac! My apologies this took so long to receive a response.

It's been a while so I took a look. Seems there is one test for wp_signon() now that was added while solving #38744, but this area could definitely benefit from more unit tests (wp_authenticate_username_password(), wp_authenticate_email_password(), and wp_authenticate_cookie()` also do not have any tests).

@johnregan3
2 years ago

Test for wp_authenticate functions

#2 @johnregan3
2 years ago

  • Keywords has-patch added

Added tests for wp_authenticate_username_password(), wp_authenticate_email_password(), and wp_authenticate_cookie().

@JordanPak
15 months ago

Unsets the AUTH_COOKIE and SECURE_AUTH_COOKIE so test_wp_authenticate_cookie_with_invalid_cookie() doesn't cause Tests_Auth::test_wp_signon_does_not_throw_deprecation_notices_with_default_parameters to fail

#3 @JordanPak
15 months ago

@johnregan3 the new Tests_Auth::test_wp_authenticate_cookie_with_invalid_cookie() appeared to be throwing off the existing Tests_Auth::test_wp_signon_does_not_throw_deprecation_notices_with_default_parameters test because the $_COOKIE values were carrying over. The test was succeeding by itself but failing when run with the other tests in Tests_Auth.

36476.2.diff is addressing the issue in my tests.

#4 @jorbin
15 months ago

  • Milestone changed from Future Release to 6.4
  • Owner set to jorbin
  • Status changed from new to assigned

Reviewing this now, the new tests are looking good. Going to commit it.

#5 @jorbin
15 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56454:

Login and Registration: Improve test coverage for sign on related functions

Adds new tests to ensure that wp_authenticate_email_password, wp_authenticate_username_password, and wp_authenticate_cookie are better tested. This also unsets cookies properly between tests.

Props JordanPak, johnregan3.
Fixes #36476.

Note: See TracTickets for help on using tickets.