diff options
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | tests/BandTest.php | 47 |
2 files changed, 45 insertions, 5 deletions
diff --git a/composer.json b/composer.json index 3b74061..fb612a3 100644 --- a/composer.json +++ b/composer.json @@ -15,5 +15,8 @@ ], "require-dev": { "wp-phpunit/wp-phpunit": "^5.7" + }, + "scripts": { + "test": "./run-tests" } } diff --git a/tests/BandTest.php b/tests/BandTest.php index d3feb51..33b14f4 100644 --- a/tests/BandTest.php +++ b/tests/BandTest.php @@ -10,21 +10,58 @@ 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("The Flamboyant Blasphemers"); + $band = GiglogAdmin_Band::create("Tullerusk"); - $this->assertEquals("The Flamboyant Blasphemers", $band->bandname()); + $this->assertEquals("Tullerusk", $band->bandname()); $this->assertEquals($count + 1, count(GiglogAdmin_Band::all_bands())); } public function testCreateExistingBand() : void { - $band1 = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); - $band2 = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + $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()); + } + + 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); + } + + 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->assertEquals($band1->id(), $band2->id()); + $this->assertNull($found); } } |