diff options
-rw-r--r-- | includes/concert.php | 9 | ||||
-rw-r--r-- | tests/ConcertTest.php | 23 |
2 files changed, 29 insertions, 3 deletions
diff --git a/includes/concert.php b/includes/concert.php index 050c924..455bc82 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -171,14 +171,17 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function find_concerts_in(string $city) : array + public static function find_concerts_in(?string $city = null) : array { global $wpdb; $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' . 'FROM wpg_concerts ' - . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' - . 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); + . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '; + + if ( $city ) { + $query .= 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); + } $results = $wpdb->get_results($query); diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index 96fc72b..ec7bc13 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -168,4 +168,27 @@ final class ConcertTest extends WP_UnitTestCase $this->assertEquals("Revolver", $gig->venue()->name()); } } + + public function testFetchAllConcerts() : void + { + $venue1 = GiglogAdmin_Venue::create("Svene Bedehus", "Svene"); + $venue2 = GiglogAdmin_Venue::create("Rockefeller Music Hall", "Oslo"); + $venue3 = GiglogAdmin_Venue::create("Meieriet", "Sogndal"); + + for ($i = 0; $i < 4; $i++) { + GiglogAdmin_Concert::create('Concert ' . $i, $venue1->id(), '', '', ''); + } + + for ($i = 4; $i < 6; $i++) { + GiglogAdmin_Concert::create('Concert ' . $i, $venue2->id(), '', '', ''); + } + + for ($i = 6; $i < 11; $i++) { + GiglogAdmin_Concert::create('Concert ' . $i, $venue3->id(), '', '', ''); + } + + $gigs = GiglogAdmin_Concert::find_concerts_in(); + + $this->assertEquals(11, count($gigs)); + } } |