public function setUp()
 {
     parent::setUp();
     Fieldmanager_Field::$debug = true;
     // insert a post
     $this->post = $this->factory->post->create_and_get(array('post_title' => rand_str(), 'post_date' => '2009-07-01 00:00:00'));
 }
Beispiel #2
0
function xd_check_input($id = 1)
{
    /*
     *On génére un hash aléatoire qui sera 
     *ajouté aux formulaires, afin d'ajouter 
     *une vérification supplémentaire
     *lors du traitement de ce dernier
     */
    /*
     *     le parametre $id permet de selectionner le type de retour
     *     0=> un input type hidden sans id
     *     1=> un input type hidden avec id
     *     2=> juste la valeur
     */
    if (!isset($_SESSION['xd_check'])) {
        //le générer
        $_SESSION['xd_check'] = rand_str(25);
    }
    switch ($id) {
        case 0:
            return "<input type=\"hidden\" name=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
            break;
        case 1:
            return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
            break;
        case 2:
            return $_SESSION['xd_check'];
            break;
        default:
            return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
            break;
    }
}
Beispiel #3
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $this->demo_user = array('user_login' => 'author1', 'user_nicename' => 'author-nicename', 'user_pass' => rand_str(), 'role' => 'author', 'display_name' => 'Michael Scott');
     $this->demo_user_id = $this->factory->user->create($this->demo_user);
     $this->demo_term = array('taxonomy' => 'category', 'name' => 'cat-a', 'slug' => 'cat-a');
     $this->demo_term_id = $this->factory->term->create($this->demo_term);
     $post_date = '';
     $this->demo_dates = array('post_date' => array('date' => '2013-02-28 01:23:45'), 'post_date_gmt' => array('date' => '2013-02-28 05:23:45'), 'post_modified' => array('date' => '2013-02-28 01:23:45'), 'post_modified_gmt' => array('date' => '2013-02-28 05:23:45'));
     foreach ($this->demo_dates as &$date) {
         $ts = strtotime($date['date']);
         $date = array('date' => strval($date['date']), 'year' => intval(date('Y', $ts)), 'month' => intval(date('m', $ts)), 'day' => intval(date('d', $ts)), 'hour' => intval(date('H', $ts)), 'minute' => intval(date('i', $ts)), 'second' => intval(date('s', $ts)), 'week' => intval(date('W', $ts)), 'day_of_week' => intval(date('N', $ts)), 'day_of_year' => intval(date('z', $ts)), 'seconds_from_day' => intval(mktime(date('H', $ts), date('i', $ts), date('s', $ts), 1, 1, 1970)), 'seconds_from_hour' => intval(mktime(0, date('i', $ts), date('s', $ts), 1, 1, 1970)));
     }
     $this->demo_post = array('post_author' => $this->demo_user_id, 'post_date' => $this->demo_dates['post_date']['date'], 'post_date_gmt' => $this->demo_dates['post_date_gmt']['date'], 'post_content' => 'Welcome to <a href="http://wp.dev/">Local WordPress Dev Sites</a>. This is your first post. Edit or delete it, then start blogging!', 'post_title' => 'Hello world!', 'post_excerpt' => 'Lorem ipsum dolor sit amet', 'post_status' => 'publish', 'post_password' => 'foobar', 'post_name' => 'hello-world', 'post_parent' => 123, 'menu_order' => 456, 'post_type' => 'post', 'post_mime_type' => 'image/jpeg', 'post_category' => array($this->demo_term_id));
     $this->demo_post_id = $this->factory->post->create($this->demo_post);
     add_post_meta($this->demo_post_id, 'test_string', 'foo');
     add_post_meta($this->demo_post_id, 'test_long', '123');
     add_post_meta($this->demo_post_id, 'test_double', '123.456');
     add_post_meta($this->demo_post_id, 'test_boolean_true', 'true');
     add_post_meta($this->demo_post_id, 'test_boolean_false', 'false');
     add_post_meta($this->demo_post_id, 'test_date', '2012-03-14 03:14:15');
     SP_Sync_Manager()->sync_post($this->demo_post_id);
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Beispiel #4
0
 public function upload()
 {
     $img_url = array();
     if (!empty($_FILES)) {
         foreach ($_FILES as $file) {
             if ($file["error"] > 0) {
                 echo "上传失败" . $_FILES["file"]["error"] . "<br>";
                 exit;
             }
             if (file_exists(STATICPATH . 'img/' . $file["name"])) {
                 echo $file["name"] . "已经存在!";
                 exit;
             }
             $folder = date('ym');
             $img_dir = ADMIN_IMG_PATH . $folder;
             !is_dir($img_dir) ? mkdir($img_dir) : null;
             $new_file_name = rand_str(8) . time() . '.jpg';
             move_uploaded_file($file["tmp_name"], $img_dir . '/' . $new_file_name);
             $img_url[] = base_url('static/img/' . $folder . '/' . $new_file_name);
         }
     }
     $json = json_encode($img_url);
     echo $json;
     exit;
 }
 public function test_wp_insert_delete_term()
 {
     $taxonomy = 'wptests_tax';
     register_taxonomy($taxonomy, 'post');
     // a new unused term
     $term = rand_str();
     $this->assertNull(term_exists($term));
     $initial_count = wp_count_terms($taxonomy);
     $t = wp_insert_term($term, $taxonomy);
     $this->assertInternalType('array', $t);
     $this->assertNotWPError($t);
     $this->assertTrue($t['term_id'] > 0);
     $this->assertTrue($t['term_taxonomy_id'] > 0);
     $this->assertEquals($initial_count + 1, wp_count_terms($taxonomy));
     // make sure the term exists
     $this->assertTrue(term_exists($term) > 0);
     $this->assertTrue(term_exists($t['term_id']) > 0);
     // now delete it
     add_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
     $this->assertTrue(wp_delete_term($t['term_id'], $taxonomy));
     remove_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
     $this->assertNull(term_exists($term));
     $this->assertNull(term_exists($t['term_id']));
     $this->assertEquals($initial_count, wp_count_terms($taxonomy));
 }
 public function sendtoaddress($address, $amount)
 {
     if ($amount >= $this->balance) {
         throw new \Exception('Not enough balance');
     }
     return rand_str();
 }
 function setUp()
 {
     parent::setUp();
     $this->post_date_ts = strtotime('+1 day');
     $this->post_data = array('post_type' => 'page', 'post_title' => rand_str(), 'post_content' => rand_str(2000), 'post_excerpt' => rand_str(100), 'post_author' => $this->make_user_by_role('author'), 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $this->post_date_ts));
     $this->post_id = wp_insert_post($this->post_data);
 }
 /**
  * Test context calculations for submenus.
  */
 public function test_submenu_contexts()
 {
     $screen = get_current_screen();
     $self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null;
     $page = isset($_GET['page']) ? $_GET['page'] : null;
     $submenus = _fieldmanager_registry('submenus');
     _fieldmanager_registry('submenus', array());
     // Spoof is_admin().
     set_current_screen('dashboard-user');
     // Submenu of a default WordPress menu.
     $options_submenu = rand_str();
     fm_register_submenu_page($options_submenu, 'options-general.php', 'Options');
     $_SERVER['PHP_SELF'] = '/options-general.php';
     $_GET['page'] = $options_submenu;
     $this->assertEquals(array('submenu', $options_submenu), fm_calculate_context());
     // Submenu of a custom menu.
     $custom_menu_submenu = rand_str();
     fm_register_submenu_page($custom_menu_submenu, rand_str(), 'Custom');
     $_SERVER['PHP_SELF'] = '/admin.php';
     $_GET['page'] = $custom_menu_submenu;
     $this->assertEquals(array('submenu', $custom_menu_submenu), fm_calculate_context());
     // Submenu that Fieldmanager didn't register.
     $_SERVER['PHP_SELF'] = '/themes.php';
     $_GET['page'] = rand_str();
     $this->assertEquals(array(null, null), fm_calculate_context());
     $GLOBALS['current_screen'] = $screen;
     $_SERVER['PHP_SELF'] = $self;
     $_GET['page'] = $page;
     _fieldmanager_registry('submenus', $submenus);
 }
 function setUp()
 {
     parent::setUp();
     $this->parent_term = wp_insert_term('parent' . rand_str(), 'category');
     $this->assertInternalType('array', $this->parent_term);
     $this->parent_term = $this->parent_term['term_id'];
 }
 function setUp()
 {
     parent::setUp();
     $args = array('post_author' => 1, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
     $id = wp_insert_post($args);
     $this->post = get_post($id);
 }
Beispiel #11
0
 function test_get_doesnt_cache_default_value()
 {
     $option = rand_str();
     $default = 'a default';
     $this->assertEquals(get_site_option($option, $default), $default);
     $this->assertFalse(get_site_option($option));
 }
Beispiel #12
0
function create_user($username, $password, $first_name, $last_name, $email, $access)
{
    $salt = rand_str(32);
    $checksum = md5(md5($password) . $salt);
    $s = q("insert into user values('', '" . clean_query($username) . "', '" . clean_query($checksum) . "', '" . clean_query($salt) . "', '" . clean_query($first_name) . "', '" . clean_query($last_name) . "', '" . clean_query($email) . "', '" . clean_query($access) . "');");
    return a() > 0 ? true : false;
}
 function test_delete_user()
 {
     $user_id = $this->factory->user->create(array('role' => 'author'));
     $user = new WP_User($user_id);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
     // insert a post and make sure the ID is ok
     $post_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($post_id));
     $this->assertTrue($post_id > 0);
     $post = get_post($post_id);
     $this->assertEquals($post_id, $post->ID);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'nav_menu_item');
     // insert a post and make sure the ID is ok
     $nav_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($nav_id));
     $this->assertTrue($nav_id > 0);
     $post = get_post($nav_id);
     $this->assertEquals($nav_id, $post->ID);
     wp_delete_user($user_id);
     $user = new WP_User($user_id);
     if (is_multisite()) {
         $this->assertTrue($user->exists());
     } else {
         $this->assertFalse($user->exists());
     }
     $this->assertNotNull(get_post($post_id));
     $this->assertEquals('trash', get_post($post_id)->post_status);
     // nav_menu_item is delete_with_user = false so the nav post should remain published.
     $this->assertNotNull(get_post($nav_id));
     $this->assertEquals('publish', get_post($nav_id)->post_status);
     wp_delete_post($nav_id, true);
     $this->assertNull(get_post($nav_id));
     wp_delete_post($post_id, true);
     $this->assertNull(get_post($post_id));
 }
 /**
  * Helper function: insert an attachment to test properties of.
  *
  * @param int $parent_post_id
  * @param str path to image to use
  * @param array $post_fields Fields, in the format to be sent to `wp_insert_post()`
  * @return int Post ID of inserted attachment
  */
 private function insert_attachment($parent_post_id = 0, $image = null, $post_fields = array())
 {
     $filename = rand_str() . '.jpg';
     $contents = rand_str();
     if ($image) {
         // @codingStandardsIgnoreStart
         $filename = basename($image);
         $contents = file_get_contents($image);
         // @codingStandardsIgnoreEnd
     }
     $upload = wp_upload_bits($filename, null, $contents);
     $this->assertTrue(empty($upload['error']));
     $type = '';
     if (!empty($upload['type'])) {
         $type = $upload['type'];
     } else {
         $mime = wp_check_filetype($upload['file']);
         if ($mime) {
             $type = $mime['type'];
         }
     }
     $attachment = wp_parse_args($post_fields, array('post_title' => basename($upload['file']), 'post_content' => 'Test Attachment', 'post_type' => 'attachment', 'post_parent' => $parent_post_id, 'post_mime_type' => $type, 'guid' => $upload['url']));
     // Save the data
     $id = wp_insert_attachment($attachment, $upload['file'], $parent_post_id);
     wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file']));
     return $id;
 }
	public function test_comment_content_length() {
		// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
		if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
			$remote_addr = $_SERVER['REMOTE_ADDR'];
		} else {
			$_SERVER['REMOTE_ADDR'] = '';
		}

		$u = $this->factory->user->create();
		$post_id = $this->factory->post->create( array( 'post_author' => $u ) );

		$data = array(
			'comment_post_ID' => $post_id,
			'comment_author' => rand_str(),
			'comment_author_url' => '',
			'comment_author_email' => '',
			'comment_type' => '',
			'comment_content' => str_repeat( 'A', 65536 ),
			'comment_date' => '2011-01-01 10:00:00',
			'comment_date_gmt' => '2011-01-01 10:00:00',
		);

		add_filter( 'pre_option_moderation_notify', '__return_zero' );
		$id = wp_new_comment( $data );
		remove_filter( 'pre_option_moderation_notify', '__return_zero' );

		$this->assertEmpty( $id );

		// Cleanup.
		if ( isset( $remote_addr ) ) {
			$_SERVER['REMOTE_ADDR'] = $remote_addr;
		} else {
			unset( $_SERVER['REMOTE_ADDR'] );
		}
	}
	/**
	 * When a site is deleted with wpmu_delete_blog(), only the files associated with
	 * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
	 * should change with upload directories.
	 */
	function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
		$filename = rand_str().'.jpg';
		$contents = rand_str();

		// Upload a file to the main site on the network.
		$file1 = wp_upload_bits( $filename, null, $contents );

		$blog_id = $this->factory->blog->create();

		switch_to_blog( $blog_id );
		$file2 = wp_upload_bits( $filename, null, $contents );
		restore_current_blog();

		wpmu_delete_blog( $blog_id, true );

		// The file on the main site should still exist. The file on the deleted site should not.
		$this->assertTrue( file_exists( $file1['file'] ) );
		$this->assertFalse( file_exists( $file2['file'] ) );

		wpmu_delete_blog( $blog_id, true );

		// The file on the main site should still exist. The file on the deleted site should not.
		$this->assertTrue( file_exists( $file1['file'] ) );
		$this->assertFalse( file_exists( $file2['file'] ) );
	}
 public function setUp()
 {
     parent::setUp();
     Fieldmanager_Field::$debug = TRUE;
     $this->post = array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str());
     // insert a post
     $this->post_id = wp_insert_post($this->post);
 }
 function setUp()
 {
     parent::setUp();
     $args = array('post_author' => 1, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
     $id = wp_insert_post($args);
     update_post_meta($id, '_wp_page_template', 'test.php');
     $this->post = get_post($id);
 }
 function test_create_posts($status = 'publish')
 {
     parent::setUp();
     global $wp_rewrite;
     $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     $post = array('post_author' => 1, 'post_status' => $status, 'post_content' => rand_str(), 'post_title' => '', 'post_date' => '2007-10-31 06:15:00');
     return wp_insert_post($post);
 }
Beispiel #20
0
 function setUp()
 {
     parent::setUp();
     // insert a post
     $id = wp_insert_post(array('post_author' => $this->author_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'tax_input' => array('post_tag' => 'tag1,tag2', 'ctax' => 'cterm1,cterm2'), 'post_type' => $post_type));
     // fetch the post
     $this->post = get_post($id);
 }
 public static function wpSetUpBeforeClass(WP_UnitTest_Factory $factory)
 {
     self::$post_id = $factory->post->create();
     self::$parent_comment_data = array('comment_post_ID' => self::$post_id, 'comment_author' => 'Test commenter', 'comment_author_url' => 'http://example.com/', 'comment_author_email' => '*****@*****.**', 'comment_content' => rand_str(100));
     self::$parent_comment_id = wp_insert_comment(self::$parent_comment_data);
     self::$child_comment_data = array('comment_post_ID' => self::$post_id, 'comment_author' => 'Test commenter 2', 'comment_author_url' => 'http://example.org/', 'comment_author_email' => '*****@*****.**', 'comment_parent' => self::$parent_comment_id, 'comment_content' => rand_str(100));
     self::$child_comment_id = wp_insert_comment(self::$child_comment_data);
 }
Beispiel #22
0
 function setUp()
 {
     parent::setUp();
     $this->config = Factory::create(WPDC_CORE_CONFIGS_DIR . 'structures/post/post-info.php', Post_Info::getDefaultsFile());
     $this->author = new WP_User($this->factory->user->create(array('role' => 'editor', 'user_nicename' => 'Tonya', 'display_name' => 'Tonya')));
     $post = array('post_author' => $this->author->ID, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str());
     $this->post_id = wp_insert_post($post);
 }
 public function setUp()
 {
     parent::setUp();
     Fieldmanager_Field::$debug = true;
     $this->post_id = $this->factory->post->create(array('post_title' => rand_str(), 'post_date' => '2009-07-01 00:00:00'));
     $this->post = get_post($this->post_id);
     $this->custom_datasource = new Fieldmanager_Datasource(array('options' => array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')));
 }
	function test_search_order_title_relevance() {
		foreach ( range( 1, 7 ) as $i )
			self::factory()->post->create( array( 'post_content' => $i . rand_str() . ' about', 'post_type' => $this->post_type ) );
		$post_id = self::factory()->post->create( array( 'post_title' => 'About', 'post_type' => $this->post_type ) );

		$posts = $this->get_search_results( 'About' );
		$this->assertEquals( $post_id, reset( $posts )->ID );
	}
 function test_insert_bogus_image()
 {
     $filename = rand_str() . '.jpg';
     $contents = rand_str();
     $upload = wp_upload_bits($filename, null, $contents);
     $this->assertTrue(empty($upload['error']));
     $id = $this->_make_attachment($upload);
 }
 public function test_get_date_front()
 {
     $post_type = rand_str(12);
     register_post_type($post_type, array("public" => true));
     update_option($post_type . "_structure", "/%year%/%monthnum%/%day%/%post_id%/");
     $this->assertEquals(CPTP_Util::get_date_front($post_type), "");
     update_option($post_type . "_structure", "/%post_id%/");
     $this->assertEquals(CPTP_Util::get_date_front($post_type), "/date");
 }
Beispiel #27
0
function gensym()
{
    static $FUNCTIONAL_TABLE = array();
    $x = rand_str(5);
    for ($x = rand_str(5); in_array($x, $FUNCTIONAL_TABLE); $x = rand_str()) {
    }
    array_push($FUNCTIONAL_TABLE, $x);
    return $x;
}
 /**
  * When creating an entry, set the correct data formats
  */
 function set_field_value($field)
 {
     $value = rand_str();
     $field_values = array('email' => '*****@*****.**', 'url' => 'http://test.com', 'number' => 120, 'scale' => 8, 'date' => '2015-01-01', 'user_id' => get_current_user_id());
     if (isset($field_values[$field->type])) {
         $value = $field_values[$field->type];
     }
     return $value;
 }
Beispiel #29
0
function getUniqueName($fileType)
{
    $imgNameLangth = bu::config('rc/imgNameLangth');
    $name = rand_str($imgNameLangth);
    while (file_exists(makePathForString($name, $fileType))) {
        $name = rand_str($imgNameLangth);
    }
    return $name;
}
 /**
  * Directories of sub sites on a network should not count against the same spaced used total for
  * the main site.
  */
 function test_get_space_used_main_site()
 {
     $space_used = get_space_used();
     $blog_id = $this->factory->blog->create();
     switch_to_blog($blog_id);
     // We don't rely on an initial value of 0 for space used, but should have a clean space available
     // so that we can remove any uploaded files and directories without concern of a conflict with
     // existing content directories in src.
     while (0 != get_space_used()) {
         restore_current_blog();
         $blog_id = $this->factory->blog->create();
         switch_to_blog($blog_id);
     }
     // Upload a file to the new site.
     $filename = rand_str() . '.jpg';
     $contents = rand_str();
     wp_upload_bits($filename, null, $contents);
     restore_current_blog();
     delete_transient('dirsize_cache');
     $this->assertEquals($space_used, get_space_used());
     // Switch back to the new site to remove the uploaded file.
     switch_to_blog($blog_id);
     $upload_dir = wp_upload_dir();
     $this->remove_added_uploads();
     $this->delete_folders($upload_dir['basedir']);
     restore_current_blog();
 }