| 1 |
<?php |
| 2 |
use PHPUnit\Framework\TestCase; |
| 3 |
|
| 4 |
class LoaderTest extends TestCase { |
| 5 |
private function getPrivate( $object, $property ) { |
| 6 |
$ref = new ReflectionClass( $object ); |
| 7 |
$prop = $ref->getProperty( $property ); |
| 8 |
$prop->setAccessible( true ); |
| 9 |
return $prop->getValue( $object ); |
| 10 |
} |
| 11 |
|
| 12 |
public function test_add_action_stores_hook() { |
| 13 |
$loader = new Mlsimport_Loader(); |
| 14 |
$loader->add_action( 'init', new stdClass(), 'method' ); |
| 15 |
$actions = $this->getPrivate( $loader, 'actions' ); |
| 16 |
$this->assertCount( 1, $actions ); |
| 17 |
$this->assertEquals( 'init', $actions[0]['hook'] ); |
| 18 |
} |
| 19 |
|
| 20 |
public function test_run_executes_registered_hooks() { |
| 21 |
global $actions_called, $filters_called; |
| 22 |
$actions_called = []; |
| 23 |
$filters_called = []; |
| 24 |
$loader = new Mlsimport_Loader(); |
| 25 |
$component = new stdClass(); |
| 26 |
$loader->add_action( 'action_hook', $component, 'callback' ); |
| 27 |
$loader->add_filter( 'filter_hook', $component, 'callback2' ); |
| 28 |
$loader->run(); |
| 29 |
$this->assertEquals( 'action_hook', $actions_called[0][0] ); |
| 30 |
$this->assertEquals( 'filter_hook', $filters_called[0][0] ); |
| 31 |
} |
| 32 |
} |
| 33 |
|