Exemplo n.º 1
0
 /**
  * Generated the entry for the users table.
  *
  * @param  string $user_login The user login slug
  *
  * @return array             An associtive array of column/values for the "users" table.
  */
 public static function generateUserTableDataFrom($user_login, array $userData = array())
 {
     $utils = new Slugifier();
     $login = $utils->slugify($user_login);
     $usersTableDefaults = array('user_login' => $login, 'user_pass' => WpPassword::instance()->make($user_login), 'user_nicename' => $user_login, 'user_email' => $login . "@example.com", 'user_url' => "http://{$login}.example.com", 'user_registered' => Date::now(), 'user_activation_key' => '', 'user_status' => '0', 'display_name' => $user_login);
     if (!empty($userData['user_pass'])) {
         $userData['user_pass'] = WpPassword::instance()->make($userData['user_pass']);
     }
     return array_merge($usersTableDefaults, array_intersect_key($userData, $usersTableDefaults));
 }
Exemplo n.º 2
0
 /**
  * @test
  * it should allow using number placeholder when inserting many
  */
 public function it_should_allow_using_number_placeholder_when_inserting_many(FunctionalTester $I)
 {
     $overrides = ['link_url' => 'http://example.com/{{n}}', 'link_name' => 'Example {{n}}', 'link_image' => 'http://example.com/images/image-{{n}}.jpg', 'link_target' => '_blank', 'link_description' => '{{n}} example link', 'link_visible' => 'N', 'link_owner' => 12, 'link_rating' => 14, 'link_updated' => Date::fromString('today'), 'link_rel' => 'nofollow', 'link_notes' => 'Not a real {{n}} image', 'link_rss' => 'http://example.com/rss/{{n}}'];
     $ids = $I->haveManyLinksInDatabase(5, $overrides);
     $table = $I->grabLinksTableName();
     for ($i = 0; $i < count($ids); $i++) {
         $I->assertTrue(is_int($ids[$i]));
         foreach ($overrides as $key => $value) {
             $I->seeInDatabase($table, ['link_id' => $ids[$i], $key => str_replace('{{n}}', $i, $value)]);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @test
  * it should allow having many comments with number placeholder
  */
 public function it_should_allow_having_many_comments_with_number_placeholder(FunctionalTester $I)
 {
     $postId = $I->havePostInDatabase();
     $overrides = ['comment_author' => 'Luca', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'https://theaveragedev.com', 'comment_author_IP' => '111.222.333.444', 'comment_date' => Date::now(), 'comment_date_gmt' => Date::gmtNow(), 'comment_content' => "No comment", 'comment_karma' => '3', 'comment_approved' => '0', 'comment_agent' => 'some agent', 'comment_type' => 'status', 'comment_parent' => 23, 'user_id' => 12];
     $ids = $I->haveManyCommentsInDatabase(5, $postId, $overrides);
     $I->assertEquals(5, count($ids));
     for ($i = 0; $i < count($ids); $i++) {
         foreach ($overrides as $key => $value) {
             $I->seeInDatabase($I->grabCommentsTableName(), ['comment_post_ID' => $postId, 'comment_ID' => $ids[$i], $key => str_replace('{{n}}', $i, $value)]);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @test
  * it should allow overriding defaults when having blogs
  */
 public function it_should_allow_overriding_defaults_when_having_blogs(FunctionalTester $I)
 {
     $now = time() - 3600;
     Date::_injectNow($now);
     $I->haveMultisiteInDatabase();
     $overrides = ['site_id' => 2, 'domain' => 'test1.something.else', 'path' => '/other/folder', 'registered' => date(Date::DATE_FORMAT, $now), 'last_updated' => date(Date::DATE_FORMAT, $now), 'public' => 0, 'archived' => 1, 'mature' => 1, 'spam' => 1, 'deleted' => 1, 'lang_id' => 3];
     $blogId = $I->haveBlogInDatabase('test1', $overrides);
     foreach ($overrides as $key => $value) {
         $I->seeBlogInDatabase(['blog_id' => $blogId, $key => $value]);
     }
 }
Exemplo n.º 5
0
 /**
  * @test
  * it should allow overriding with n key when having many posts
  */
 public function it_should_allow_overriding_with_n_key_when_having_many_posts(FunctionalTester $I)
 {
     $table = $I->grabPostsTableName();
     Date::_injectNow(time() - 300);
     $now = Date::now();
     $gmtNow = Date::gmtNow();
     $overrides = ['post_author' => '{{n}}', 'post_date' => $now, 'post_date_gmt' => $gmtNow, 'post_content' => "Post content {{n}}", 'post_title' => 'Post title {{n}}', 'post_excerpt' => "Post excerpt {{n}}", 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_password' => '{{n}}foo{{n}}', 'post_name' => 'post-title-{{n}}', 'to_ping' => 1, 'pinged' => 1, 'post_modified' => $now, 'post_modified_gmt' => $gmtNow, 'post_content_filtered' => 'Foo bar {{n}}{{n}}', 'post_parent' => 23, 'guid' => 'http://example.com/?p={{n}}&var={{n}}', 'menu_order' => '{{n}}', 'post_type' => 'antother_type'];
     $post_ids = $I->haveManyPostsInDatabase(3, $overrides);
     foreach ($overrides as $key => $value) {
         for ($i = 0; $i < count($post_ids); $i++) {
             $post_id = $post_ids[$i];
             $processedValue = str_replace('{{n}}', $i, $value);
             $I->seeInDatabase($table, ['ID' => $post_id, $key => $processedValue]);
         }
     }
 }
Exemplo n.º 6
0
 protected static function getDefaults($id, $url)
 {
     $title = self::generateTitle($id);
     $defaults = array('post_author' => 1, 'post_date' => Date::now(), 'post_date_gmt' => Date::gmtNow(), 'post_content' => self::generateContent($id), 'post_title' => $title, 'post_excerpt' => self::generateExcerpt($id), 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'open', 'post_password' => '', 'post_name' => (new Slugifier())->slugify($title), 'to_ping' => '', 'pinged' => '', 'post_modified' => Date::now(), 'post_modified_gmt' => Date::gmtNow(), 'post_content_filtered' => '', 'post_parent' => 0, 'guid' => "{$url}/?p={$id}", 'menu_order' => 0, 'post_type' => 'post');
     return $defaults;
 }
Exemplo n.º 7
0
 /**
  * Sets up the required tables for a WordPress multisite installation if not present in the database.
  *
  * @param bool $subdomainInstall Whether this is a subdomain multisite installation or a subfolder one.
  *
  * @param bool $needHtaccess     Whether an `.htaccess` file should be put in place or not.
  * @param int  $sleep            A number in seconds the method should wait for db and files operation to complete; def. `0`.
  *
  * @return array An array containing exit information about multisite tables created/altered/updated.
  * @throws ModuleConfigException
  */
 public function haveMultisiteInDatabase($subdomainInstall = true, $needHtaccess = false, $sleep = 0)
 {
     $this->isSubdomainMultisiteInstall = $subdomainInstall;
     $this->needHtaccess = $needHtaccess;
     $this->isMultisite = true;
     $dbh = $this->driver->getDbh();
     foreach ($this->tables->multisiteTables() as $table) {
         $operation = 'create';
         $prefixedTableName = $this->grabPrefixedTableNameFor($table);
         if ($this->_seeTableInDatabase($prefixedTableName)) {
             $query = $this->tables->getAlterTableQuery($table, $this->config['tablePrefix']);
             $operation = 'alter';
         } else {
             $query = $this->tables->getCreateTableQuery($table, $this->config['tablePrefix']);
         }
         if (!empty($query)) {
             $sth = $dbh->prepare($query);
             $this->debugSection('Query', $sth->queryString);
             $out[$table] = ['operation' => $operation, 'exit' => $sth->execute([])];
         } else {
             $out[$table] = ['operation' => $operation, 'exit' => false];
         }
     }
     $domain = $this->getSiteDomain();
     if (!$this->countInDatabase($this->grabSiteTableName(), ['domain' => $domain])) {
         $this->haveInDatabase($this->grabSiteTableName(), ['domain' => $domain, 'path' => '/']);
     }
     if (!$this->countInDatabase($this->grabBlogsTableName(), ['blog_id' => 1])) {
         $this->query("ALTER TABLE {$this->grabBlogsTableName()} AUTO_INCREMENT=1");
         $mainBlogData = ['site_id' => 1, 'domain' => $domain, 'path' => '/', 'registered' => Date::now(), 'last_updated' => Date::now(), 'public' => 1];
         $this->haveInDatabase($this->grabBlogsTableName(), $mainBlogData);
     }
     if ($this->needHtaccess) {
         $this->replaceFiles();
     }
     if ($sleep) {
         sleep($sleep);
     }
     return $out;
 }