Skip to content

Commit

Permalink
BUGS-6563: Adds unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wagner committed Sep 21, 2023
1 parent deb3cf4 commit 85db732
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/phpunit/test-init-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package WPNPS
*/

use Pantheon_Sessions\CLI_Command;

/**
* Tests plugin initialization.
*/
Expand Down Expand Up @@ -42,4 +44,49 @@ public function test_database_created() {
$columns
);
}

/**
* Ensure that the primary key addition command works.
*/
public function test_primary_key_addition() {
global $wpdb, $table_prefix;
$table_name = "{$table_prefix}pantheon_sessions";
$command = new CLI_Command();

$query = "ALTER TABLE {$table_name} DROP COLUMN id";
$wpdb->query( $query );

$command->add_index('', '');
$column_data = $wpdb->get_results( "SHOW COLUMNS FROM {$table_name}" );
$columns = wp_list_pluck( $column_data, 'Field' );
$this->assertEquals(
[
'user_id',
'session_id',
'secure_session_id',
'ip_address',
'datetime',
'data',
],
$columns
);

$command->add_index('', '');
$column_data = $wpdb->get_results( "SHOW COLUMNS FROM {$table_name}" );
$columns = wp_list_pluck( $column_data, 'Field' );
$this->assertEquals(
[
'id',
'user_id',
'session_id',
'secure_session_id',
'ip_address',
'datetime',
'data',
],
$columns
);


}
}

0 comments on commit 85db732

Please sign in to comment.