From 6076d8ae50cc43b7722fcc63e6eba38117f91206 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 22 Apr 2021 23:13:15 +0200 Subject: Add some tests for Concert class. --- tests/ConcertTest.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/ConcertTest.php (limited to 'tests') diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php new file mode 100644 index 0000000..19267ee --- /dev/null +++ b/tests/ConcertTest.php @@ -0,0 +1,49 @@ + +// SPDX-FileCopyrightText: 2021 Harald Eilertsen +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +final class ConcertTest extends WP_UnitTestCase +{ + public function testCreateConcert() : void + { + $venue = GiglogAdmin_Venue::create("a venue"); + $today = date("Y-m-d"); + + $concert = GiglogAdmin_Concert::create( + "a concert", + $venue->id(), + $today, + "https://example.com/tickets/42", + "https://example.com/events/93"); + + $this->assertEquals("a concert", $concert->cname()); + $this->assertEquals($venue->id(), $concert->venue()); + $this->assertEquals($today, $concert->cdate()); + $this->assertEquals("https://example.com/tickets/42", $concert->tickets()); + $this->assertEquals("https://example.com/events/93", $concert->eventlink()); + } + + public function testCreateExistingConcert() : void + { + $venue = GiglogAdmin_Venue::create("a venue"); + $today = date("Y-m-d"); + + GiglogAdmin_Concert::create( + "a concert", + $venue->id(), + $today, + "https://example.com/tickets/42", + "https://example.com/events/93"); + + $new = GiglogAdmin_Concert::create( + "a concert", + $venue->id(), + $today, + "https://example.com/tickets/42", + "https://example.com/events/93"); + + $this->assertEquals("dup", $new); + } +} -- cgit v1.2.3 From a5ea57f20c1beb80f327fea5233605400462156c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 22 Apr 2021 23:15:22 +0200 Subject: Concert::create return NULL if concert already exist. We probably need some better error handling here. There's a myriad of reasons why this call could fail, and we might need to communicate the failure reason somewhere. --- tests/ConcertTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index 19267ee..82bdc9a 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -44,6 +44,6 @@ final class ConcertTest extends WP_UnitTestCase "https://example.com/tickets/42", "https://example.com/events/93"); - $this->assertEquals("dup", $new); + $this->assertNull($new); } } -- cgit v1.2.3