factory.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  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->assertEquals( '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->assertEquals( $id, $term->term_id );
  25. }
  26. }