Index: tests/phpunit/tests/term.php
===================================================================
--- tests/phpunit/tests/term.php	(revision 31373)
+++ tests/phpunit/tests/term.php	(working copy)
@@ -1683,21 +1683,62 @@
 			'taxonomy' => 'wptests_tax',
 			'slug' => 'foo',
 		) );
 
 		wp_update_term( $t3, 'wptests_tax', array(
 			'parent' => $t1,
 		) );
 
 		$t3_term = get_term( $t3, 'wptests_tax' );
 
 		$this->assertSame( 'foo', $t3_term->slug );
 
 		_unregister_taxonomy( 'wptests_tax' );
 	}
 
+	/**
+	 * @ticket 31270
+	 */
+	public function test_31270() {
+		register_taxonomy( 'foo', 'post', array(
+			'hierarchical' => true
+		) );
+
+		$term_slugs = array();
+
+		$t1 = $this->factory->term->create( array(
+			'taxonomy' => 'foo',
+			'name' => 'Foo',
+		) );
+		$term_slugs[ $t1 ] = get_term( $t1, 'foo' )->slug;
+
+		$t2 = $this->factory->term->create( array(
+			'taxonomy' => 'foo',
+			'name' => 'Bar',
+			'slug' => 'foo-bar', // non-conflicting slug
+			'parent' => $t1,
+		) );
+		$term_slugs[ $t2 ] = get_term( $t2, 'foo' )->slug;
+
+		$t3 = $this->factory->term->create( array(
+			'taxonomy' => 'foo',
+			'name' => 'Bar',
+		) );
+		$term_slugs[ $t3 ] = get_term( $t3, 'foo' )->slug;
+
+		_unregister_taxonomy( 'foo' );
+
+		$expected = array(
+			$t1 => 'foo',
+			$t2 => 'foo-bar',
+			$t3 => 'bar',
+		);
+
+		$this->assertEquals( $expected, $term_slugs );
+	}
+
 	/** Helpers **********************************************************/
 
 	public function _pre_insert_term_callback() {
 		return new WP_Error( 'custom_error' );
 	}
 }
