Index: tests/phpunit/tests/post/template.php
===================================================================
--- tests/phpunit/tests/post/template.php	(revision 31480)
+++ tests/phpunit/tests/post/template.php	(working copy)
@@ -197,4 +197,48 @@
 
 		$this->assertContains( 'value="' . $p . '"', $found );
 	}
+
+	/**
+	 * @ticket 31389
+	 */
+	public function test_get_page_template_slug_by_id() {
+		$page_id = $this->factory->post->create( array(
+			'post_type' => 'page',
+		) );
+
+		$this->assertEquals( get_page_template_slug($page_id), '' );
+
+		update_post_meta($page_id, '_wp_page_template', 'default');
+		$this->assertEquals( get_page_template_slug($page_id), '' );
+
+		update_post_meta($page_id, '_wp_page_template', 'example.php');
+		$this->assertEquals( get_page_template_slug($page_id), 'example.php' );
+	}
+
+	/**
+	 * @ticket 31389
+	 */
+	public function test_get_page_template_slug_from_loop() {
+		$page_id = $this->factory->post->create( array(
+			'post_type' => 'page',
+		) );
+		update_post_meta($page_id, '_wp_page_template', 'example.php');
+		$this->go_to( get_permalink( $page_id ) );
+
+		$this->assertEquals( get_page_template_slug(), 'example.php' );
+	}
+
+	/**
+	 * @ticket 31389
+	 */
+	public function test_get_page_template_slug_non_page() {
+		$post_id = $this->factory->post->create( array(
+			'post_type' => 'post',
+		) );
+
+		$this->assertFalse( get_page_template_slug($post_id) );
+
+		$this->go_to( get_permalink( $post_id ) );
+		$this->assertFalse( get_page_template_slug() );
+	}
 }
