summaryrefslogtreecommitdiffstats
path: root/tests/ConcertTest.php
blob: dc828393d9877739d1e37bd6e66e498dd5e2e792 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php declare(strict_types=1);
// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
//
// 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()->id());
        $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->assertNull($new);
    }

    public function testCreateExistingConcertVariableCase() : void
    {
        $venue = GiglogAdmin_Venue::create("a venue");
        $today = date("Y-m-d");

        GiglogAdmin_Concert::create(
            "a concert123",
            $venue->id(),
            $today,
            "https://example.com/tickets/42",
            "https://example.com/events/93");

        $new = GiglogAdmin_Concert::create(
            "a CoNceRt123",
            $venue->id(),
            $today,
            "https://example.com/tickets/42",
            "https://example.com/events/93");

        $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());
    }

    public function testOnlyFetchConcertsFromGivenCity() : 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_in_svene = GiglogAdmin_Concert::find_concerts_in("Svene");

        $this->assertEquals(4, count($gigs_in_svene));
        while ($gig = array_pop($gigs_in_svene)) {
            $this->assertEquals("Svene", $gig->venue()->city());
        }


        $gigs_in_oslo = GiglogAdmin_Concert::find_concerts_in("Oslo");

        $this->assertEquals(2, count($gigs_in_oslo));
        while ($gig = array_pop($gigs_in_oslo)) {
            $this->assertEquals("Oslo", $gig->venue()->city());
        }

        $gigs_in_sogndal = GiglogAdmin_Concert::find_concerts_in("Sogndal");

        $this->assertEquals(5, count($gigs_in_sogndal));
        while ($gig = array_pop($gigs_in_sogndal)) {
            $this->assertEquals("Sogndal", $gig->venue()->city());
        }
    }
}