summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-06-27 15:23:35 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-06-27 15:23:35 +0200
commit184f1e3f971423fad351de2b2fbde6f436e6d9ce (patch)
treebd531c064cbf53613455264dc08d5d4b7cf56999
parentf1fced27a60d656c70c0c060f894679773158f9c (diff)
downloadgigologadmin-184f1e3f971423fad351de2b2fbde6f436e6d9ce.tar.gz
gigologadmin-184f1e3f971423fad351de2b2fbde6f436e6d9ce.tar.bz2
gigologadmin-184f1e3f971423fad351de2b2fbde6f436e6d9ce.zip
Remove Band class and tests.
-rw-r--r--includes/band.php151
-rw-r--r--tests/BandTest.php69
2 files changed, 0 insertions, 220 deletions
diff --git a/includes/band.php b/includes/band.php
deleted file mode 100644
index 3460acb..0000000
--- a/includes/band.php
+++ /dev/null
@@ -1,151 +0,0 @@
-<?php
-
-// 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
-
-if ( !class_exists('GiglogAdmin_Band') ) {
- class GiglogAdmin_Band
- {
- private $id;
- private $bandname;
- private $country;
-
- /*
- * Constructs a new band object from an array of attributes.
- * The attributes are expected to be named as in the database,
- * so this constructor can be used to construct the object
- * directly from the database row.
- */
- public function __construct($attrs = [])
- {
- $this->id = isset($attrs->id) ? $attrs->id : NULL;
- $this->bandname = isset($attrs->wpgband_name) ? $attrs->wpgband_name : NULL;
- $this->country = isset($attrs->wpgband_country) ? $attrs->wpgband_country : 'NO';
- }
-
- static function create($bandname, $country = 'NO'): self
- {
- $band = GiglogAdmin_Band::find($bandname, $country);
-
- if ( ! $band ) {
- $band = new GiglogAdmin_Band((object) [
- 'wpgband_name' => $bandname,
- 'wpgband_country' => $country,
- ]);
-
- $band->save();
-
- error_log( 'NEW BAND ADDED: '
- . ' ID: ' . $band->id()
- . ' BAND NAME ' . $band->bandname()
- . ', COUNTRY ' . $band->country());
- }
-
- return $band;
- }
-
- static function find($name, $country): ?self
- {
- global $wpdb;
-
- $q = 'SELECT * FROM wpg_bands '
- . 'WHERE upper(wpgband_name)="' . $name
- . '" and wpgband_country = "' . $country.'"';
-
- $results = $wpdb->get_results($q);
-
- if ($results) {
- return new GiglogAdmin_Band($results[0]);
- }
- else {
- return NULL;
- }
- }
-
-
- static function all_bands()
- {
- global $wpdb;
-
- $results = $wpdb->get_results("select id, wpgband_name as vname from wpg_bands order by wpgband_name");
-
- return ($results);
- }
-
- static function all_countries()
- {
- global $wpdb;
-
- $results = $wpdb->get_results("select id, wpgcountry_name as cname from wpg_countries order by id");
-
- return ($results);
- }
-
- /**
- * @return array|string
- *
- * @psalm-return array{0: mixed, 1: mixed}|string
- */
- static function get_band($bid)
- {
- global $wpdb;
- if(!empty($bid))
- {
-
- $results = $wpdb->get_results('select wpgband_name as bname, wpgband_country as cname from wpg_bands where wpg_bands.id = '.$bid );
-
- return array ($results[0]->bname,$results[0]->cname);
- }
- else return('');
- }
-
- static function update_band($bid,$bname,$bcountry)
- {
- global $wpdb;
-
- $res = $wpdb->update('wpg_bands', array(
- 'wpgband_name' => $bname,
- 'wpgband_country' => $bcountry
- ),
- array('id' => $bid)
- );
-
- if ( !$res ) {
- // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed
- error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}");
- die;
- }
-
- return ($wpdb->last_error);
- }
-
- public function save(): void
- {
- global $wpdb;
-
- $wpdb->insert('wpg_bands', array(
- 'id' => '',
- 'wpgband_name' => $this->bandname,
- 'wpgband_country' => $this->country
- ));
-
- $this->id = $wpdb->insert_id;
- }
-
- public function id()
- {
- return $this->id;
- }
-
- public function bandname()
- {
- return $this->bandname;
- }
- public function country()
- {
- return $this->country;
- }
- }
-}
diff --git a/tests/BandTest.php b/tests/BandTest.php
deleted file mode 100644
index e4fccbe..0000000
--- a/tests/BandTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-// 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
-
-declare(strict_types=1);
-
-require __DIR__ . '/../includes/band.php';
-
-final class BandTest extends WP_UnitTestCase
-{
- /* This function runs _once_ before all the test cases.
- *
- * Use it to set up a common state that all test cases can
- * use
- */
- static function wpSetUpBeforeClass() : void
- {
- GiglogAdmin_Band::create("The Flamboyant Blasphemers");
- }
-
- public function testCreatingBandWithName() : void
- {
- $count = count(GiglogAdmin_Band::all_bands());
-
- $band = GiglogAdmin_Band::create("Tullerusk");
-
- $this->assertEquals("Tullerusk", $band->bandname());
- $this->assertEquals($count + 1, count(GiglogAdmin_Band::all_bands()));
- }
-
- public function testCreateExistingBand() : void
- {
- $count = count(GiglogAdmin_Band::all_bands());
-
- $existing_band = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO");
- $new_band = GiglogAdmin_Band::create("The Flamboyant Blasphemers");
-
- $this->assertEquals($count, count(GiglogAdmin_Band::all_bands()));
- $this->assertEquals($existing_band->id(), $new_band->id());
- $this->assertEquals($existing_band->bandname(), $new_band->bandname());
- }
-
- public function testCreateBandsWithSameNameInDifferentCountry() : void
- {
- $existing_band = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO");
- $new_band = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "RO");
-
- $this->assertNotEquals($existing_band->id(), $new_band->id());
- }
-
- public function testFindExistingBandReturnsObject() : void
- {
- $found = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO");
-
- $this->assertNotNull($found);
- $this->assertEquals("The Flamboyant Blasphemers", $found->bandname());
- }
-
- public function testFindNonExistingBandReturnsNULL() : void
- {
- // Nice, UK isn't in the country list, so let's move Venom to Azerbajan
- // for now...
- $found = GiglogAdmin_Band::find("Venom", "AZ");
-
- $this->assertNull($found);
- }
-}