<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[37642] branches/4.4/tests/phpunit/tests: Tests: Move `wp_set_object_terms()` tests to their own file.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/37642">37642</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/37642","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-06-06 21:08:23 +0000 (Mon, 06 Jun 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Move `wp_set_object_terms()` tests to their own file.

See <a href="https://core.trac.wordpress.org/ticket/37009">#37009</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches44testsphpunitteststermphp">branches/4.4/tests/phpunit/tests/term.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branches44testsphpunitteststermwpSetObjectTermsphp">branches/4.4/tests/phpunit/tests/term/wpSetObjectTerms.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches44testsphpunitteststermwpSetObjectTermsphpfromrev37641branches44testsphpunitteststermphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: branches/4.4/tests/phpunit/tests/term/wpSetObjectTerms.php (from rev 37641, branches/4.4/tests/phpunit/tests/term.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.4/tests/phpunit/tests/term/wpSetObjectTerms.php                                (rev 0)
+++ branches/4.4/tests/phpunit/tests/term/wpSetObjectTerms.php  2016-06-06 21:08:23 UTC (rev 37642)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,312 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group taxonomy
+ */
+class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase {
+       protected $taxonomy = 'category';
+       protected static $post_ids = array();
+
+       public static function wpSetUpBeforeClass( $factory ) {
+               self::$post_ids = $factory->post->create_many( 5 );
+       }
+
+       public static function wpTearDownAfterClass() {
+               foreach ( self::$post_ids as $post_id ) {
+                       wp_delete_post( $post_id, true );
+               }
+       }
+
+       /**
+        * @ticket 26570
+        */
+       function test_set_object_terms() {
+               $non_hier = rand_str( 10 );
+               $hier     = rand_str( 10 );
+
+               // Register taxonomies
+               register_taxonomy( $non_hier, array() );
+               register_taxonomy( $hier, array( 'hierarchical' => true ) );
+
+               // Create a post.
+               $post_id = self::$post_ids[0];
+
+               /*
+                * Set a single term (non-hierarchical) by ID.
+                */
+               $tag = wp_insert_term( 'Foo', $non_hier );
+               $this->assertFalse( has_term( $tag['term_id'], $non_hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, $tag['term_id'], $non_hier );
+               $this->assertTrue( has_term( $tag['term_id'], $non_hier, $post_id ) );
+
+               /*
+                * Set a single term (non-hierarchical) by slug.
+                */
+               $tag = wp_insert_term( 'Bar', $non_hier );
+               $tag = get_term( $tag['term_id'], $non_hier );
+
+               $this->assertFalse( has_term( $tag->slug, $non_hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, $tag->slug, $non_hier );
+               $this->assertTrue( has_term( $tag->slug, $non_hier, $post_id ) );
+
+               /*
+                * Set a single term (hierarchical) by ID.
+                */
+               $cat = wp_insert_term( 'Baz', $hier );
+               $this->assertFalse( has_term( $cat['term_id'], $hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, $cat['term_id'], $hier );
+               $this->assertTrue( has_term( $cat['term_id'], $hier, $post_id ) );
+
+               /*
+                * Set a single term (hierarchical) by slug.
+                */
+               $cat = wp_insert_term( 'Qux', $hier );
+               $cat = get_term( $cat['term_id'], $hier );
+
+               $this->assertFalse( has_term( $cat->slug, $hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, $cat->slug, $hier );
+               $this->assertTrue( has_term( $cat->slug, $hier, $post_id ) );
+
+               /*
+                * Set an array of term IDs (non-hierarchical) by ID.
+                */
+               $tag1 = wp_insert_term( '_tag1', $non_hier );
+               $this->assertFalse( has_term( $tag1['term_id'], $non_hier, $post_id ) );
+
+               $tag2 = wp_insert_term( '_tag2', $non_hier );
+               $this->assertFalse( has_term( $tag2['term_id'], $non_hier, $post_id ) );
+
+               $tag3 = wp_insert_term( '_tag3', $non_hier );
+               $this->assertFalse( has_term( $tag3['term_id'], $non_hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, array( $tag1['term_id'], $tag2['term_id'], $tag3['term_id'] ), $non_hier );
+               $this->assertTrue( has_term( array( $tag1['term_id'], $tag2['term_id'], $tag3['term_id'] ), $non_hier, $post_id ) );
+
+               /*
+                * Set an array of term slugs (hierarchical) by slug.
+                */
+               $cat1 = wp_insert_term( '_cat1', $hier );
+               $cat1 = get_term( $cat1['term_id'], $hier );
+               $this->assertFalse( has_term( $cat1->slug, $hier, $post_id ) );
+
+               $cat2 = wp_insert_term( '_cat2', $hier );
+               $cat2 = get_term( $cat2['term_id'], $hier );
+               $this->assertFalse( has_term( $cat2->slug, $hier, $post_id ) );
+
+               $cat3 = wp_insert_term( '_cat3', $hier );
+               $cat3 = get_term( $cat3['term_id'], $hier );
+               $this->assertFalse( has_term( $cat3->slug, $hier, $post_id ) );
+
+               wp_set_object_terms( $post_id, array( $cat1->slug, $cat2->slug, $cat3->slug ), $hier );
+               $this->assertTrue( has_term( array( $cat1->slug, $cat2->slug, $cat3->slug ), $hier, $post_id ) );
+       }
+
+       function test_set_object_terms_by_id() {
+               $ids = self::$post_ids;
+
+               $terms = array();
+               for ($i=0; $i<3; $i++ ) {
+                       $term = rand_str();
+                       $result = wp_insert_term( $term, $this->taxonomy );
+                       $this->assertInternalType( 'array', $result );
+                       $term_id[$term] = $result['term_id'];
+               }
+
+               foreach ($ids as $id) {
+                       $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy );
+                       // should return three term taxonomy ids
+                       $this->assertEquals( 3, count($tt) );
+               }
+
+               // each term should be associated with every post
+               foreach ($term_id as $term=>$id) {
+                       $actual = get_objects_in_term($id, $this->taxonomy);
+                       $this->assertEquals( $ids, array_map('intval', $actual) );
+               }
+
+               // each term should have a count of 5
+               foreach (array_keys($term_id) as $term) {
+                       $t = get_term_by('name', $term, $this->taxonomy);
+                       $this->assertEquals( 5, $t->count );
+               }
+       }
+
+       function test_set_object_terms_by_name() {
+               $ids = self::$post_ids;
+
+               $terms = array(
+                       rand_str(),
+                       rand_str(),
+                       rand_str()
+               );
+
+               foreach ($ids as $id) {
+                       $tt = wp_set_object_terms( $id, $terms, $this->taxonomy );
+                       // should return three term taxonomy ids
+                       $this->assertEquals( 3, count($tt) );
+                       // remember which term has which term_id
+                       for ($i=0; $i<3; $i++) {
+                               $term = get_term_by('name', $terms[$i], $this->taxonomy);
+                               $term_id[$terms[$i]] = intval($term->term_id);
+                       }
+               }
+
+               // each term should be associated with every post
+               foreach ($term_id as $term=>$id) {
+                       $actual = get_objects_in_term($id, $this->taxonomy);
+                       $this->assertEquals( $ids, array_map('intval', $actual) );
+               }
+
+               // each term should have a count of 5
+               foreach ($terms as $term) {
+                       $t = get_term_by('name', $term, $this->taxonomy);
+                       $this->assertEquals( 5, $t->count );
+               }
+       }
+
+       function test_set_object_terms_invalid() {
+               // bogus taxonomy
+               $result = wp_set_object_terms( self::$post_ids[0], array(rand_str()), rand_str() );
+               $this->assertTrue( is_wp_error($result) );
+       }
+
+       public function test_wp_set_object_terms_append_true() {
+               register_taxonomy( 'wptests_tax', 'post' );
+               $p = self::$post_ids[0];
+               $t1 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+               $t2 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+
+               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
+               $this->assertNotEmpty( $added1 );
+               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', true );
+               $this->assertNotEmpty( $added2 );
+               $this->assertEqualSets( array( $t1, $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               _unregister_taxonomy( 'wptests_tax' );
+       }
+
+       public function test_wp_set_object_terms_append_false() {
+               register_taxonomy( 'wptests_tax', 'post' );
+               $p = self::$post_ids[0];
+               $t1 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+               $t2 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+
+               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
+               $this->assertNotEmpty( $added1 );
+               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', false );
+               $this->assertNotEmpty( $added2 );
+               $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               _unregister_taxonomy( 'wptests_tax' );
+       }
+
+       public function test_wp_set_object_terms_append_default_to_false() {
+               register_taxonomy( 'wptests_tax', 'post' );
+               $p = self::$post_ids[0];
+               $t1 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+               $t2 = self::factory()->term->create( array(
+                       'taxonomy' => 'wptests_tax',
+               ) );
+
+               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
+               $this->assertNotEmpty( $added1 );
+               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax' );
+               $this->assertNotEmpty( $added2 );
+               $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
+
+               _unregister_taxonomy( 'wptests_tax' );
+       }
+
+       function test_change_object_terms_by_id() {
+               // set some terms on an object; then change them while leaving one intact
+
+               $post_id = self::$post_ids[0];
+
+               // first set: 3 terms
+               $terms_1 = array();
+               for ($i=0; $i<3; $i++ ) {
+                       $term = rand_str();
+                       $result = wp_insert_term( $term, $this->taxonomy );
+                       $this->assertInternalType( 'array', $result );
+                       $terms_1[$i] = $result['term_id'];
+               }
+
+               // second set: one of the original terms, plus one new term
+               $terms_2 = array();
+               $terms_2[0] = $terms_1[1];
+
+               $term = rand_str();
+               $result = wp_insert_term( $term, $this->taxonomy );
+               $terms_2[1] = $result['term_id'];
+
+
+               // set the initial terms
+               $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
+               $this->assertEquals( 3, count($tt_1) );
+
+               // make sure they're correct
+               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
+               $this->assertEquals( $terms_1, $terms );
+
+               // change the terms
+               $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
+               $this->assertEquals( 2, count($tt_2) );
+
+               // make sure they're correct
+               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
+               $this->assertEquals( $terms_2, $terms );
+
+               // make sure the tt id for 'bar' matches
+               $this->assertEquals( $tt_1[1], $tt_2[0] );
+
+       }
+
+       function test_change_object_terms_by_name() {
+               // set some terms on an object; then change them while leaving one intact
+
+               $post_id = self::$post_ids[0];
+
+               $terms_1 = array('foo', 'bar', 'baz');
+               $terms_2 = array('bar', 'bing');
+
+               // set the initial terms
+               $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
+               $this->assertEquals( 3, count($tt_1) );
+
+               // make sure they're correct
+               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
+               $this->assertEquals( $terms_1, $terms );
+
+               // change the terms
+               $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
+               $this->assertEquals( 2, count($tt_2) );
+
+               // make sure they're correct
+               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
+               $this->assertEquals( $terms_2, $terms );
+
+               // make sure the tt id for 'bar' matches
+               $this->assertEquals( $tt_1[1], $tt_2[0] );
+
+       }
+}
</ins></span></pre></div>
<a id="branches44testsphpunitteststermphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.4/tests/phpunit/tests/term.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.4/tests/phpunit/tests/term.php 2016-06-06 21:03:34 UTC (rev 37641)
+++ branches/4.4/tests/phpunit/tests/term.php   2016-06-06 21:08:23 UTC (rev 37642)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,299 +69,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @ticket 26570
-        */
-       function test_set_object_terms() {
-               $non_hier = rand_str( 10 );
-               $hier     = rand_str( 10 );
-
-               // Register taxonomies
-               register_taxonomy( $non_hier, array() );
-               register_taxonomy( $hier, array( 'hierarchical' => true ) );
-
-               // Create a post.
-               $post_id = self::$post_ids[0];
-
-               /*
-                * Set a single term (non-hierarchical) by ID.
-                */
-               $tag = wp_insert_term( 'Foo', $non_hier );
-               $this->assertFalse( has_term( $tag['term_id'], $non_hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, $tag['term_id'], $non_hier );
-               $this->assertTrue( has_term( $tag['term_id'], $non_hier, $post_id ) );
-
-               /*
-                * Set a single term (non-hierarchical) by slug.
-                */
-               $tag = wp_insert_term( 'Bar', $non_hier );
-               $tag = get_term( $tag['term_id'], $non_hier );
-
-               $this->assertFalse( has_term( $tag->slug, $non_hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, $tag->slug, $non_hier );
-               $this->assertTrue( has_term( $tag->slug, $non_hier, $post_id ) );
-
-               /*
-                * Set a single term (hierarchical) by ID.
-                */
-               $cat = wp_insert_term( 'Baz', $hier );
-               $this->assertFalse( has_term( $cat['term_id'], $hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, $cat['term_id'], $hier );
-               $this->assertTrue( has_term( $cat['term_id'], $hier, $post_id ) );
-
-               /*
-                * Set a single term (hierarchical) by slug.
-                */
-               $cat = wp_insert_term( 'Qux', $hier );
-               $cat = get_term( $cat['term_id'], $hier );
-
-               $this->assertFalse( has_term( $cat->slug, $hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, $cat->slug, $hier );
-               $this->assertTrue( has_term( $cat->slug, $hier, $post_id ) );
-
-               /*
-                * Set an array of term IDs (non-hierarchical) by ID.
-                */
-               $tag1 = wp_insert_term( '_tag1', $non_hier );
-               $this->assertFalse( has_term( $tag1['term_id'], $non_hier, $post_id ) );
-
-               $tag2 = wp_insert_term( '_tag2', $non_hier );
-               $this->assertFalse( has_term( $tag2['term_id'], $non_hier, $post_id ) );
-
-               $tag3 = wp_insert_term( '_tag3', $non_hier );
-               $this->assertFalse( has_term( $tag3['term_id'], $non_hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, array( $tag1['term_id'], $tag2['term_id'], $tag3['term_id'] ), $non_hier );
-               $this->assertTrue( has_term( array( $tag1['term_id'], $tag2['term_id'], $tag3['term_id'] ), $non_hier, $post_id ) );
-
-               /*
-                * Set an array of term slugs (hierarchical) by slug.
-                */
-               $cat1 = wp_insert_term( '_cat1', $hier );
-               $cat1 = get_term( $cat1['term_id'], $hier );
-               $this->assertFalse( has_term( $cat1->slug, $hier, $post_id ) );
-
-               $cat2 = wp_insert_term( '_cat2', $hier );
-               $cat2 = get_term( $cat2['term_id'], $hier );
-               $this->assertFalse( has_term( $cat2->slug, $hier, $post_id ) );
-
-               $cat3 = wp_insert_term( '_cat3', $hier );
-               $cat3 = get_term( $cat3['term_id'], $hier );
-               $this->assertFalse( has_term( $cat3->slug, $hier, $post_id ) );
-
-               wp_set_object_terms( $post_id, array( $cat1->slug, $cat2->slug, $cat3->slug ), $hier );
-               $this->assertTrue( has_term( array( $cat1->slug, $cat2->slug, $cat3->slug ), $hier, $post_id ) );
-       }
-
-       function test_set_object_terms_by_id() {
-               $ids = self::$post_ids;
-
-               $terms = array();
-               for ($i=0; $i<3; $i++ ) {
-                       $term = rand_str();
-                       $result = wp_insert_term( $term, $this->taxonomy );
-                       $this->assertInternalType( 'array', $result );
-                       $term_id[$term] = $result['term_id'];
-               }
-
-               foreach ($ids as $id) {
-                       $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy );
-                       // should return three term taxonomy ids
-                       $this->assertEquals( 3, count($tt) );
-               }
-
-               // each term should be associated with every post
-               foreach ($term_id as $term=>$id) {
-                       $actual = get_objects_in_term($id, $this->taxonomy);
-                       $this->assertEquals( $ids, array_map('intval', $actual) );
-               }
-
-               // each term should have a count of 5
-               foreach (array_keys($term_id) as $term) {
-                       $t = get_term_by('name', $term, $this->taxonomy);
-                       $this->assertEquals( 5, $t->count );
-               }
-       }
-
-       function test_set_object_terms_by_name() {
-               $ids = self::$post_ids;
-
-               $terms = array(
-                       rand_str(),
-                       rand_str(),
-                       rand_str()
-               );
-
-               foreach ($ids as $id) {
-                       $tt = wp_set_object_terms( $id, $terms, $this->taxonomy );
-                       // should return three term taxonomy ids
-                       $this->assertEquals( 3, count($tt) );
-                       // remember which term has which term_id
-                       for ($i=0; $i<3; $i++) {
-                               $term = get_term_by('name', $terms[$i], $this->taxonomy);
-                               $term_id[$terms[$i]] = intval($term->term_id);
-                       }
-               }
-
-               // each term should be associated with every post
-               foreach ($term_id as $term=>$id) {
-                       $actual = get_objects_in_term($id, $this->taxonomy);
-                       $this->assertEquals( $ids, array_map('intval', $actual) );
-               }
-
-               // each term should have a count of 5
-               foreach ($terms as $term) {
-                       $t = get_term_by('name', $term, $this->taxonomy);
-                       $this->assertEquals( 5, $t->count );
-               }
-       }
-
-       function test_set_object_terms_invalid() {
-               // bogus taxonomy
-               $result = wp_set_object_terms( self::$post_ids[0], array(rand_str()), rand_str() );
-               $this->assertTrue( is_wp_error($result) );
-       }
-
-       public function test_wp_set_object_terms_append_true() {
-               register_taxonomy( 'wptests_tax', 'post' );
-               $p = self::$post_ids[0];
-               $t1 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-               $t2 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-
-               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
-               $this->assertNotEmpty( $added1 );
-               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', true );
-               $this->assertNotEmpty( $added2 );
-               $this->assertEqualSets( array( $t1, $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               _unregister_taxonomy( 'wptests_tax' );
-       }
-
-       public function test_wp_set_object_terms_append_false() {
-               register_taxonomy( 'wptests_tax', 'post' );
-               $p = self::$post_ids[0];
-               $t1 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-               $t2 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-
-               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
-               $this->assertNotEmpty( $added1 );
-               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', false );
-               $this->assertNotEmpty( $added2 );
-               $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               _unregister_taxonomy( 'wptests_tax' );
-       }
-
-       public function test_wp_set_object_terms_append_default_to_false() {
-               register_taxonomy( 'wptests_tax', 'post' );
-               $p = self::$post_ids[0];
-               $t1 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-               $t2 = self::factory()->term->create( array(
-                       'taxonomy' => 'wptests_tax',
-               ) );
-
-               $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
-               $this->assertNotEmpty( $added1 );
-               $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax' );
-               $this->assertNotEmpty( $added2 );
-               $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
-
-               _unregister_taxonomy( 'wptests_tax' );
-       }
-
-       function test_change_object_terms_by_id() {
-               // set some terms on an object; then change them while leaving one intact
-
-               $post_id = self::$post_ids[0];
-
-               // first set: 3 terms
-               $terms_1 = array();
-               for ($i=0; $i<3; $i++ ) {
-                       $term = rand_str();
-                       $result = wp_insert_term( $term, $this->taxonomy );
-                       $this->assertInternalType( 'array', $result );
-                       $terms_1[$i] = $result['term_id'];
-               }
-
-               // second set: one of the original terms, plus one new term
-               $terms_2 = array();
-               $terms_2[0] = $terms_1[1];
-
-               $term = rand_str();
-               $result = wp_insert_term( $term, $this->taxonomy );
-               $terms_2[1] = $result['term_id'];
-
-
-               // set the initial terms
-               $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
-               $this->assertEquals( 3, count($tt_1) );
-
-               // make sure they're correct
-               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
-               $this->assertEquals( $terms_1, $terms );
-
-               // change the terms
-               $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
-               $this->assertEquals( 2, count($tt_2) );
-
-               // make sure they're correct
-               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
-               $this->assertEquals( $terms_2, $terms );
-
-               // make sure the tt id for 'bar' matches
-               $this->assertEquals( $tt_1[1], $tt_2[0] );
-
-       }
-
-       function test_change_object_terms_by_name() {
-               // set some terms on an object; then change them while leaving one intact
-
-               $post_id = self::$post_ids[0];
-
-               $terms_1 = array('foo', 'bar', 'baz');
-               $terms_2 = array('bar', 'bing');
-
-               // set the initial terms
-               $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
-               $this->assertEquals( 3, count($tt_1) );
-
-               // make sure they're correct
-               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
-               $this->assertEquals( $terms_1, $terms );
-
-               // change the terms
-               $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
-               $this->assertEquals( 2, count($tt_2) );
-
-               // make sure they're correct
-               $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
-               $this->assertEquals( $terms_2, $terms );
-
-               // make sure the tt id for 'bar' matches
-               $this->assertEquals( $tt_1[1], $tt_2[0] );
-
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * @ticket 15475
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_add_remove_object_terms() {
</span></span></pre>
</div>
</div>

</body>
</html>