-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add activate and uninstall tests
- Loading branch information
Showing
7 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class WP_Notifications_DB_TestCase extends TestCase { | ||
protected function table_exists( $table_name ): bool { | ||
global $wpdb; | ||
$expected = $wpdb->prefix . $table_name; | ||
$result = $wpdb->get_var( | ||
$wpdb->prepare( | ||
'SHOW TABLES LIKE %s', | ||
$wpdb->esc_like( $wpdb->prefix . $table_name ) | ||
) | ||
); | ||
return $expected == $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use WP\Notifications\Activator; | ||
use WP\Notifications\Uninstaller; | ||
|
||
class Test_WP_Notify_Activator extends WP_Notifications_DB_TestCase { | ||
|
||
/** | ||
* Remove the plugin to test installation. | ||
*/ | ||
public static function setUpBeforeClass(): void { | ||
Uninstaller::drop_tables(); | ||
} | ||
|
||
// Sanity checks to ensure the database table initially does not exist. | ||
|
||
public function test_it_should_initially_not_have_messages_table() { | ||
$this->assertFalse( $this->table_exists( 'notifications_messages' ) ); | ||
} | ||
|
||
public function test_it_should_initially_not_have_channels_table() { | ||
$this->assertFalse( $this->table_exists( 'notifications_channels' ) ); | ||
} | ||
|
||
public function test_it_should_initially_not_have_subscriptions_table() { | ||
$this->assertFalse( $this->table_exists( 'notifications_subscriptions' ) ); | ||
} | ||
|
||
public function test_it_should_initially_not_have_queue_table() { | ||
$this->assertFalse( $this->table_exists( 'notifications_queue' ) ); | ||
} | ||
|
||
// Installation procedure tests. | ||
|
||
/** | ||
* Test to ensure the uninstall procedure drops the correct tables. | ||
*/ | ||
public function test_it_should_create_tables() { | ||
Activator::create_tables_v1(); | ||
|
||
$this->assertTrue( $this->table_exists( 'notifications_messages' ) ); | ||
$this->assertTrue( $this->table_exists( 'notifications_channels' ) ); | ||
$this->assertTrue( $this->table_exists( 'notifications_subscriptions' ) ); | ||
$this->assertTrue( $this->table_exists( 'notifications_queue' ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
use WP\Notifications\Activator; | ||
use WP\Notifications\Uninstaller; | ||
|
||
class Test_WP_Notify_Uninstaller extends WP_Notifications_DB_TestCase { | ||
|
||
/** | ||
* Ensure tables are created before tests. | ||
*/ | ||
public static function setUpBeforeClass(): void { | ||
Activator::create_tables_v1(); | ||
} | ||
|
||
// Sanity checks to ensure the database tables initially do exist. | ||
|
||
public function test_it_should_initially_have_messages_table() { | ||
$this->assertTrue( $this->table_exists( 'notifications_messages' ) ); | ||
} | ||
|
||
public function test_it_should_initially_have_channels_table() { | ||
$this->assertTrue( $this->table_exists( 'notifications_channels' ) ); | ||
} | ||
|
||
public function test_it_should_initially_have_subscriptions_table() { | ||
$this->assertTrue( $this->table_exists( 'notifications_subscriptions' ) ); | ||
} | ||
|
||
public function test_it_should_initially_have_queue_table() { | ||
$this->assertTrue( $this->table_exists( 'notifications_queue' ) ); | ||
} | ||
|
||
/** | ||
* Test to ensure the uninstall procedure drops the correct tables. | ||
*/ | ||
public function test_it_should_drops_tables() { | ||
Uninstaller::uninstall(); | ||
|
||
$this->assertFalse( $this->table_exists( 'notifications_messages' ) ); | ||
$this->assertFalse( $this->table_exists( 'notifications_channels' ) ); | ||
$this->assertFalse( $this->table_exists( 'notifications_subscriptions' ) ); | ||
$this->assertFalse( $this->table_exists( 'notifications_queue' ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters