Skip to content
Permalink
Browse files

Merge pull request #862 from rheinardkorf/bugfix/836-custom-roles-not…

…-tracking

Bugfix: #836 Custom Roles not tracking
  • Loading branch information...
Luke Carbis
Luke Carbis committed Jul 27, 2016
2 parents 9560e3c + 5d1d159 commit 5df0f500c9762066442ab3508bbfc4af475cd61d
Showing with 101 additions and 6 deletions.
  1. +6 −6 classes/class-install.php
  2. +17 −0 includes/db-updates.php
  3. +68 −0 tests/tests/test-class-log.php
  4. +10 −0 tests/tests/test-class-plugin.php
@@ -76,8 +76,6 @@ public function __construct( $plugin ) {
* @return void
*/
public function check() {
global $wpdb;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
@@ -97,15 +95,16 @@ public function check() {
if ( ! $update ) {
$this->update_required = true;
$this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'auto' ) );
} elseif ( 'update_and_continue' === $update ) {
}
if ( 'update_and_continue' === $update ) {
$this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'user' ) );
}
$versions = $this->db_update_versions();
if ( version_compare( end( $versions ), $this->db_version, '>' ) ) {
if ( ! $this->success_db && version_compare( end( $versions ), $this->db_version, '>' ) ) {
add_action( 'all_admin_notices', array( $this, 'update_notice_hook' ) );
return;
}
@@ -337,6 +336,7 @@ public function db_update_versions() {
$db_update_versions = array(
'3.0.0' /* @version 3.0.0 Drop the stream_context table, changes to stream table */,
'3.0.2' /* @version 3.0.2 Fix uppercase values in stream table, connector column */,
'3.0.8' /* @version 3.0.8 Increase size of user role IDs, user_roll column */,
);
/**
@@ -399,7 +399,7 @@ public function install( $current_version ) {
blog_id bigint(20) unsigned NOT NULL DEFAULT '1',
object_id bigint(20) unsigned NULL,
user_id bigint(20) unsigned NOT NULL DEFAULT '0',
user_role varchar(20) NOT NULL DEFAULT '',
user_role varchar(50) NOT NULL DEFAULT '',
summary longtext NOT NULL,
created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
connector varchar(100) NOT NULL,
@@ -1,4 +1,21 @@
<?php
/**
* Version 3.0.8
*
* Force update for older versions to call \dbdelta in install() method to fix column widths.
*
* @param string $db_version
* @param string $current_version
*
* @return string
*/
function wp_stream_update_auto_308( $db_version, $current_version ) {
$plugin = wp_stream_get_instance();
$plugin->install->install( $current_version );
return $current_version;
}
/**
* Version 3.0.2
*
@@ -0,0 +1,68 @@
<?php
namespace WP_Stream;
class Test_Log extends WP_StreamTestCase {
public function setUp() {
parent::setUp();
$admin_role = get_role( 'administrator' );
/**
* Add user roles for testing.
*/
$role = 'this_longish_user_role_slug_to_be_logged_in_stream';
$long = get_role( $role );
if ( ! $long ) {
$long = add_role(
$role,
'This longish user_role slug to be logged in stream',
(array) $admin_role->capabilities
);
}
$role = 'this_is_a_really_long_user_role_slug_that_will_not_be_logged_in_stream';
$extra_long = get_role( $role );
if ( ! $extra_long ) {
$extra_long = add_role(
$role,
'This is a really long user_role slug that will not be logged in stream',
(array) $admin_role->capabilities
);
}
/**
* Add users for testing and assign roles.
*/
$user_id = wp_create_user( 'test1', 'password', 'test1@example.com' );
wp_update_user( array( 'ID' => $user_id, 'role' => $long->name ) );
$user_id = wp_create_user( 'test2', 'password', 'test2@example.com' );
wp_update_user( array( 'ID' => $user_id, 'role' => $extra_long->name ) );
}
public function test_field_lengths() {
$user1 = get_user_by( 'slug', 'test1' );
$user2 = get_user_by( 'slug', 'test2' );
// Test user_role length (<=50)
$result = $this->plugin->log->log( 'test_connector', 'Test user_role 1', array(), 0, 'settings', 'test', $user1->ID );
$this->assertNotEmpty( $result );
$record = $this->plugin->db->query( array( 'search' => $result, 'search_field' => 'ID' ) );
$this->assertEquals( $result, $record[0]->ID );
// Test user_role length (>50)
$result = $this->plugin->log->log( 'test_connector', 'Test user_role 2', array(), 0, 'settings', 'test', $user2->ID );
$this->assertEmpty( $result );
// Test connector length
// Test context length
// Test action length
// Test IP length
}
}
@@ -33,6 +33,16 @@ public function test_autoload() {
public function test_i18n() {
global $l10n;
/**
* Make sure we get the correct MO file during tests.
* WP looks in develop installation where MO file is not found.
*/
add_filter( 'load_textdomain_mofile', function( $mofile ) {
$locale = get_locale();
$mofile = sprintf( '%s/languages/stream-%s.mo', $this->plugin->locations['dir'], $locale );
return $mofile;
} );
$this->plugin->i18n();
$this->assertArrayHasKey( 'stream', $l10n );
}

0 comments on commit 5df0f50

Please sign in to comment.
You can’t perform that action at this time.