summaryrefslogtreecommitdiffstats
path: root/tests/ConcertTest.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-06-27 15:18:39 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-06-27 15:18:39 +0200
commit06ec509ce40d3ca04c770e542f57891a3540c7cd (patch)
treed0f0b7442408dbaf81e1e8f242ce7aee95cc71fa /tests/ConcertTest.php
parentf3c31f5e3b6f57bbc887e6b4e435e5202eb41208 (diff)
downloadgigologadmin-06ec509ce40d3ca04c770e542f57891a3540c7cd.tar.gz
gigologadmin-06ec509ce40d3ca04c770e542f57891a3540c7cd.tar.bz2
gigologadmin-06ec509ce40d3ca04c770e542f57891a3540c7cd.zip
Refactor ConcertTest some more.
Create more of the concerts used by tests into the wpSetupBeforeClass hook.
Diffstat (limited to 'tests/ConcertTest.php')
-rw-r--r--tests/ConcertTest.php83
1 files changed, 25 insertions, 58 deletions
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
index bde488b..77b1ed3 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -16,7 +16,12 @@ final class ConcertTest extends WP_UnitTestCase
];
const CONCERTS = [
- [ "a concert", 0 ],
+ [ "a concert", 0, 1 ],
+ [ "Concert in Svene #", 1, 4 ],
+ [ "Concert at Rockefeller #", 2, 2 ],
+ [ "Concert at Sentrum Scene #", 3, 4 ],
+ [ "Concert at Revolver #", 4, 5 ],
+ [ "Concert at Meieriet #", 5, 5 ],
];
private static $concerts = [];
@@ -36,12 +41,21 @@ final class ConcertTest extends WP_UnitTestCase
$today = date("Y-m-d");
foreach (self::CONCERTS as $concert) {
- self::$concerts[] = GiglogAdmin_Concert::create(
- $concert[0],
- $created_venues[$concert[1]]->id(),
- $today,
- "https://example.com/tickets/42",
- "https://example.com/events/93");
+ for ($i = 0; $i < $concert[2]; $i++) {
+ if ($concert[2] > 1) {
+ $concert_name = $concert[0] . ($i + 1);
+ }
+ else {
+ $concert_name = $concert[0];
+ }
+
+ self::$concerts[] = GiglogAdmin_Concert::create(
+ $concert_name,
+ $created_venues[$concert[1]]->id(),
+ $today,
+ "https://example.com/tickets/42",
+ "https://example.com/events/93");
+ }
}
}
@@ -121,22 +135,6 @@ final class ConcertTest extends WP_UnitTestCase
public function testOnlyFetchConcertsFromGivenCity() : void
{
- $venue1 = GiglogAdmin_Venue::find_or_create("Svene Bedehus", "Svene");
- $venue2 = GiglogAdmin_Venue::find_or_create("Rockefeller Music Hall", "Oslo");
- $venue3 = GiglogAdmin_Venue::find_or_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_in_svene = GiglogAdmin_Concert::find_concerts([ "city" => "Svene"]);
$this->assertEquals(4, count($gigs_in_svene));
@@ -144,10 +142,9 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertEquals("Svene", $gig->venue()->city());
}
-
$gigs_in_oslo = GiglogAdmin_Concert::find_concerts(["city" => "Oslo"]);
- $this->assertEquals(2, count($gigs_in_oslo));
+ $this->assertEquals(11, count($gigs_in_oslo));
while ($gig = array_pop($gigs_in_oslo)) {
$this->assertEquals("Oslo", $gig->venue()->city());
}
@@ -163,21 +160,6 @@ final class ConcertTest extends WP_UnitTestCase
public function testOnlyFetchConcertsAtGivenVenue() : void
{
$venue1 = GiglogAdmin_Venue::find_or_create("Sentrum Scene", "Oslo");
- $venue2 = GiglogAdmin_Venue::find_or_create("Rockefeller Music Hall", "Oslo");
- $venue3 = GiglogAdmin_Venue::find_or_create("Revolver", "Oslo");
-
- 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_at_ss = GiglogAdmin_Concert::find_concerts(["venue_id" => $venue1->id()]);
$this->assertEquals(4, count($gigs_at_ss));
@@ -185,6 +167,7 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertEquals("Sentrum Scene", $gig->venue()->name());
}
+ $venue2 = GiglogAdmin_Venue::find_or_create("Rockefeller Music Hall", "Oslo");
$gigs_at_rmh = GiglogAdmin_Concert::find_concerts(["venue_id" => $venue2->id()]);
$this->assertEquals(2, count($gigs_at_rmh));
@@ -192,6 +175,7 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertEquals("Rockefeller Music Hall", $gig->venue()->name());
}
+ $venue3 = GiglogAdmin_Venue::find_or_create("Revolver", "Oslo");
$gigs_at_r = GiglogAdmin_Concert::find_concerts(["venue_id" => $venue3->id()]);
$this->assertEquals(5, count($gigs_at_r));
@@ -202,24 +186,7 @@ final class ConcertTest extends WP_UnitTestCase
public function testFetchAllConcerts() : void
{
- $venue1 = GiglogAdmin_Venue::find_or_create("Svene Bedehus", "Svene");
- $venue2 = GiglogAdmin_Venue::find_or_create("Rockefeller Music Hall", "Oslo");
- $venue3 = GiglogAdmin_Venue::find_or_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();
-
- $this->assertEquals(count(self::$concerts) + 11, count($gigs));
+ $this->assertEquals(count(self::$concerts), count($gigs));
}
}