-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest-send-lists.php
43 lines (38 loc) · 2.12 KB
/
test-send-lists.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Class Newsletters Test Send_Lists
*
* @package Newspack_Newsletters
*/
use Newspack\Newsletters\Send_List;
use Newspack\Newsletters\Send_Lists;
/**
* Tests the Send_List class
*/
class Send_Lists_Test extends WP_UnitTestCase {
use Send_Lists_Setup;
/**
* Test matching by item ID.
*/
public function test_match_by_id() {
$this->assertTrue( Send_Lists::matches_id( '123', '123' ) ); // Single ID matches.
$this->assertTrue( Send_Lists::matches_id( [ '123', '456' ], '123' ) ); // Array of IDs matches.
$this->assertTrue( Send_Lists::matches_id( 123, '123' ) ); // Type-insensitive single ID matches.
$this->assertTrue( Send_Lists::matches_id( [ 123, 456 ], '123' ) ); // Type-insensitive array of ID matches.
$this->assertFalse( Send_Lists::matches_id( '456', '123' ) ); // Single of ID doesn't match.
$this->assertFalse( Send_Lists::matches_id( [ '456', '789' ], '123' ) ); // Array of IDs doesn't match.
}
/**
* Test matching by search term(s).
*/
public function test_match_by_search() {
$this->assertTrue( Send_Lists::matches_search( null, [ 'search term', 'another term' ] ) ); // Null term (default value meaning no filtering) matches.
$this->assertTrue( Send_Lists::matches_search( 'search', [ 'search term', 'another term' ] ) ); // Single term matches.
$this->assertTrue( Send_Lists::matches_search( [ 'search', 'no match' ], [ 'search term', 'another term' ] ) ); // Single term matches.
$this->assertTrue( Send_Lists::matches_search( 123, [ '123 term', 'another term' ] ) ); // Terms are cast as strings when comparing.
$this->assertFalse( Send_Lists::matches_search( 'no match', [ 'search term', 'another term' ] ) ); // Single of ID doesn't match.
$this->assertFalse( Send_Lists::matches_search( [ 'no match', 'another no match' ], [ 'search term', 'another term' ] ) ); // Array of IDs doesn't match.
$this->assertFalse( Send_Lists::matches_search( [ false, 0, '' ], [ 'search term', 'another term' ] ) ); // Non-null falsy values don't match.
$this->assertFalse( Send_Lists::matches_search( [ [ 'invalid_type' ] ], [ 'search term', 'another term' ] ) ); // Array values don't match.
}
}