Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(starter-content): e2e improvements; removal CLI command #3498

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/class-starter-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@ public static function upload_logo() {
* @return bool E2E testing environment?
*/
public static function is_e2e() {
return defined( 'WP_NEWSPACK_IS_E2E' ) && WP_NEWSPACK_IS_E2E;
return defined( 'NEWSPACK_IS_E2E' ) && NEWSPACK_IS_E2E;
}
}
1 change: 1 addition & 0 deletions includes/cli/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function register_comands() {
}

WP_CLI::add_command( 'newspack setup', 'Newspack\CLI\Setup' );
WP_CLI::add_command( 'newspack remove-starter-content', [ 'Newspack\Starter_Content','remove_starter_content' ] );

// Utility commands for managing RAS data via WP CLI.
WP_CLI::add_command(
Expand Down
5 changes: 3 additions & 2 deletions includes/cli/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ private function initial_content( $assoc_args ) {
return WP_CLI::error( $response->data['message'] );
}

WP_CLI::line( 'Creating Posts' );
for ( $i = 0; $i < 40; $i++ ) {
$posts_count = \Newspack\Starter_Content::is_e2e() ? 10 : 40;
WP_CLI::line( sprintf( 'Creating %d posts', $posts_count ) );
for ( $i = 0; $i < $posts_count; $i++ ) {
$request = new WP_REST_Request( 'POST', '/' . NEWSPACK_API_NAMESPACE . '/wizard/newspack-setup-wizard/starter-content/post/' . $i );
$response = rest_do_request( $request );
echo '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function create_post( $post_index ) {
}
$page_templates = [ '', 'single-feature.php' ];
$paragraphs = explode( PHP_EOL, self::get_lipsum( 'paras', 5 ) );
$title = self::generate_title();
$title = self::generate_title( $post_index );
$post_data = [
'post_title' => $title,
'post_name' => sanitize_title_with_dashes( $title, '', 'save' ),
Expand Down Expand Up @@ -247,11 +247,12 @@ public static function create_homepage() {
/**
* Generate a post title
*
* @param int $post_index The index of the created post.
* @return string The title.
*/
public static function generate_title() {
public static function generate_title( $post_index = 0 ) {
if ( Starter_Content::is_e2e() ) {
return file_get_contents( NEWSPACK_ABSPATH . 'includes/raw_assets/markup/title.txt' );
return $post_index . ' ' . file_get_contents( NEWSPACK_ABSPATH . 'includes/raw_assets/markup/title.txt' );
}
$title = self::get_lipsum( 'words', wp_rand( 7, 14 ) );
$title = ucfirst( strtolower( str_replace( '.', '', $title ) ) ); // Remove periods, convert to sentence case.
Expand Down