adminbar.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @group admin-bar
  4. * @group toolbar
  5. * @group admin
  6. */
  7. class Tests_AdminBar extends WP_UnitTestCase {
  8. static function setUpBeforeClass() {
  9. WP_UnitTestCase::setUpBeforeClass();
  10. require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
  11. }
  12. function setUp() {
  13. parent::setUp();
  14. $this->current_user = get_current_user_id();
  15. wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) );
  16. }
  17. function tearDown() {
  18. wp_set_current_user( $this->current_user );
  19. parent::tearDown();
  20. }
  21. /**
  22. * @ticket 21117
  23. */
  24. function test_content_post_type() {
  25. register_post_type( 'content', array( 'show_in_admin_bar' => true ) );
  26. $admin_bar = new WP_Admin_Bar;
  27. wp_admin_bar_new_content_menu( $admin_bar );
  28. $nodes = $admin_bar->get_nodes();
  29. $this->assertFalse( $nodes['new-content']->parent );
  30. $this->assertEquals( 'new-content', $nodes['add-new-content']->parent );
  31. _unregister_post_type( 'content' );
  32. }
  33. /**
  34. * @ticket 21117
  35. */
  36. function test_merging_existing_meta_values() {
  37. $admin_bar = new WP_Admin_Bar;
  38. $admin_bar->add_node( array(
  39. 'id' => 'test-node',
  40. 'meta' => array( 'class' => 'test-class' ),
  41. ) );
  42. $node = $admin_bar->get_node( 'test-node' );
  43. $this->assertEquals( array( 'class' => 'test-class' ), $node->meta );
  44. $admin_bar->add_node( array(
  45. 'id' => 'test-node',
  46. 'meta' => array( 'some-meta' => 'value' ),
  47. ) );
  48. $node = $admin_bar->get_node( 'test-node' );
  49. $this->assertEquals( array( 'class' => 'test-class', 'some-meta' => 'value' ), $node->meta );
  50. }
  51. }