WordPress cookie cutter
February 10, 2015
Another small step toward more precise WordPress cookie handling in CodeCeption tests.
The need
I'd like to be able to set up a common shared fixture in cest
format Codeception tests to avoid code duplication and side effects.
Codeception allows for methods to be run before any other method in the class
/**
* @beforeClass
*/
public static function myRunOnceCommonInit(Tester $I){
...
}
and after any test method in the class did run
/**
* @afterClass
*/
public static function myRunOnceCommonClosing(Tester $I){
...
}
Grabbing and setting up WordPress auth cookies here, or any auth cookie for the matter, would allow test methods to focus on a realistic user interaction without repeating the
$I->loginAs('name', 'password');
step in each test method or before each test method in the _before
method.
One step forward
I've pushed version 1.5.7
of WP Browser to GitHub and have added WordPress specific methods to grab the auth cookies:
$I->grabWordPressTestCookie($pattern = null);
$I->grabWordPressAuthCookie($pattern = null);
$I->grabWordPressLoginCookie($pattern = null);
all of them pretty clear in their scope. While I could work on the concept more and add "sugar" methods I think the methods above in conjunction with the recently added grabCookiesWithPattern
method are a solid base covering all the generic needs I now have.