Index: tests/phpunit/tests/dependencies/jquery.php
===================================================================
--- tests/phpunit/tests/dependencies/jquery.php	(revision 36589)
+++ tests/phpunit/tests/dependencies/jquery.php	(working copy)
@@ -81,4 +81,36 @@
 
 		unset( $GLOBALS['wp_scripts'] );
 	}
+
+	/**
+	 * Test placing of jquery in footer.
+	 * @ticket 25247
+	 */
+	function test_jquery_in_footer() {
+		$scripts = new WP_Scripts;
+		$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ) );
+		$scripts->add( 'jquery-core', '/jquery.js', array() );
+		$scripts->add( 'jquery-migrate', "/jquery-migrate.js", array() );
+
+		$scripts->enqueue( 'jquery' );
+
+		$object = $scripts->query( 'jquery' );
+		$object->add_data( 'group', 1 );
+		foreach( $object->deps as $dep ) {
+			$scripts->add_data( $dep, 'group', 1 );
+		}
+
+		//$this->setOutputCallback( '__return_empty_string' );
+
+		$scripts->do_items( false, 0 );
+		// Could do $this->assertContains( 'jquery', $scripts->done );
+		$this->assertNotContains( 'jquery-core', $scripts->done, 'jquery-core should be in footer but is in head' );
+		$this->assertNotContains( 'jquery-migrate', $scripts->done, 'jquery-migrate should be in footer but is in head' );
+
+		$this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' );
+		$scripts->do_items( false, 1 );
+		$this->assertContains( 'jquery', $scripts->done );
+		$this->assertContains( 'jquery-core', $scripts->done, 'jquery-core in footer' );
+		$this->assertContains( 'jquery-migrate', $scripts->done, 'jquery-migrate in footer' );
+	}
 }
Index: tests/phpunit/tests/dependencies/scripts.php
===================================================================
--- tests/phpunit/tests/dependencies/scripts.php	(revision 36589)
+++ tests/phpunit/tests/dependencies/scripts.php	(working copy)
@@ -157,6 +157,54 @@
 	}
 
 	/**
+	 * Test mismatch of groups in dependencies outputs all scripts in right order.
+	 * @ticket 25247
+	 */
+	public function test_group_mismatch_in_deps() {
+		$scripts = new WP_Scripts;
+		$scripts->add( 'one', 'one', array(), 'v1', 1 ); 
+		$scripts->add( 'two', 'two', array( 'one' ) ); 
+		$scripts->add( 'three', 'three', array( 'two' ), 'v1', 1 ); 
+
+		$scripts->enqueue( array( 'three' ) );
+
+		//$this->setOutputCallback( '__return_empty_string' );
+		$this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' );
+		$scripts->do_items( false, 0 );
+		$this->assertContains( 'one', $scripts->done );
+		$this->assertContains( 'two', $scripts->done );
+		$this->assertNotContains( 'three', $scripts->done );
+
+		$this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){1}/' );
+		$scripts->do_items( false, 1 );
+		$this->assertContains( 'one', $scripts->done );
+		$this->assertContains( 'two', $scripts->done );
+		$this->assertContains( 'three', $scripts->done );
+
+		$scripts = new WP_Scripts;
+		$scripts->add( 'one', 'one', array(), 'v1', 1 ); 
+		$scripts->add( 'two', 'two', array( 'one' ), 'v1', 1 ); 
+		$scripts->add( 'three', 'three', array( 'one' ) ); 
+		$scripts->add( 'four', 'four', array( 'two', 'three' ), 'v1', 1 ); 
+
+		$scripts->enqueue( array( 'four' ) );
+
+		$this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' );
+		$scripts->do_items( false, 0 );
+		$this->assertContains( 'one', $scripts->done );
+		$this->assertNotContains( 'two', $scripts->done );
+		$this->assertContains( 'three', $scripts->done );
+		$this->assertNotContains( 'four', $scripts->done );
+
+		$this->expectOutputRegex( '/^(?:<script[^>]+><\/script>\\n){2}/' );
+		$scripts->do_items( false, 1 );
+		$this->assertContains( 'one', $scripts->done );
+		$this->assertContains( 'two', $scripts->done );
+		$this->assertContains( 'three', $scripts->done );
+		$this->assertContains( 'four', $scripts->done );
+	}
+
+	/**
 	 * Testing 'wp_register_script' return boolean success/failure value.
 	 *
 	 * @ticket 31126
@@ -199,4 +247,25 @@
 		$this->assertContains( home_url( 'bar.js' ), $footer );
 		$this->assertContains( home_url( 'baz.js' ), $footer );
 	}
+
+	/**
+	 * @ticket 35873
+	 */
+	function test_wp_register_script_with_dependencies_in_head_and_footer() {
+		wp_register_script( 'parent', home_url( 'parent.js' ), array( 'child' ), '1', true ); // in footer
+		wp_register_script( 'child', home_url( 'child.js' ), array( 'grandchild' ), '1', false ); // in head
+		wp_register_script( 'grandchild', home_url( 'grandchild.js' ), array(), '1', true ); // in footer
+
+		wp_enqueue_script( 'parent' );
+
+		$header = get_echo( 'wp_print_head_scripts' );
+		$footer = get_echo( 'wp_print_footer_scripts' );
+
+		$expected_header  = "<script type='text/javascript' src='http://example.org/grandchild.js?ver=1'></script>\n";
+		$expected_header .= "<script type='text/javascript' src='http://example.org/child.js?ver=1'></script>\n";
+		$expected_footer  = "<script type='text/javascript' src='http://example.org/parent.js?ver=1'></script>\n";
+
+		$this->assertEquals( $expected_header, $header );
+		$this->assertEquals( $expected_footer, $footer );
+	}
 }
