Skip to content

Commit

Permalink
NEW assertions for adjust_event_sql() method
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Oct 1, 2024
1 parent 13992c8 commit d69a5bb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions test/unit/php/includes/core/classes/class-test-event-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,39 @@ public function test_adjust_event_sql(): void {
$table = sprintf( Event::TABLE_FORMAT, $wpdb->prefix, Event::POST_TYPE );
$retval = $instance->adjust_event_sql( array(), 'all', 'DESC' );

$this->assertStringContainsString( 'DESC', $retval['orderby'] );
$this->assertStringContainsString( '.datetime_start_gmt DESC', $retval['orderby'] );
$this->assertEmpty( $retval['where'] );

$retval = $instance->adjust_event_sql( array(), 'past', 'desc' ); // inclusive will be TRUE by default.

$this->assertStringContainsString( 'DESC', $retval['orderby'] );
$this->assertStringContainsString( '.datetime_start_gmt DESC', $retval['orderby'] );
$this->assertStringContainsString( "AND `{$table}`.`datetime_start_gmt` <", $retval['where'] );

$retval = $instance->adjust_event_sql( array(), 'past', 'desc', 'datetime', false );

$this->assertStringContainsString( 'DESC', $retval['orderby'] );
$this->assertStringContainsString( '.datetime_start_gmt DESC', $retval['orderby'] );
$this->assertStringContainsString( "AND `{$table}`.`datetime_end_gmt` <", $retval['where'] );

$retval = $instance->adjust_event_sql( array(), 'upcoming', 'ASC' );

$this->assertStringContainsString( 'ASC', $retval['orderby'] );
$this->assertStringContainsString( '.datetime_start_gmt ASC', $retval['orderby'] );
$this->assertStringContainsString( "AND `{$table}`.`datetime_end_gmt` >=", $retval['where'] );

$retval = $instance->adjust_event_sql( array(), 'past', 'desc', 'id', false );

$this->assertStringContainsString( '.ID DESC', $retval['orderby'] );

$retval = $instance->adjust_event_sql( array(), 'past', 'desc', 'title', false );

$this->assertStringContainsString( '.post_name DESC', $retval['orderby'] );

$retval = $instance->adjust_event_sql( array(), 'past', 'desc', 'modified', false );

$this->assertStringContainsString( '.post_modified_gmt DESC', $retval['orderby'] );

$retval = $instance->adjust_event_sql( array(), 'upcoming', 'desc', 'rand', false );

$this->assertStringContainsString( 'RAND()', $retval['orderby'] );
}

/**
Expand Down

0 comments on commit d69a5bb

Please sign in to comment.