Skip to content

Commit

Permalink
Merge pull request #895 from GatherPress/mauteri-unit-test-2
Browse files Browse the repository at this point in the history
Added new unit tests, small code changes.
  • Loading branch information
mauteri authored Sep 20, 2024
2 parents 963597d + b7cd7f2 commit 010d16b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion includes/core/classes/class-venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ public function register_post_type(): void {
public static function get_localized_post_type_slug(): string {
$switched_locale = switch_to_locale( get_locale() );
$slug = _x( 'venue', 'Post Type Slug', 'gatherpress' );
$slug = sanitize_title( $slug, '', 'save' );
$slug = sanitize_title( $slug );

if ( $switched_locale ) {
restore_previous_locale();
}

return $slug;
}

Expand Down
19 changes: 19 additions & 0 deletions test/unit/php/includes/core/classes/class-test-rsvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GatherPress\Core\Rsvp;
use PMC\Unit_Test\Base;
use PMC\Unit_Test\Utility;
use WP_Error;

/**
* Class Test_Rsvp.
Expand Down Expand Up @@ -109,6 +110,24 @@ public function test_save(): void {
$rsvp = new Rsvp( $post->ID );
$user_1_id = $this->factory->user->create();
$this->assertSame( 2, $rsvp->save( $user_1_id, 'attending', 0, 3 )['guests'], 'Failed to assert that user 1 can only bring 2 guests at most.' );

// Simulate error saving RSVP.
add_filter( 'query', '__return_false' );

$user_id = $this->factory->user->create();
$result = $rsvp->save( $user_id, 'attending' );
$expected = array(
'post_id' => 0,
'user_id' => 0,
'timestamp' => '0000-00-00 00:00:00',
'status' => 'no_status',
'guests' => 0,
'anonymous' => 0,
);

$this->assertEquals( $expected, $result );

remove_filter( 'query', '__return_false' );
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/unit/php/includes/core/classes/class-test-venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ public function test_register_post_type(): void {
$this->assertTrue( post_type_exists( Venue::POST_TYPE ), 'Failed to assert that post type exists.' );
}

/**
* Coverage for get_localized_post_type_slug method.
*
* @covers ::get_localized_post_type_slug
*
* @return void
*/
public function test_get_localized_post_type_slug(): void {
$this->assertSame(
'venue',
Venue::get_localized_post_type_slug(),
'Failed to assert that post type slug is same.'
);
}

/**
* Coverage for register_post_meta method.
*
Expand Down

0 comments on commit 010d16b

Please sign in to comment.