summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-23 19:42:55 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-04-23 19:42:55 +0200
commit42d033b154ae26cb0ae259de415ee507b98186b5 (patch)
treef3ceff138386f1f0688a413dbb5c8fb99a8d33f1
parent04f3974a6b8bb327500a34369857c2975a326a00 (diff)
parentce5ed26cadf5f60e2b07d6a355f64d3357bf5397 (diff)
downloadgigologadmin-42d033b154ae26cb0ae259de415ee507b98186b5.tar.gz
gigologadmin-42d033b154ae26cb0ae259de415ee507b98186b5.tar.bz2
gigologadmin-42d033b154ae26cb0ae259de415ee507b98186b5.zip
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
-rw-r--r--composer.json2
-rw-r--r--includes/admin/views/giglog_admin_page.php19
-rw-r--r--includes/concert.php8
-rw-r--r--tests/ConcertTest.php49
4 files changed, 66 insertions, 12 deletions
diff --git a/composer.json b/composer.json
index fb612a3..83619c6 100644
--- a/composer.json
+++ b/composer.json
@@ -17,6 +17,6 @@
"wp-phpunit/wp-phpunit": "^5.7"
},
"scripts": {
- "test": "./run-tests"
+ "test": "npm run wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/giglogadmin/phpunit.xml'"
}
}
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index f344b0d..870e361 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -329,17 +329,20 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {
//header("Refresh: 1; URL=$url2"); //reload page
}
- if(isset($_POST['newconcert']))
- {
- IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl']))
+ if(isset($_POST['newconcert'])) {
+ if (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) {
echo '<script language="javascript">alert("You are missing a value, concert was not created"); </script>';
- else
- {
- $ret = GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']);
- if ($ret!='dup') echo '<script language="javascript">alert("Yey, concert created"); </script>';
- else echo '<script language="javascript">alert("Nay, concert was duplicated"); </script>';
+ }
+ else {
+ if (GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl'])) {
+ echo '<script language="javascript">alert("Yey, concert created"); </script>';
+ }
+ else {
+ echo '<script language="javascript">alert("Nay, concert was duplicated"); </script>';
+ }
}
}
+
if(isset($_POST['editconcert']))
{
IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl']))
diff --git a/includes/concert.php b/includes/concert.php
index 37e8fe3..22fc13d 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -51,7 +51,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
}
}
- static function check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink)
+ private static function check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink)
{
global $wpdb;
@@ -62,8 +62,10 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
return ('new');
}
+
public static function create($cname, $venue, $cdate, $ticketlink, $eventlink)
- { $c = GiglogAdmin_Concert::check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink);
+ {
+ $c = GiglogAdmin_Concert::check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink);
if ($c=='new')
{
$attrs = new stdClass();
@@ -102,7 +104,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
. ' CONCERT NAME ' . $cname
. ', VENUE ID ' . $venue
. ', CONCERTDATE ' . $cdate);
- return('dup');
+ return NULL;
}
}
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
new file mode 100644
index 0000000..82bdc9a
--- /dev/null
+++ b/tests/ConcertTest.php
@@ -0,0 +1,49 @@
+<?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());
+ $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);
+ }
+}