From 1fa1654de0527440d057c5ed05891bed6cc0b69c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 18 Jun 2022 18:18:23 +0200 Subject: Fix concert tests. --- includes/concert.php | 8 ++++---- tests/ConcertTest.php | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/includes/concert.php b/includes/concert.php index 8aec96a..fed48a5 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -127,7 +127,7 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { $concert->save(); - return $concert; + return self::get( $concert->id() ); } } @@ -222,16 +222,16 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { case 'month': case 'venue': case 'city': - array_push( $where, $wpdb->prepare( '%s=%s', $keymap[ $key ], $value ) ); + array_push( $where, $keymap[ $key ] . $wpdb->prepare( '=%s', $value ) ); break; case 'id': case 'venue_id': - array_push( $where, $wpdb->prepare( '%s=%d', $keymap[ $key ], $value ) ); + array_push( $where, $keymap[ $key ] . $wpdb->prepare( '=%d', $value ) ); break; case 'currentuser': - array_push( $where, $wpdb->prepare( '%s like %s', $keymap[ $key ], esc_like( $value ) ) ); + array_push( $where, $keymap[ $key ] . $wpdb->prepare( ' like %s', esc_like( $value ) ) ); break; case 'offset': diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index dc2a712..d84e6a9 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -38,7 +38,7 @@ final class ConcertTest extends WP_UnitTestCase $created_venues[] = GiglogAdmin_Venue::find_or_create($venue[0], $venue[1]); } - $today = date("Y-m-d"); + $today = new DateTime(); foreach (self::CONCERTS as $concert) { for ($i = 0; $i < $concert[2]; $i++) { @@ -49,10 +49,13 @@ final class ConcertTest extends WP_UnitTestCase $concert_name = $concert[0]; } + $offset = rand(1, 13); + $concert_date = $today->modify( "+$offset days" ); + self::$concerts[] = GiglogAdmin_Concert::create( $concert_name, $created_venues[$concert[1]]->id(), - $today, + $concert_date->format( 'Y-m-d' ), "https://example.com/tickets/42", "https://example.com/events/93"); } @@ -82,30 +85,30 @@ final class ConcertTest extends WP_UnitTestCase { $this->expectException(GiglogAdmin_DuplicateConcertException::class); - $venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere"); - $today = date("Y-m-d"); + $origin = self::$concerts[0]; $new = GiglogAdmin_Concert::create( - "a concert", - $venue->id(), - $today, - "https://example.com/tickets/42", - "https://example.com/events/93"); + $origin->cname(), + $origin->venue()->id(), + $origin->cdate(), + $origin->tickets(), + $origin->eventlink() + ); } public function testCreateExistingConcertVariableCase() : void { $this->expectException(GiglogAdmin_DuplicateConcertException::class); - $venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere"); - $today = date("Y-m-d"); + $origin = self::$concerts[0]; $new = GiglogAdmin_Concert::create( - "a CoNceRt", - $venue->id(), - $today, - "https://example.com/tickets/42", - "https://example.com/events/93"); + strtoupper( $origin->cname() ), + $origin->venue()->id(), + $origin->cdate(), + $origin->tickets(), + $origin->eventlink() + ); } public function testGetConcertByIdReturnsFullConcertObject() : void @@ -201,17 +204,17 @@ final class ConcertTest extends WP_UnitTestCase public function testFetchConcertByNameVenueAndDate() : void { + $origin = self::$concerts[0]; + $gigs = GiglogAdmin_Concert::find_concerts([ - 'name' => 'a concert', - 'venue' => 'a venue', - 'date' => date('Y-m-d') + 'name' => $origin->cname(), + 'venue' => $origin->venue()->name(), + 'date' => $origin->cdate(), ]); $this->assertEquals(1, count($gigs)); $gig = array_shift($gigs); - $this->assertEquals('a concert', $gig->cname()); - $this->assertEquals('a venue', $gig->venue()->name()); - $this->assertEquals(date('Y-m-d'), explode(' ', $gig->cdate())[0]); + $this->assertEquals($origin, $gig); } } -- cgit v1.2.3