WordPress.org

Make WordPress Core

Ticket #23378: term.php

File term.php, 2.2 KB (added by joehoyle, 15 months ago)

Added unit tests for wp_(update|insert)_term with parent

Line 
1Index: tests/term.php
2===================================================================
3--- tests/term.php      (revision 1202)
4+++ tests/term.php      (working copy)
5@@ -85,6 +85,63 @@
6                $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
7        }
8 
9+       /**
10+        * Test inserting a new term with a parent
11+        */
12+       function test_insert_term_with_parent_by_id() {
13+               
14+               $term_parent = wp_insert_term( 'My test parent Term', 'category' );
15+
16+               $term_child = wp_insert_term( 'My child term', 'category', array( 'parent' => $term_parent['term_id'] ) );
17+
18+               $term_chid_object = get_term( (int) $term_child['term_id'], 'category' );
19+
20+               wp_delete_term( $term_parent['term_id'], 'category' );
21+               wp_delete_term( $term_child['term_id'], 'category' );
22+
23+               $this->assertEquals( $term_parent['term_id'], $term_chid_object->parent );
24+       }
25+
26+       /**
27+        * @ticket 23378
28+        */
29+       function test_insert_term_with_parent_by_slug() {
30+               
31+               $term_parent = wp_insert_term( 'My test parent Term', 'category' );
32+               $term_parent_object = get_term( (int) $term_parent['term_id'], 'category' );
33+
34+               $term_child = wp_insert_term( 'My child term', 'category', array( 'parent' => $term_parent_object->slug ) );
35+
36+               $term_chid_object = get_term( (int) $term_child['term_id'], 'category' );
37+
38+               wp_delete_term( $term_parent['term_id'], 'category' );
39+               wp_delete_term( $term_child['term_id'], 'category' );
40+
41+               $this->assertEquals( $term_parent['term_id'], $term_chid_object->parent );
42+
43+       }
44+
45+       /**
46+        * @ticket 23378
47+        */
48+       function test_update_term_with_parent_by_slug() {
49+               
50+               $term_parent = wp_insert_term( 'My test parent Term', 'category' );
51+               $term_parent_object = get_term( (int) $term_parent['term_id'], 'category' );
52+
53+               $term_child = wp_insert_term( 'My child term', 'category' );
54+
55+               wp_update_term( (int) $term_child['term_id'], 'category', array( 'parent' => $term_parent_object->slug ) );
56+
57+               $term_chid_object = get_term( (int) $term_child['term_id'], 'category' );
58+
59+               wp_delete_term( $term_parent['term_id'], 'category' );
60+               wp_delete_term( $term_child['term_id'], 'category' );
61+
62+               $this->assertEquals( $term_parent['term_id'], $term_chid_object->parent );
63+
64+       }
65+
66        function test_set_object_terms_by_id() {
67                $ids = $this->factory->post->create_many(5);
68