Make WordPress Core

Changeset 29997


Ignore:
Timestamp:
10/23/2014 01:52:57 PM (12 years ago)
Author:
boonebgorges
Message:

Add unit tests for 'append' argument of wp_set_object_terms().

See #29624.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term.php

    r29945 r29997  
    13051305        }
    13061306
     1307        public function test_wp_set_object_terms_append_true() {
     1308                register_taxonomy( 'wptests_tax', 'post' );
     1309                $p = $this->factory->post->create();
     1310                $t1 = $this->factory->term->create( array(
     1311                        'taxonomy' => 'wptests_tax',
     1312                ) );
     1313                $t2 = $this->factory->term->create( array(
     1314                        'taxonomy' => 'wptests_tax',
     1315                ) );
     1316
     1317                $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
     1318                $this->assertNotEmpty( $added1 );
     1319                $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1320
     1321                $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', true );
     1322                $this->assertNotEmpty( $added2 );
     1323                $this->assertEqualSets( array( $t1, $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1324
     1325                _unregister_taxonomy( 'wptests_tax' );
     1326        }
     1327
     1328        public function test_wp_set_object_terms_append_false() {
     1329                register_taxonomy( 'wptests_tax', 'post' );
     1330                $p = $this->factory->post->create();
     1331                $t1 = $this->factory->term->create( array(
     1332                        'taxonomy' => 'wptests_tax',
     1333                ) );
     1334                $t2 = $this->factory->term->create( array(
     1335                        'taxonomy' => 'wptests_tax',
     1336                ) );
     1337
     1338                $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
     1339                $this->assertNotEmpty( $added1 );
     1340                $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1341
     1342                $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax', false );
     1343                $this->assertNotEmpty( $added2 );
     1344                $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1345
     1346                _unregister_taxonomy( 'wptests_tax' );
     1347        }
     1348
     1349        public function test_wp_set_object_terms_append_default_to_false() {
     1350                register_taxonomy( 'wptests_tax', 'post' );
     1351                $p = $this->factory->post->create();
     1352                $t1 = $this->factory->term->create( array(
     1353                        'taxonomy' => 'wptests_tax',
     1354                ) );
     1355                $t2 = $this->factory->term->create( array(
     1356                        'taxonomy' => 'wptests_tax',
     1357                ) );
     1358
     1359                $added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
     1360                $this->assertNotEmpty( $added1 );
     1361                $this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1362
     1363                $added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax' );
     1364                $this->assertNotEmpty( $added2 );
     1365                $this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );
     1366
     1367                _unregister_taxonomy( 'wptests_tax' );
     1368        }
     1369
    13071370        function test_change_object_terms_by_id() {
    13081371                // set some terms on an object; then change them while leaving one intact
Note: See TracChangeset for help on using the changeset viewer.