Skip to content

Commit

Permalink
feat(starter-content): e2e improvements; removal CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Nov 15, 2024
1 parent 340fcb5 commit 35431ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
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 @@ -127,8 +127,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
7 changes: 4 additions & 3 deletions includes/starter_content/class-starter-content-generated.php
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

0 comments on commit 35431ac

Please sign in to comment.