| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class TestTheme |
| 4 |
* |
| 5 |
* @package micropackage/requirements |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Micropackage\Requirements\Test\Checker; |
| 9 |
|
| 10 |
use phpmock\Mock; |
| 11 |
use phpmock\MockBuilder; |
| 12 |
use Micropackage\Requirements\Requirements; |
| 13 |
use Micropackage\Requirements\Checker\Theme as TestedChecker; |
| 14 |
|
| 15 |
/** |
| 16 |
* Theme checker test case. |
| 17 |
*/ |
| 18 |
class TestTheme extends \WP_UnitTestCase { |
| 19 |
|
| 20 |
use \phpmock\phpunit\PHPMock; |
| 21 |
|
| 22 |
public function setUp() { |
| 23 |
parent::setUp(); |
| 24 |
$this->checker = new TestedChecker(); |
| 25 |
} |
| 26 |
|
| 27 |
public function tearDown() { |
| 28 |
parent::tearDown(); |
| 29 |
Mock::disableAll(); |
| 30 |
} |
| 31 |
|
| 32 |
public function bad_params() { |
| 33 |
return [ |
| 34 |
[ '5.3' ], |
| 35 |
[ 1 ], |
| 36 |
[ true ], |
| 37 |
[ [ 'slug', 'name' ] ], |
| 38 |
[ [ 'slug' => 'slug', 'name' ] ], |
| 39 |
[ [ 'slug', 'name' => 'name' ] ], |
| 40 |
]; |
| 41 |
} |
| 42 |
|
| 43 |
public function test_get_name_should_return_valid_name() { |
| 44 |
$this->assertSame( 'theme', $this->checker->get_name() ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* @dataProvider bad_params |
| 49 |
* @expectedException Exception |
| 50 |
*/ |
| 51 |
public function test_check_should_throw_exception_if_passed_not_array_with_slug_and_name_keys( $param ) { |
| 52 |
$this->checker->check( $param ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @doesNotPerformAssertions |
| 57 |
*/ |
| 58 |
public function test_check_should_accept_array_with_slug_and_name_requirement() { |
| 59 |
|
| 60 |
$this->checker->check( [ |
| 61 |
'slug' => 'test', |
| 62 |
'name' => 'Test', |
| 63 |
] ); |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
public function test_check_should_pass_if_current_theme_slug_matches_requirement() { |
| 68 |
|
| 69 |
$this->checker->check( [ |
| 70 |
'slug' => 'default', |
| 71 |
'name' => 'Default', |
| 72 |
] ); |
| 73 |
|
| 74 |
$this->assertEmpty( $this->checker->get_errors() ); |
| 75 |
} |
| 76 |
|
| 77 |
public function test_check_should_fail_if_current_theme_slug_doesnt_match_requirement() { |
| 78 |
|
| 79 |
$this->checker->check( [ |
| 80 |
'slug' => 'not-existing', |
| 81 |
'name' => 'Ups', |
| 82 |
] ); |
| 83 |
|
| 84 |
$errors = $this->checker->get_errors(); |
| 85 |
|
| 86 |
$this->assertNotEmpty( $errors ); |
| 87 |
$this->assertCount( 1, $errors ); |
| 88 |
$this->assertContains( 'Ups', $errors[0] ); |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
|