Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
75.00% |
6 / 8 |
CRAP | |
93.33% |
28 / 30 |
| mg_view_function_Test | |
0.00% |
0 / 1 |
|
75.00% |
6 / 8 |
8.02 | |
93.33% |
28 / 30 |
| setUp | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| root_path | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| load_not_existing_file | |
0.00% |
0 / 1 |
1.04 | |
66.67% |
2 / 3 |
|||
| invalid_file_name_must_throw_an_exception | |
0.00% |
0 / 1 |
1.04 | |
66.67% |
2 / 3 |
|||
| load_valid_file_with_standard_slash_notation_in_file_name | |
100.00% |
1 / 1 |
1 | |
100.00% |
7 / 7 |
|||
| load_valid_file_with_dot_notation_in_file_name | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| pass_variables_to_view | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
| tearDown | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| <?php | |
| class mg_view_function_Test extends WP_UnitTestCase { | |
| function setUp() { | |
| parent::setUp(); | |
| add_filter( 'wp-migrator/core/view-dir', [ __CLASS__, 'root_path' ] ); | |
| } | |
| public static function root_path() { | |
| return WPMG_SAMPLE_TEST_DIR . '/views'; | |
| } | |
| /** | |
| * @test | |
| * | |
| * @expectedException BS_Exception | |
| * @expectedExceptionCode file_not_found | |
| */ | |
| public function load_not_existing_file() { | |
| mg_view( 'file.name', [], [ | |
| 'error_type' => BS_Error_handler::THROW_ERROR, | |
| ] ); | |
| } | |
| /** | |
| * @test | |
| * | |
| * @expectedException BS_Exception | |
| * @expectedExceptionCode invalid_file_name | |
| */ | |
| public function invalid_file_name_must_throw_an_exception() { | |
| mg_view( [ 1, 2 ], [], [ | |
| 'error_type' => BS_Error_handler::THROW_ERROR, | |
| ] ); | |
| } | |
| /** | |
| * @test | |
| */ | |
| public function load_valid_file_with_standard_slash_notation_in_file_name() { | |
| $echo = FALSE; | |
| $loaded = mg_view( 'layouts/sample-view-file', [], compact( 'echo' ) ); | |
| $this->assertEquals( 'view', $loaded ); | |
| $root = self::root_path() . '/layouts'; | |
| $loaded = mg_view( 'sample-view-file', [], compact( 'echo', 'root' ) ); | |
| $this->assertEquals( 'view', $loaded ); | |
| } | |
| /** | |
| * @test | |
| */ | |
| public function load_valid_file_with_dot_notation_in_file_name() { | |
| $echo = FALSE; | |
| $loaded = mg_view( 'layouts.sample-view-file', [], compact( 'echo' ) ); | |
| $this->assertEquals( 'view', $loaded ); | |
| } | |
| /** | |
| * @test | |
| */ | |
| public function pass_variables_to_view() { | |
| $echo = FALSE; | |
| $var1 = '-aaa'; | |
| $var2 = '-xyz'; | |
| $loaded = mg_view( 'layouts.sample-view-file', compact( 'var1', 'var2' ), compact( 'echo' ) ); | |
| $this->assertEquals( 'view' . $var1 . $var2, $loaded ); | |
| } | |
| function tearDown() { | |
| parent::tearDown(); | |
| remove_filter( 'wp-migrator/core/view-dir', [ __CLASS__, 'root_path' ] ); | |
| } | |
| } |