@@ -71,9 +71,13 @@ public function test_to_object() {
7171 // Check type is OrderedCollection.
7272 $ this ->assertEquals ( 'OrderedCollection ' , $ object ->get_type () );
7373
74- // Check ID is the term link.
74+ // Check ID uses stable term_id-based URL.
75+ $ expected_id = \add_query_arg ( 'term_id ' , $ term ->term_id , \home_url ( '/ ' ) );
76+ $ this ->assertEquals ( $ expected_id , $ object ->get_id () );
77+
78+ // Check URL is the term link.
7579 $ expected_url = get_term_link ( $ term );
76- $ this ->assertEquals ( $ expected_url , $ object ->get_id () );
80+ $ this ->assertEquals ( $ expected_url , $ object ->get_url () );
7781 }
7882
7983 /**
@@ -86,13 +90,43 @@ public function test_to_id() {
8690 $ transformer = new Term ( $ term );
8791 $ id = $ transformer ->to_id ();
8892
89- // Should return the term link.
93+ // Should return stable term_id-based URL.
94+ $ expected_id = \add_query_arg ( 'term_id ' , $ term ->term_id , \home_url ( '/ ' ) );
95+ $ this ->assertEquals ( $ expected_id , $ id );
96+ }
97+
98+ /**
99+ * Test get_id returns stable ID.
100+ *
101+ * @covers ::get_id
102+ */
103+ public function test_get_id () {
104+ $ term = get_term ( self ::$ term_id );
105+ $ transformer = new Term ( $ term );
106+
107+ $ expected_id = \add_query_arg ( 'term_id ' , $ term ->term_id , \home_url ( '/ ' ) );
108+ $ this ->assertEquals ( $ expected_id , $ transformer ->get_id () );
109+ }
110+
111+ /**
112+ * Test get_url returns term link.
113+ *
114+ * @covers ::get_url
115+ */
116+ public function test_get_url () {
117+ $ term = get_term ( self ::$ term_id );
118+ $ transformer = new Term ( $ term );
119+
90120 $ expected_url = get_term_link ( $ term );
91- $ this ->assertEquals ( $ expected_url , $ id );
121+ $ this ->assertEquals ( $ expected_url , $ transformer -> get_url () );
92122 }
93123
94124 /**
95125 * Test with category taxonomy.
126+ *
127+ * @covers ::to_object
128+ * @covers ::get_id
129+ * @covers ::get_url
96130 */
97131 public function test_category_term () {
98132 $ category = self ::factory ()->term ->create_and_get (
@@ -107,6 +141,12 @@ public function test_category_term() {
107141 $ object = $ transformer ->to_object ();
108142
109143 $ this ->assertEquals ( 'OrderedCollection ' , $ object ->get_type () );
110- $ this ->assertEquals ( get_term_link ( $ category ), $ object ->get_id () );
144+
145+ // ID should use stable term_id-based URL.
146+ $ expected_id = \add_query_arg ( 'term_id ' , $ category ->term_id , \home_url ( '/ ' ) );
147+ $ this ->assertEquals ( $ expected_id , $ object ->get_id () );
148+
149+ // URL should be the term link.
150+ $ this ->assertEquals ( get_term_link ( $ category ), $ object ->get_url () );
111151 }
112152}
0 commit comments