-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest-cli.php
More file actions
57 lines (47 loc) · 1.54 KB
/
test-cli.php
File metadata and controls
57 lines (47 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Plugin CLI command tests.
*
* @package authorship
*/
declare( strict_types=1 );
namespace Authorship\Tests;
use Authorship\CLI;
use const Authorship\POSTS_PARAM;
use const Authorship\TAXONOMY;
class TestCLI extends TestCase {
public function set_up() {
parent::set_up();
require_once dirname( __DIR__, 2 ) . '/inc/cli/namespace.php';
require_once dirname( __DIR__, 2 ) . '/inc/cli/class-migrate-command.php';
CLI\bootstrap();
}
public function testMigrateWpAuthorsPagination() : void {
$factory = self::factory()->post;
$posts = [];
for ( $i = 0; $i < 200; $i++ ) {
$posts[] = $factory->create_and_get( [
'post_author' => self::$users['admin']->ID,
POSTS_PARAM => [
self::$users['editor']->ID,
],
] );
}
$paged_post = $posts[100]; // Any post from second page of results.
$authorship_authors = \Authorship\get_authors( $paged_post );
// Asset initial authorship authors set correctly.
$this->assertCount( 1, $authorship_authors );
$this->assertSame( self::$users['editor']->ID, $authorship_authors[0]->ID );
// Migrate, overwriting authorship data with WP Author data.
$command = new CLI\Migrate_Command;
$command->wp_authors( [], [
'dry-run' => false,
'overwrite' => true,
'post-type' => 'post', // Must set default value manually.
] );
// Verify author data migrated correctly.
$authorship_authors = \Authorship\get_authors( $paged_post->ID );
$this->assertCount( 1, $authorship_authors );
$this->assertSame( self::$users['admin']->ID, $authorship_authors[0]->ID );
}
}