factory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class TestFactoryFor extends WP_UnitTestCase {
  3. function setUp() {
  4. parent::setUp();
  5. $this->category_factory = new WP_UnitTest_Factory_For_Term( null, 'category' );
  6. }
  7. function test_create_creates_a_category() {
  8. $id = $this->category_factory->create();
  9. $this->assertTrue( (bool) get_term_by( 'id', $id, 'category' ) );
  10. }
  11. function test_get_object_by_id_gets_an_object() {
  12. $id = $this->category_factory->create();
  13. $this->assertTrue( (bool) $this->category_factory->get_object_by_id( $id ) );
  14. }
  15. function test_get_object_by_id_gets_an_object_with_the_same_name() {
  16. $id = $this->category_factory->create( array( 'name' => 'Boo' ) );
  17. $object = $this->category_factory->get_object_by_id( $id );
  18. $this->assertSame( 'Boo', $object->name );
  19. }
  20. function test_the_taxonomy_argument_overrules_the_factory_taxonomy() {
  21. $term_factory = new WP_UnitTest_Factory_For_term( null, 'category' );
  22. $id = $term_factory->create( array( 'taxonomy' => 'post_tag' ) );
  23. $term = get_term( $id, 'post_tag' );
  24. $this->assertSame( $id, $term->term_id );
  25. }
  26. /**
  27. * @ticket 32536
  28. */
  29. public function test_term_factory_create_and_get_should_return_term_object() {
  30. register_taxonomy( 'wptests_tax', 'post' );
  31. $term = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) );
  32. $this->assertInternalType( 'object', $term );
  33. $this->assertNotEmpty( $term->term_id );
  34. }
  35. }