From d116e23de0efcd528226acf6dbe4c7cbc5c5698b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 May 2021 15:42:58 +0200 Subject: Include info from venue in concerts. This makes the concert a full object containing all relevant info, while we can still segment the data in the db. Instead of this: $concert = GiglogAdmin_Concert::get($concert_id); $venue = GiglogAdmin_Venue::get($concert->venue()); echo "{$concert->name()} @ {$venue->name()} : {$concert->cdate()}" You can now do: $concert = GiglogAdmin_Concert::get($concert_id); echo "{$concert->name()} @ {$concert->venue()->name()} : {$concert->cdate()}" And yeah, renamed Concert::find_cid() to Concert::get() and changed it's semantics somewhat. It now either returns the given concert if it exists, or NULL if it does not. Simpler function; simpler to use. --- tests/ConcertTest.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index 6d14b68..0517ad8 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -19,7 +19,7 @@ final class ConcertTest extends WP_UnitTestCase "https://example.com/events/93"); $this->assertEquals("a concert", $concert->cname()); - $this->assertEquals($venue->id(), $concert->venue()); + $this->assertEquals($venue->id(), $concert->venue()->id()); $this->assertEquals($today, $concert->cdate()); $this->assertEquals("https://example.com/tickets/42", $concert->tickets()); $this->assertEquals("https://example.com/events/93", $concert->eventlink()); @@ -68,4 +68,23 @@ final class ConcertTest extends WP_UnitTestCase $this->assertNull($new); } + + public function testGetConcertByIdReturnsFullConcertObject() : void + { + $venue = GiglogAdmin_Venue::create("a venue"); + $today = date("Y-m-d"); + + $gig = GiglogAdmin_Concert::create( + "a concert123", + $venue->id(), + $today, + "https://example.com/tickets/42", + "https://example.com/events/93"); + + $fetched_gig = GiglogAdmin_Concert::get($gig->id()); + + $this->assertEquals($gig->id(), $fetched_gig->id()); + $this->assertEquals($gig->cname(), $fetched_gig->cname()); + $this->assertEquals($venue->id(), $fetched_gig->venue()->id()); + } } -- cgit v1.2.3