コード例 #1
0
ファイル: slashes.php プロジェクト: pbearne/contrib2core
 /**
  * Tests the controller function that expects slashed data
  *
  */
 function test_edit_post()
 {
     $id = self::factory()->post->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->slash_6;
     $_POST['meta'] = array($meta_1 => array('key' => 'slash_test_1', 'value' => $this->slash_1), $meta_2 => array('key' => 'slash_test_2', 'value' => $this->slash_3), $meta_3 => array('key' => 'slash_test_3', 'value' => $this->slash_4));
     $_POST = add_magic_quotes($_POST);
     // the edit_post() function will strip slashes
     edit_post();
     $post = get_post($id);
     $this->assertEquals($this->slash_6, get_post_meta($id, 'slash_test_0', true));
     $this->assertEquals($this->slash_1, get_post_meta($id, 'slash_test_1', true));
     $this->assertEquals($this->slash_3, get_post_meta($id, 'slash_test_2', true));
     $this->assertEquals($this->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->slash_7;
     $_POST['meta'] = array($meta_1 => array('key' => 'slash_test_1', 'value' => $this->slash_2), $meta_2 => array('key' => 'slash_test_2', 'value' => $this->slash_4), $meta_3 => array('key' => 'slash_test_3', 'value' => $this->slash_5));
     $_POST = add_magic_quotes($_POST);
     // the edit_post() function will strip slashes
     edit_post();
     $post = get_post($id);
     $this->assertEquals($this->slash_2, get_post_meta($id, 'slash_test_1', true));
     $this->assertEquals($this->slash_4, get_post_meta($id, 'slash_test_2', true));
     $this->assertEquals($this->slash_5, get_post_meta($id, 'slash_test_3', true));
 }
コード例 #2
0
ファイル: slashes.php プロジェクト: boonebgorges/wp
 /**
  * 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->factory->post->create();
     wp_add_post_meta($id, 'slash_test_1', $this->slash_1);
     wp_add_post_meta($id, 'slash_test_2', $this->slash_3);
     wp_add_post_meta($id, 'slash_test_3', $this->slash_4);
     $this->assertEquals($this->slash_1, get_post_meta($id, 'slash_test_1', true));
     $this->assertEquals($this->slash_3, get_post_meta($id, 'slash_test_2', true));
     $this->assertEquals($this->slash_4, get_post_meta($id, 'slash_test_3', true));
 }