-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from Yoast/132-whip-php-81-improvements
- Loading branch information
Showing
4 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* WHIP libary test file. | ||
* | ||
* @package Yoast\WHIP | ||
*/ | ||
|
||
/** | ||
* Message Dismiss Listener unit tests. | ||
* | ||
* @coversDefaultClass Whip_WPMessageDismissListener | ||
*/ | ||
class WPMessageDismissListener extends Whip_TestCase { | ||
|
||
/** | ||
* Tests the listen method. | ||
* | ||
* @covers ::listen | ||
* | ||
* @dataProvider listenProvider | ||
* | ||
* @param string $action The action to test. | ||
* @param string $nonce The nonce to test. | ||
* @param int $verifyNonceTimes The times to call wp_verify_nonce. | ||
* @param bool $isCorrectNonce Whether the nonce is correct. | ||
* @param bool $dismissTimes The times to call dismiss. | ||
*/ | ||
public function testDismiss( $action, $nonce, $verifyNonceTimes, $isCorrectNonce, $dismissTimes ) { | ||
$dismisser = $this->getMockBuilder( 'Whip_MessageDismisser' ) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$instance = new Whip_WPMessageDismissListener( $dismisser ); | ||
|
||
$_GET['action'] = $action; | ||
$_GET['nonce'] = $nonce; | ||
|
||
$dismisser->expects( $this->exactly( $verifyNonceTimes ) ) | ||
->method( 'verifyNonce' ) | ||
->with( $nonce, $action ) | ||
->willReturn( $isCorrectNonce ); | ||
|
||
$dismisser->expects( $this->exactly( $dismissTimes ) ) | ||
->method( 'dismiss' ); | ||
|
||
$instance->listen(); | ||
} | ||
|
||
/** | ||
* Data provider for testDismiss. | ||
* | ||
* @return array | ||
*/ | ||
public function listenProvider() { | ||
return array( | ||
'correct action and nonce' => array( | ||
'action' => Whip_WPMessageDismissListener::ACTION_NAME, | ||
'nonce' => 'the_right_nonce', | ||
'verifyNonceTimes' => 1, | ||
'isCorrectNonce' => true, | ||
'dismissTimes' => 1, | ||
), | ||
'incorrect action correct nonce' => array( | ||
'action' => 'wrong_action', | ||
'nonce' => 'the_right_nonce', | ||
'verifyNonceTimes' => 0, | ||
'isCorrectNonce' => false, | ||
'dismissTimes' => 0, | ||
), | ||
'correct action incorrect nonce' => array( | ||
'action' => Whip_WPMessageDismissListener::ACTION_NAME, | ||
'nonce' => 'wrong_nonce', | ||
'verifyNonceTimes' => 1, | ||
'isCorrectNonce' => false, | ||
'dismissTimes' => 0, | ||
), | ||
'incorrect action and nonce' => array( | ||
'action' => 'wrong_action', | ||
'nonce' => 'wrong_nonce', | ||
'verifyNonceTimes' => 0, | ||
'isCorrectNonce' => false, | ||
'dismissTimes' => 0, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters