From b8cb1da7778939417dfeb2fa90e2040b0091844e Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Fri, 4 Nov 2016 14:11:37 +0100 Subject: [PATCH] added custom information to HS Beacon --- lib/Config/Renderer.php | 5 ++ lib/Helpscout/Beacon.php | 50 +++++++++++++ lib/Twig/Helpscout.php | 21 ++++++ tests/unit/Helpscout/BeaconTest.php | 107 ++++++++++++++++++++++++++++ views/layout.html | 10 ++- 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 lib/Helpscout/Beacon.php create mode 100644 lib/Twig/Helpscout.php create mode 100644 tests/unit/Helpscout/BeaconTest.php diff --git a/lib/Config/Renderer.php b/lib/Config/Renderer.php index 921584660f..06f4d79c3a 100644 --- a/lib/Config/Renderer.php +++ b/lib/Config/Renderer.php @@ -25,6 +25,7 @@ class Renderer { $this->setupTranslations(); $this->setupFunctions(); $this->setupHandlebars(); + $this->setupHelpscout(); $this->setupGlobalVariables(); $this->setupSyntax(); @@ -43,6 +44,10 @@ class Renderer { $this->renderer->addExtension(new Twig\Handlebars()); } + function setupHelpscout() { + $this->renderer->addExtension(new Twig\Helpscout()); + } + function setupGlobalVariables() { $this->renderer->addExtension(new Twig\Assets(array( 'assets_url' => Env::$assets_url, diff --git a/lib/Helpscout/Beacon.php b/lib/Helpscout/Beacon.php new file mode 100644 index 0000000000..3adb1be6c5 --- /dev/null +++ b/lib/Helpscout/Beacon.php @@ -0,0 +1,50 @@ +get_var('SELECT @@VERSION'); + + // curent user + $current_user = wp_get_current_user(); + + return array( + 'name' => $current_user->display_name, + 'email' => $current_user->user_email, + 'PHP version' => PHP_VERSION, + 'MailPoet version' => MAILPOET_VERSION, + 'WordPress version' => get_bloginfo('version'), + 'Database version' => $db_version, + 'WP_MEMORY_LIMIT' => WP_MEMORY_LIMIT, + 'WP_MAX_MEMORY_LIMIT' => WP_MAX_MEMORY_LIMIT, + 'WP_DEBUG' => WP_DEBUG, + 'PHP max_execution_time' => ini_get('max_execution_time'), + 'PHP memory_limit' => ini_get('memory_limit'), + 'PHP upload_max_filesize' => ini_get('upload_max_filesize'), + 'PHP post_max_size' => ini_get('post_max_size'), + 'WordPress language' => get_locale(), + 'Multisite environment?' => (is_multisite() ? 'Yes' : 'No'), + 'Current Theme' => $current_theme->get('Name'). + ' (version '.$current_theme->get('Version').')', + 'Active Plugin names' => join(", ", get_option('active_plugins')), + 'Sending Method' => $mta['method'], + 'Sending Frequency' => sprintf('%d emails every %d minutes', + $mta['frequency']['emails'], + $mta['frequency']['interval'] + ), + 'Task Scheduler method' => Setting::getValue('cron_trigger.method'), + 'Default FROM address' => Setting::getValue('sender.address'), + 'Default Reply-To address' => Setting::getValue('reply_to.address'), + 'Bounce Email Address' => Setting::getValue('bounce.address'), + 'Total number of subscribers' => Subscriber::getTotalSubscribers() + ); + } +} \ No newline at end of file diff --git a/lib/Twig/Helpscout.php b/lib/Twig/Helpscout.php new file mode 100644 index 0000000000..f936e8d29d --- /dev/null +++ b/lib/Twig/Helpscout.php @@ -0,0 +1,21 @@ + array('all')) + ) + ); + } +} diff --git a/tests/unit/Helpscout/BeaconTest.php b/tests/unit/Helpscout/BeaconTest.php new file mode 100644 index 0000000000..e57c815749 --- /dev/null +++ b/tests/unit/Helpscout/BeaconTest.php @@ -0,0 +1,107 @@ + 'user1@mailpoet.com', + 'status' => Subscriber::STATUS_SUBSCRIBED + )); + Subscriber::createOrUpdate(array( + 'email' => 'user2@mailpoet.com', + 'status' => Subscriber::STATUS_UNCONFIRMED + )); + Subscriber::createOrUpdate(array( + 'email' => 'user3@mailpoet.com', + 'status' => Subscriber::STATUS_UNSUBSCRIBED + )); + + $this->beacon_data = Beacon::getData(); + } + + function testItReturnsPhpVersion() { + expect($this->beacon_data['PHP version'])->equals(PHP_VERSION); + } + + function testItReturnsMailpoetVersion() { + expect($this->beacon_data['MailPoet version'])->equals(MAILPOET_VERSION); + } + + function testItReturnsWordpressVersion() { + expect($this->beacon_data['WordPress version'])->equals(get_bloginfo('version')); + } + + function testItReturnsDatabaseVersion() { + global $wpdb; + $db_version = $wpdb->get_var('SELECT @@VERSION'); + expect($this->beacon_data['Database version'])->equals($db_version); + } + + function testItReturnsWpMemoryLimit() { + expect($this->beacon_data['WP_MEMORY_LIMIT'])->equals(WP_MEMORY_LIMIT); + } + + function testItReturnsWpMaxMemoryLimit() { + expect($this->beacon_data['WP_MAX_MEMORY_LIMIT'])->equals(WP_MAX_MEMORY_LIMIT); + } + + function testItReturnsWpDebugValue() { + expect($this->beacon_data['WP_DEBUG'])->equals(WP_DEBUG); + } + + function testItReturnsPhpMaxExecutionTime() { + expect($this->beacon_data['PHP max_execution_time'])->equals(ini_get('max_execution_time')); + } + + function testItReturnsPhpMemoryLimit() { + expect($this->beacon_data['PHP memory_limit'])->equals(ini_get('memory_limit')); + } + + function testItReturnsPhpUploadMaxFilesize() { + expect($this->beacon_data['PHP upload_max_filesize'])->equals(ini_get('upload_max_filesize')); + } + + function testItReturnsPhpPostMaxSize() { + expect($this->beacon_data['PHP post_max_size'])->equals(ini_get('post_max_size')); + } + + function testItReturnsWpLanguage() { + expect($this->beacon_data['WordPress language'])->equals(get_locale()); + } + + function testItReturnsIfWpIsMultisite() { + expect($this->beacon_data['Multisite environment?'])->equals(is_multisite() ? 'Yes' : 'No'); + } + + function testItReturnsCurrentThemeNameAndVersion() { + $current_theme = wp_get_theme(); + expect($this->beacon_data['Current Theme'])->contains($current_theme->get('Name')); + expect($this->beacon_data['Current Theme'])->contains($current_theme->get('Version')); + } + + function testItReturnsActivePlugins() { + expect($this->beacon_data['Active Plugin names'])->equals(join(", ", get_option('active_plugins'))); + } + + function testItReturnsSendingMethodDetails() { + $mta = Setting::getValue('mta'); + expect($this->beacon_data['Sending Method'])->equals($mta['method']); + expect($this->beacon_data['Sending Frequency'])->contains($mta['frequency']['emails'].' emails'); + expect($this->beacon_data['Sending Frequency'])->contains($mta['frequency']['interval'].' minutes'); + } + + function testItReturnsSomeSettings() { + expect($this->beacon_data['Task Scheduler method'])->equals(Setting::getValue('cron_trigger.method')); + expect($this->beacon_data['Default FROM address'])->equals(Setting::getValue('sender.address')); + expect($this->beacon_data['Default Reply-To address'])->equals(Setting::getValue('reply_to.address')); + expect($this->beacon_data['Bounce Email Address'])->equals(Setting::getValue('bounce.address')); + } + + function testItReturnsTotalNumberOfSubscribers() { + // unsubscribed users are not taken into account + expect($this->beacon_data['Total number of subscribers'])->equals(2); + } +} \ No newline at end of file diff --git a/views/layout.html b/views/layout.html index 73e4a11940..6beb835748 100644 --- a/views/layout.html +++ b/views/layout.html @@ -57,10 +57,18 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')