Skip to content

Commit

Permalink
move transition page status test to page types test class
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Nov 8, 2024
1 parent 5474528 commit 05c917c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 70 deletions.
File renamed without changes.
67 changes: 0 additions & 67 deletions tests/phpunit/test-class-page-transition.php

This file was deleted.

44 changes: 41 additions & 3 deletions tests/phpunit/test-class-page-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public static function setUpBeforeClass(): void {
'post_status' => 'publish',
]
);

// Assign the post to the "homepage" page type.
\progress_planner()->get_page_types()->set_page_type_by_slug( self::$homepage_post_id, 'homepage' );
}

/**
Expand Down Expand Up @@ -116,6 +113,10 @@ function ( $page_type ) use ( $lesson ) {
* @return void
*/
public function test_get_posts_by_type() {

// Assign the post to the "homepage" page type.
\progress_planner()->get_page_types()->set_page_type_by_slug( self::$homepage_post_id, 'homepage' );

$posts = \progress_planner()->get_page_types()->get_posts_by_type( 'page', 'homepage' );
$this->assertEquals( self::$homepage_post_id, $posts[0]->ID );
}
Expand Down Expand Up @@ -151,4 +152,41 @@ public function test_post_updated() {
*/
public function test_assign_child_pages() {
}

/**
* Test if the transition of a page status updates the options.
*
* @return void
*/
public function test_transition_post_status_updates_options() {

// Check if the options are set to default values.
$this->assertEquals( 0, get_option( 'page_on_front' ) );
$this->assertEquals( 'posts', get_option( 'show_on_front' ) );

// Update homepage page to draft.
wp_update_post(
[
'ID' => self::$homepage_post_id,
'post_status' => 'draft',
]
);

$term = \get_term_by( 'slug', 'homepage', \progress_planner()->get_page_types()::TAXONOMY_NAME );

// Directly assign the term to the page, without using the set_page_type_by_slug method.
\wp_set_object_terms( self::$homepage_post_id, $term->term_id, \progress_planner()->get_page_types()::TAXONOMY_NAME );

// Update the page status to publish.
wp_update_post(
[
'ID' => self::$homepage_post_id,
'post_status' => 'publish',
]
);

// Check if the options are updated.
$this->assertEquals( self::$homepage_post_id, get_option( 'page_on_front' ) );
$this->assertEquals( 'page', get_option( 'show_on_front' ) );
}
}

0 comments on commit 05c917c

Please sign in to comment.