summaryrefslogtreecommitdiffstats
path: root/tests/VenueTest.php
blob: a49301bb170689f14da9d3eaeae78020f71bae00 (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
// 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

<?php
declare(strict_types=1);

use PHPUnit\Framework\TestCase;

require 'tests/stubs/wpdb_stub.php';
require 'includes/venue.php';

final class VenueTest extends TestCase
{
    public function testCreatingVenueWithName(): void
    {
        $venue = GiglogAdmin_Venue::create("Svene Samfunns- og Bedehus");
        $this->assertEquals("Svene Samfunns- og Bedehus", $venue->name());
        $this->assertEquals(1, $venue->id());
    }

    public function testFindOrCreateNonExistingVenue() : void
    {
        $venue = GiglogAdmin_Venue::find_or_create("Svene Samfunns- og Bedehus");
        $this->assertEquals("Svene Samfunns- og Bedehus", $venue->name());
        $this->assertEquals(1, $venue->id());
    }

    public function testFindOrCreateExistingVenue() : void
    {
        global $wpdb;

        $v = new stdClass();
        $v->id = 42;
        $v->wpgvenue_name = 'Slarkhaillen';
        $v->wpgvenue_city = 'Ofoten';
        $v->wpgvenue_address = 'Baillsvingen 4';
        $v->wpgvenue_webpage = 'https://slarkhaillen.no';

        $wpdb = $this->createStub(wpdb::class);
        $wpdb->method('get_results')->willReturn(array($v));
        $venue = GiglogAdmin_Venue::find_or_create("Slarkhaillen");

        $this->assertEquals(42, $venue->id());
        $this->assertEquals($v->wpgvenue_name, $venue->name());
    }

    public function testFindAllVenuesInCity() : void
    {
        global $wpdb;

        $results = array();
        for ($i = 0; $i < 3; $i++) {
            $results[$i] = new stdClass();
            $results[$i]->id = 42 + $i;
            $results[$i]->wpgvenue_name = "Venue #" . $i;
            $results[$i]->wpgvenue_city = "Osaka";
        }

        $wpdb = $this->createStub(wpdb::class);
        $wpdb->method('prepare')->willReturn("prepared");
        $wpdb->method('get_results')->willReturn($results);

        $venues = GiglogAdmin_Venue::venues_in_city("Osaka");

        for ($i = 0; $i < 3; $i++) {
            $this->assertEquals("Osaka", $venues[$i]->city());
            $this->assertEquals("Venue #" . $i, $venues[$i]->name());
            $this->assertEquals(42 + $i, $venues[$i]->id());
        }
    }

    public function testFindAllVenues() : void
    {
        global $wpdb;

        $results = array();
        for ($i = 0; $i < 3; $i++) {
            $results[$i] = new stdClass();
            $results[$i]->id = 42 + $i;
            $results[$i]->wpgvenue_name = "Venue #" . $i;
            $results[$i]->wpgvenue_city = "City #" . $i;
        }

        $wpdb = $this->createStub(wpdb::class);
        $wpdb->method('get_results')->willReturn($results);

        $venues = GiglogAdmin_Venue::all_venues();

        for ($i = 0; $i < 3; $i++) {
            $this->assertEquals("City #" . $i, $venues[$i]->city());
            $this->assertEquals("Venue #" . $i, $venues[$i]->name());
            $this->assertEquals(42 + $i, $venues[$i]->id());
        }
    }
}