<!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>[Tests][1041] trunk/tests: adding initial slashes test cases for core ticket #21676</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, #logmsg > ol { margin-left: 0; 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">
<dt>Revision</dt> <dd><a href="http://unit-tests.trac.wordpress.org/changeset/1041">1041</a></dd>
<dt>Author</dt> <dd>alexkingorg</dd>
<dt>Date</dt> <dd>2012-09-22 22:04:30 +0000 (Sat, 22 Sep 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>adding initial slashes test cases for core ticket <a href="http://unit-tests.trac.wordpress.org/ticket/21676">#21676</a></pre>

<h3>Added Paths</h3>
<ul>
<li>trunk/tests/comment/</li>
<li><a href="#trunktestscommentslashesphp">trunk/tests/comment/slashes.php</a></li>
<li>trunk/tests/meta/</li>
<li><a href="#trunktestsmetaslashesphp">trunk/tests/meta/slashes.php</a></li>
<li><a href="#trunktestspostslashesphp">trunk/tests/post/slashes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestscommentslashesphp"></a>
<div class="addfile"><h4>Added: trunk/tests/comment/slashes.php (0 => 1041)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/comment/slashes.php                                (rev 0)
+++ trunk/tests/comment/slashes.php        2012-09-22 22:04:30 UTC (rev 1041)
</span><span class="lines">@@ -0,0 +1,162 @@
</span><ins>+&lt;?php
+
+/**
+ * @group comment
+ * @group slashes
+ * @ticket 21767
+ */
+class Tests_Comment_Slashes extends WP_UnitTestCase {
+        function setUp() {
+                parent::setUp();
+                // we need an admin user to bypass comment flood protection
+                $this-&gt;author_id = $this-&gt;factory-&gt;user-&gt;create( array( 'role' =&gt; 'administrator' ) );
+                $this-&gt;old_current_user = get_current_user_id();
+                wp_set_current_user( $this-&gt;author_id );
+                
+                // it is important to test with both even and odd numbered slashes as
+                // kses does a strip-then-add slashes in some of it's function calls
+                $this-&gt;slash_1 = 'String with 1 slash \\';
+                $this-&gt;slash_2 = 'String with 2 slashes \\\\';
+                $this-&gt;slash_3 = 'String with 3 slashes \\\\\\';
+                $this-&gt;slash_4 = 'String with 4 slashes \\\\\\\\';
+                $this-&gt;slash_5 = 'String with 5 slashes \\\\\\\\\\';
+                $this-&gt;slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
+                $this-&gt;slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
+        }
+
+        function tearDown() {
+                wp_set_current_user( $this-&gt;old_current_user );
+                parent::tearDown();
+        }
+
+        /**
+         * Tests the extended model function that expects un-slashed data
+         *
+         */
+        function test_wp_new_comment() {
+                $post_id = $this-&gt;factory-&gt;post-&gt;create();
+
+                // not testing comment_author_email or comment_author_url 
+                // as slashes are not permitted in that data
+                $data = array(
+                        'comment_post_ID' =&gt; $post_id,
+                        'comment_author' =&gt; $this-&gt;slash_1,
+                        'comment_content' =&gt; $this-&gt;slash_7,
+                );
+                $id = wp_new_comment( $data );
+
+                $comment = get_comment($id);
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_7, $comment-&gt;comment_content );
+
+                $data = array(
+                        'comment_post_ID' =&gt; $post_id,
+                        'comment_author' =&gt; $this-&gt;slash_2,
+                        'comment_content' =&gt; $this-&gt;slash_4,
+                );
+                $id = wp_new_comment( $data );
+
+                $comment = get_comment($id);
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $comment-&gt;comment_content );
+        }
+
+        /**
+         * Tests the controller function that expects slashed data
+         *
+         */
+        function test_edit_comment() {
+                $post_id = $this-&gt;factory-&gt;post-&gt;create();
+                $comment_id = $this-&gt;factory-&gt;comment-&gt;create(array(
+                        'comment_post_ID' =&gt; $post_id
+                ));
+
+                // not testing comment_author_email or comment_author_url 
+                // as slashes are not permitted in that data
+                $_POST = array();
+                $_POST['comment_ID'] = $comment_id;
+                $_POST['newcomment_author'] = $this-&gt;slash_1;
+                $_POST['content'] = $this-&gt;slash_7;
+                $_POST = add_magic_quotes( $_POST );
+                
+                edit_comment();
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_7, $comment-&gt;comment_content );
+
+                $_POST = array();
+                $_POST['comment_ID'] = $comment_id;
+                $_POST['newcomment_author'] = $this-&gt;slash_2;
+                $_POST['content'] = $this-&gt;slash_4;
+                $_POST = add_magic_quotes( $_POST );
+                
+                edit_comment();
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $comment-&gt;comment_content );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_insert_comment() {
+                $post_id = $this-&gt;factory-&gt;post-&gt;create();
+                
+                $comment_id = wp_insert_comment(array(
+                        'comment_post_ID' =&gt; $post_id,
+                        'comment_author' =&gt; $this-&gt;slash_1,
+                        'comment_content' =&gt; $this-&gt;slash_7,
+                ));
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_7, $comment-&gt;comment_content );
+
+                $comment_id = wp_insert_comment(array(
+                        'comment_post_ID' =&gt; $post_id,
+                        'comment_author' =&gt; $this-&gt;slash_2,
+                        'comment_content' =&gt; $this-&gt;slash_4,
+                ));
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $comment-&gt;comment_content );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_update_comment() {
+                $post_id = $this-&gt;factory-&gt;post-&gt;create();
+                $comment_id = $this-&gt;factory-&gt;comment-&gt;create(array(
+                        'comment_post_ID' =&gt; $post_id
+                ));
+                
+                wp_update_comment(array(
+                        'comment_ID' =&gt; $comment_id,
+                        'comment_author' =&gt; $this-&gt;slash_1,
+                        'comment_content' =&gt; $this-&gt;slash_7,
+                ));
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_7, $comment-&gt;comment_content );
+
+                wp_update_comment(array(
+                        'comment_ID' =&gt; $comment_id,
+                        'comment_author' =&gt; $this-&gt;slash_2,
+                        'comment_content' =&gt; $this-&gt;slash_4,
+                ));
+                $comment = get_comment( $comment_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $comment-&gt;comment_author );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $comment-&gt;comment_content );
+        }
+
+}
</ins></span></pre></div>
<a id="trunktestsmetaslashesphp"></a>
<div class="addfile"><h4>Added: trunk/tests/meta/slashes.php (0 => 1041)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/meta/slashes.php                                (rev 0)
+++ trunk/tests/meta/slashes.php        2012-09-22 22:04:30 UTC (rev 1041)
</span><span class="lines">@@ -0,0 +1,223 @@
</span><ins>+&lt;?php
+
+/**
+ * @group meta
+ * @group slashes
+ * @ticket 21767
+ */
+class Tests_Meta_Slashes extends WP_UnitTestCase {
+        function setUp() {
+                parent::setUp();
+                $this-&gt;author_id = $this-&gt;factory-&gt;user-&gt;create( array( 'role' =&gt; 'editor' ) );
+                $this-&gt;old_current_user = get_current_user_id();
+                wp_set_current_user( $this-&gt;author_id );
+
+                $this-&gt;slash_1 = 'String with 1 slash \\';
+                $this-&gt;slash_2 = 'String with 2 slashes \\\\';
+                $this-&gt;slash_3 = 'String with 3 slashes \\\\\\';
+                $this-&gt;slash_4 = 'String with 4 slashes \\\\\\\\';
+                $this-&gt;slash_5 = 'String with 5 slashes \\\\\\\\\\';
+                $this-&gt;slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
+                $this-&gt;slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
+        }
+
+        function tearDown() {
+                wp_set_current_user( $this-&gt;old_current_user );
+                parent::tearDown();
+        }
+
+        /**
+         * Tests the controller function that expects slashed data
+         *
+         */
+        function test_edit_post() {
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+                if ( function_exists( 'wp_add_post_meta' ) ) {
+                        $meta_1 = wp_add_post_meta( $id, 'slash_test_1', 'foo' );
+                        $meta_2 = wp_add_post_meta( $id, 'slash_test_2', 'foo' );
+                        $meta_3 = wp_add_post_meta( $id, 'slash_test_3', 'foo' );
+                }
+                else {
+                        // expects slashed data
+                        $meta_1 = add_post_meta( $id, 'slash_test_1', addslashes( 'foo' ) );
+                        $meta_2 = add_post_meta( $id, 'slash_test_2', addslashes( 'foo' ) );
+                        $meta_3 = add_post_meta( $id, 'slash_test_3', addslashes( 'foo' ) );
+                }
+
+                $_POST = array();
+                $_POST['post_ID'] = $id;
+                $_POST['metakeyselect'] = '#NONE#';
+                $_POST['metakeyinput'] = 'slash_test_0';
+                $_POST['metavalue'] = $this-&gt;slash_6;
+                $_POST['meta'] = array(
+                        $meta_1 =&gt; array(
+                                'key' =&gt; 'slash_test_1',
+                                'value' =&gt; $this-&gt;slash_1
+                        ),
+                        $meta_2 =&gt; array(
+                                'key' =&gt; 'slash_test_2',
+                                'value' =&gt; $this-&gt;slash_3
+                        ),
+                        $meta_3 =&gt; array(
+                                'key' =&gt; 'slash_test_3',
+                                'value' =&gt; $this-&gt;slash_4
+                        ),
+                );
+                $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
+
+                edit_post();
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_6, get_post_meta( $id, 'slash_test_0', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_3', true ) );
+
+                $_POST = array();
+                $_POST['post_ID'] = $id;
+                $_POST['metakeyselect'] = '#NONE#';
+                $_POST['metakeyinput'] = 'slash_test_0';
+                $_POST['metavalue'] = $this-&gt;slash_7;
+                $_POST['meta'] = array(
+                        $meta_1 =&gt; array(
+                                'key' =&gt; 'slash_test_1',
+                                'value' =&gt; $this-&gt;slash_2
+                        ),
+                        $meta_2 =&gt; array(
+                                'key' =&gt; 'slash_test_2',
+                                'value' =&gt; $this-&gt;slash_4
+                        ),
+                        $meta_3 =&gt; array(
+                                'key' =&gt; 'slash_test_3',
+                                'value' =&gt; $this-&gt;slash_5
+                        ),
+                );
+                $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
+
+                edit_post();
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_5, get_post_meta( $id, 'slash_test_3', true ) );
+        }
+
+        /**
+         * Tests the legacy model function that expects slashed data
+         *
+         */
+        function test_add_post_meta() {
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+                add_post_meta( $id, 'slash_test_1', addslashes( $this-&gt;slash_1 ) );
+                add_post_meta( $id, 'slash_test_2', addslashes( $this-&gt;slash_3 ) );
+                add_post_meta( $id, 'slash_test_3', addslashes( $this-&gt;slash_4 ) );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_3', true ) );
+        }
+
+        /**
+         * Tests the legacy model function that expects slashed data
+         *
+         */
+        function test_update_post_meta() {
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+                update_post_meta( $id, 'slash_test_1', addslashes( $this-&gt;slash_1 ) );
+                update_post_meta( $id, 'slash_test_2', addslashes( $this-&gt;slash_3 ) );
+                update_post_meta( $id, 'slash_test_3', addslashes( $this-&gt;slash_4 ) );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_3', true ) );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_add_post_meta() {
+                if ( !function_exists( 'wp_add_post_meta' ) ) {
+                        return;
+                }
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+                wp_add_post_meta( $id, 'slash_test_1', $this-&gt;slash_1 );
+                wp_add_post_meta( $id, 'slash_test_2', $this-&gt;slash_3 );
+                wp_add_post_meta( $id, 'slash_test_3', $this-&gt;slash_4 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_3', true ) );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_update_post_meta() {
+                if ( !function_exists( 'wp_update_post_meta' ) ) {
+                        return;
+                }
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+                wp_update_post_meta( $id, 'slash_test_1', $this-&gt;slash_1 );
+                wp_update_post_meta( $id, 'slash_test_2', $this-&gt;slash_3 );
+                wp_update_post_meta( $id, 'slash_test_3', $this-&gt;slash_4 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_post_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_post_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_post_meta( $id, 'slash_test_3', true ) );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_add_comment_meta() {
+                $id = $this-&gt;factory-&gt;comment-&gt;create();
+
+                add_comment_meta( $id, 'slash_test_1', $this-&gt;slash_1 );
+                add_comment_meta( $id, 'slash_test_2', $this-&gt;slash_3 );
+                add_comment_meta( $id, 'slash_test_3', $this-&gt;slash_5 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_comment_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_comment_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_5, get_comment_meta( $id, 'slash_test_3', true ) );
+
+                add_comment_meta( $id, 'slash_test_4', $this-&gt;slash_2 );
+                add_comment_meta( $id, 'slash_test_5', $this-&gt;slash_4 );
+                add_comment_meta( $id, 'slash_test_6', $this-&gt;slash_6 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, get_comment_meta( $id, 'slash_test_4', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_comment_meta( $id, 'slash_test_5', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_6, get_comment_meta( $id, 'slash_test_6', true ) );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_update_comment_meta() {
+                $id = $this-&gt;factory-&gt;comment-&gt;create();
+
+                add_comment_meta( $id, 'slash_test_1', 'foo' );
+                add_comment_meta( $id, 'slash_test_2', 'foo' );
+                add_comment_meta( $id, 'slash_test_3', 'foo' );
+
+                update_comment_meta( $id, 'slash_test_1', $this-&gt;slash_1 );
+                update_comment_meta( $id, 'slash_test_2', $this-&gt;slash_3 );
+                update_comment_meta( $id, 'slash_test_3', $this-&gt;slash_5 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, get_comment_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_3, get_comment_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_5, get_comment_meta( $id, 'slash_test_3', true ) );
+
+                update_comment_meta( $id, 'slash_test_1', $this-&gt;slash_2 );
+                update_comment_meta( $id, 'slash_test_2', $this-&gt;slash_4 );
+                update_comment_meta( $id, 'slash_test_3', $this-&gt;slash_6 );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, get_comment_meta( $id, 'slash_test_1', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_4, get_comment_meta( $id, 'slash_test_2', true ) );
+                $this-&gt;assertEquals( $this-&gt;slash_6, get_comment_meta( $id, 'slash_test_3', true ) );
+        }
+
+}
</ins></span></pre></div>
<a id="trunktestspostslashesphp"></a>
<div class="addfile"><h4>Added: trunk/tests/post/slashes.php (0 => 1041)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/post/slashes.php                                (rev 0)
+++ trunk/tests/post/slashes.php        2012-09-22 22:04:30 UTC (rev 1041)
</span><span class="lines">@@ -0,0 +1,131 @@
</span><ins>+&lt;?php
+
+/**
+ * @group post
+ * @group slashes
+ * @ticket 21767
+ */
+class Tests_Post_Slashes extends WP_UnitTestCase {
+        function setUp() {
+                parent::setUp();
+                $this-&gt;author_id = $this-&gt;factory-&gt;user-&gt;create( array( 'role' =&gt; 'editor' ) );
+                $this-&gt;old_current_user = get_current_user_id();
+                wp_set_current_user( $this-&gt;author_id );
+                
+                // it is important to test with both even and odd numbered slashes as
+                // kses does a strip-then-add slashes in some of it's function calls
+                $this-&gt;slash_1 = 'String with 1 slash \\';
+                $this-&gt;slash_2 = 'String with 2 slashes \\\\';
+                $this-&gt;slash_3 = 'String with 3 slashes \\\\\\';
+                $this-&gt;slash_4 = 'String with 4 slashes \\\\\\\\';
+                $this-&gt;slash_5 = 'String with 5 slashes \\\\\\\\\\';
+                $this-&gt;slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
+                $this-&gt;slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
+        }
+
+        function tearDown() {
+                wp_set_current_user( $this-&gt;old_current_user );
+                parent::tearDown();
+        }
+
+        /**
+         * Tests the controller function that expects slashed data
+         *
+         */
+        function test_edit_post() {
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+
+                $_POST = array();
+                $_POST['post_ID'] = $id;
+                $_POST['post_title'] = $this-&gt;slash_1;
+                $_POST['content'] = $this-&gt;slash_5;
+                $_POST['excerpt'] = $this-&gt;slash_7;
+                $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
+
+                $post_id = edit_post();
+                $post = get_post( $post_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_5, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_7, $post-&gt;post_excerpt );
+
+                $_POST = array();
+                $_POST['post_ID'] = $id;
+                $_POST['post_title'] = $this-&gt;slash_2;
+                $_POST['content'] = $this-&gt;slash_4;
+                $_POST['excerpt'] = $this-&gt;slash_6;
+                $_POST = add_magic_quotes( $_POST );
+
+                $post_id = edit_post();
+                $post = get_post( $post_id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_6, $post-&gt;post_excerpt );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_insert_post() {
+                $id = wp_insert_post(array(
+                        'post_status' =&gt; 'publish',
+                        'post_title' =&gt; $this-&gt;slash_1,
+                        'post_content' =&gt; $this-&gt;slash_3,
+                        'post_excerpt' =&gt; $this-&gt;slash_5,
+                        'post_type' =&gt; 'post'
+                ));
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_3, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_5, $post-&gt;post_excerpt );
+
+                $id = wp_insert_post(array(
+                        'post_status' =&gt; 'publish',
+                        'post_title' =&gt; $this-&gt;slash_2,
+                        'post_content' =&gt; $this-&gt;slash_4,
+                        'post_excerpt' =&gt; $this-&gt;slash_6,
+                        'post_type' =&gt; 'post'
+                ));
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_6, $post-&gt;post_excerpt );
+        }
+
+        /**
+         * Tests the model function that expects un-slashed data
+         *
+         */
+        function test_wp_update_post() {
+                $id = $this-&gt;factory-&gt;post-&gt;create();
+        
+                wp_update_post(array(
+                        'ID' =&gt; $id,
+                        'post_title' =&gt; $this-&gt;slash_1,
+                        'post_content' =&gt; $this-&gt;slash_3,
+                        'post_excerpt' =&gt; $this-&gt;slash_5,
+                ));
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_1, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_3, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_5, $post-&gt;post_excerpt );
+
+                wp_update_post(array(
+                        'ID' =&gt; $id,
+                        'post_title' =&gt; $this-&gt;slash_2,
+                        'post_content' =&gt; $this-&gt;slash_4,
+                        'post_excerpt' =&gt; $this-&gt;slash_6,
+                ));
+                $post = get_post( $id );
+
+                $this-&gt;assertEquals( $this-&gt;slash_2, $post-&gt;post_title );
+                $this-&gt;assertEquals( $this-&gt;slash_4, $post-&gt;post_content );
+                $this-&gt;assertEquals( $this-&gt;slash_6, $post-&gt;post_excerpt );
+        }
+
+}
</ins></span></pre>
</div>
</div>

</body>
</html>