iterator.php 938 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Test the Iterator implementation of WP_Hook
  4. *
  5. * @group hooks
  6. * @covers WP_Hook::add_filter
  7. */
  8. class Tests_Hooks_Iterator extends WP_UnitTestCase {
  9. public function test_foreach() {
  10. $callback_one = '__return_null';
  11. $callback_two = '__return_false';
  12. $hook = new WP_Hook();
  13. $tag = __FUNCTION__;
  14. $priority = rand( 1, 100 );
  15. $accepted_args = rand( 1, 100 );
  16. $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
  17. $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
  18. $functions = array();
  19. $priorities = array();
  20. foreach ( $hook as $key => $callbacks ) {
  21. $priorities[] = $key;
  22. foreach ( $callbacks as $function_index => $the_ ) {
  23. $functions[] = $the_['function'];
  24. }
  25. }
  26. $this->assertSameSets( array( $priority, $priority + 1 ), $priorities );
  27. $this->assertSameSets( array( $callback_one, $callback_two ), $functions );
  28. }
  29. }