diff --git a/wordpress/wp-content/plugins/intercom/assets/banner-1544x500.png b/wordpress/wp-content/plugins/intercom/assets/banner-1544x500.png new file mode 100644 index 0000000000000000000000000000000000000000..cc0164b8a413920681ad2b3e237137ed30683ebe Binary files /dev/null and b/wordpress/wp-content/plugins/intercom/assets/banner-1544x500.png differ diff --git a/wordpress/wp-content/plugins/intercom/assets/banner-772x250.png b/wordpress/wp-content/plugins/intercom/assets/banner-772x250.png new file mode 100644 index 0000000000000000000000000000000000000000..cc3d56d6be607aa8f3b73f0d93fbf6366803a1e4 Binary files /dev/null and b/wordpress/wp-content/plugins/intercom/assets/banner-772x250.png differ diff --git a/wordpress/wp-content/plugins/intercom/assets/icon.svg b/wordpress/wp-content/plugins/intercom/assets/icon.svg new file mode 100644 index 0000000000000000000000000000000000000000..c70e758092d3f1ac38166b904bdecdc7bcdbab95 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/assets/icon.svg @@ -0,0 +1,10 @@ + + + + intercom-icon + Created with Sketch. + + + + + \ No newline at end of file diff --git a/wordpress/wp-content/plugins/intercom/bootstrap.php b/wordpress/wp-content/plugins/intercom/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..c1f14de16a1ff56838d9855fc99d602265bedb46 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/bootstrap.php @@ -0,0 +1,579 @@ +Intercom support for WordPress. +Author: Bob Long +Author URI: https://www.intercom.io +Version: 2.5.7 + */ + +class SecureModeCalculator +{ + private $raw_data = array(); + private $secret_key = ""; + + public function __construct($data, $secret_key, $secure_mode) + { + $this->raw_data = $data; + $this->secret_key = $secret_key; + $this->secure_mode = $secure_mode; + } + + public function secureModeComponent() + { + $secret_key = $this->getSecretKey(); + $secure_mode = $this->getSecureMode(); + if (empty($secret_key) || !$secure_mode) + { + return $this->emptySecureModeHashComponent(); + } + if (array_key_exists("user_id", $this->getRawData())) + { + return $this->secureModeHashComponent("user_id"); + } + if (array_key_exists("email", $this->getRawData())) + { + return $this->secureModeHashComponent("email"); + } + return $this->emptySecureModeHashComponent(); + } + + private function emptySecureModeHashComponent() + { + return array(); + } + + private function secureModeHashComponent($key) + { + $raw_data = $this->getRawData(); + return array("user_hash" => hash_hmac("sha256", $raw_data[$key], $this->getSecretKey())); + } + + private function getSecretKey() + { + return $this->secret_key; + } + + private function getSecureMode() + { + return $this->secure_mode; + } + + private function getRawData() + { + return $this->raw_data; + } +} + +class IntercomSettingsPage +{ + private $settings = array(); + private $styles = array(); + + public function __construct($settings) + { + $this->settings = $settings; + $this->styles = $this->setStyles($settings); + } + + public function dismissibleMessage($text) + { + return << +

$text

+ + +END; + } + + public function getAuthUrl() { + return "https://wordpress_auth.intercom.io/confirm?state=".get_site_url()."::".wp_create_nonce('intercom-oauth'); + } + + public function htmlUnclosed() + { + $settings = $this->getSettings(); + $styles = $this->getStyles(); + $app_id = WordPressEscaper::escAttr($settings['app_id']); + $secret = WordPressEscaper::escAttr($settings['secret']); + $secure_mode = WordPressEscaper::escAttr($settings['secure_mode']); + $auth_url = $this->getAuthUrl(); + $dismissable_message = ''; + if (isset($_GET['appId'])) { + // Copying app_id from setup guide + $app_id = WordPressEscaper::escAttr($_GET['appId']); + $dismissable_message = $this->dismissibleMessage("We've copied your new Intercom app id below. click to save changes and then close this window to finish signing up for Intercom."); + } + if (isset($_GET['saved'])) { + $dismissable_message = $this->dismissibleMessage("Your app id has been successfully saved. You can now close this window to finish signing up for Intercom."); + } + if (isset($_GET['authenticated'])) { + $dismissable_message = $this->dismissibleMessage('You successfully authenticated with Intercom'); + } + if (isset($_GET['enable_secure_mode'])) { + $dismissable_message = $this->dismissibleMessage('Secure Mode successfully enabled'); + } + $onboarding_markup = $this->getOnboardingLinkIfNoAppId(); + + return << + + +
+ $dismissable_message + +
+
+
+ +
+
+
Get started with Intercom
+ +
+ Chat with visitors to your website in real-time, capture them as leads, and convert them to customers. Install Intercom on your WordPress site in a couple of clicks. +
+ +
+ + + +
+ $onboarding_markup +
+ +
Intercom setup
+
Intercom app ID saved
+
+
Intercom has been installed
+ +
+
+ Intercom is now set up and ready to go. You can now chat with your existing and potential new customers, send them targeted messages, and get feedback. +
+
+ Click here to access your Intercom Team Inbox. +
+
+ Need help? Visit our documentation for best practices, tips, and much more. +
+
+
+ +
+
+ Learn more about our products : Acquire, Engage, Learn and Support. +
+
+ + + + + + + + + + + +
+ + +
+ +END; + } + + public function htmlClosed() + { + $settings = $this->getSettings(); + $styles = $this->getStyles(); + $auth_url = $this->getAuthUrl(); + $secret = WordPressEscaper::escAttr($settings['secret']); + $app_id = WordPressEscaper::escAttr($settings['app_id']); + $auth_url_secure = ""; + if (empty($secret) && !empty($app_id)) { + $auth_url_secure = $auth_url.'&enable_secure_mode=1'; + } + return << +
+ +

Secure mode allows you to make sure that conversations between you and your users are kept private.
+ Once you enabled secure mode you cannot disable it.
+ Learn more about Secure Mode +

+
+
If the Intercom application associated with your store is incorrect, please click here to reconnect with Intercom, to choose a new application.
+
+
+
+
+
+
+
+
+ + +END; + } + + public function html() + { + return $this->htmlUnclosed() . $this->htmlClosed(); + } + + public function setStyles($settings) { + $styles = array(); + $app_id = WordPressEscaper::escAttr($settings['app_id']); + $secret = WordPressEscaper::escAttr($settings['secret']); + $secure_mode = WordPressEscaper::escAttr($settings['secure_mode']); + + // Use Case : secure mode enabled : checkbox checked and disabled (can not reverse secure mode) + if($secure_mode) { + $styles['secure_mode_state'] = 'checked disabled'; + } + + // Use Case : app_id here but secure mode disabled + if (empty($secret) && !empty($app_id)) { + $styles['app_secret_row_style'] = 'display: none;'; + $styles['app_secret_link_style'] = ''; + } else { + $styles['app_secret_row_style'] = ''; + $styles['app_secret_link_style'] = 'display: none;'; + } + + // Copying appId from Intercom Setup Guide for validation + if (isset($_GET['appId'])) { + $app_id = WordPressEscaper::escAttr($_GET['appId']); + $styles['app_id_state'] = 'readonly'; + $styles['app_id_class'] = "cta__email"; + $styles['button_submit_style'] = ''; + $styles['app_id_copy_hidden'] = 'display: none;'; + $styles['app_id_copy_title'] = ''; + $styles['secure_mode_state'] = 'disabled'; # Prevent from sending POST data about secure_mode when using app_id form + } else { + $styles['app_id_class'] = ""; + $styles['button_submit_style'] = 'display: none;'; + $styles['app_id_copy_title'] = 'display: none;'; + $styles['app_id_state'] = 'disabled'; # Prevent from sending POST data about app_id when using secure_mode form + $styles['app_id_copy_hidden'] = ''; + } + + //Use Case App_id successfully copied + if (isset($_GET['saved'])) { + $styles['app_id_copy_hidden'] = 'display: none;'; + $styles['app_id_saved_title'] = ''; + } else { + $styles['app_id_saved_title'] = 'display: none;'; + } + + // Display 'connect with intercom' button if no app_id provided (copied from setup guide or from Oauth) + if (empty($app_id)) { + $styles['app_id_row_style'] = 'display: none;'; + $styles['app_id_link_style'] = ''; + } else { + $styles['app_id_row_style'] = ''; + $styles['app_id_link_style'] = 'display: none;'; + } + return $styles; + } + + private function getSettings() + { + return $this->settings; + } + + private function getStyles() + { + return $this->styles; + } + + private function getOnboardingLinkIfNoAppId() + { + $settings = $this->getSettings(); + $app_id = $settings['app_id']; + if(!$app_id) { + return '

Need an Intercom account? Get started.

'; + } else { + return ''; + } + } +} + +class Snippet +{ + private $snippet_settings = ""; + + public function __construct($snippet_settings) + { + $this->snippet_settings = $snippet_settings; + } + public function html() + { + return $this->shutdown_on_logout() . $this->source(); + } + + + private function shutdown_on_logout() + { + return << + var logout_link = document.querySelectorAll('a[href*="wp-login.php?action=logout"]'); + if (logout_link) { + for(var i=0; i < logout_link.length; i++) { + logout_link[i].addEventListener( "click", function() { + Intercom('shutdown'); + }); + } + } + + +HTML; + } + private function source() + { + $snippet_json = $this->snippet_settings->json(); + $app_id = $this->snippet_settings->appId(); + + return << + window.intercomSettings = $snippet_json; + + +HTML; + } +} + +class SnippetSettings +{ + private $raw_data = array(); + private $secret = NULL; + private $wordpress_user = NULL; + + public function __construct($raw_data, $secret = NULL, $secure_mode = false, $wordpress_user = NULL, $constants = array('ICL_LANGUAGE_CODE' => 'language_override')) + { + $this->raw_data = $this->validateRawData($raw_data); + $this->secret = $secret; + $this->secure_mode = $secure_mode; + $this->wordpress_user = $wordpress_user; + $this->constants = $constants; + } + + public function json() + { + return json_encode($this->getRawData()); + } + + public function appId() + { + $raw_data = $this->getRawData(); + return $raw_data["app_id"]; + } + + private function getRawData() + { + $user = new IntercomUser($this->wordpress_user, $this->raw_data); + $settings = $user->buildSettings(); + $secureModeCalculator = new SecureModeCalculator($settings, $this->secret, $this->secure_mode); + $result = array_merge($settings, $secureModeCalculator->secureModeComponent()); + $result = $this->mergeConstants($result); + return $result; + } + + private function mergeConstants($settings) { + foreach($this->constants as $key => $value) { + if (defined($key)) { + $const_val = WordPressEscaper::escJS(constant($key)); + $settings = array_merge($settings, array($value => $const_val)); + } + } + return $settings; + } + + private function validateRawData($raw_data) + { + if (!array_key_exists("app_id", $raw_data)) { + throw new Exception("app_id is required"); + } + return $raw_data; + } +} + +class WordPressEscaper +{ + public static function escAttr($value) + { + if (function_exists('esc_attr')) { + return esc_attr($value); + } else { + if (getenv('INTERCOM_PLUGIN_TEST') == '1') { + return $value; + } + } + } + + public static function escJS($value) + { + if (function_exists('esc_js')) { + return esc_js($value); + } else { + if (getenv('INTERCOM_PLUGIN_TEST') == '1') { + return $value; + } + } + } +} + +class IntercomUser +{ + private $wordpress_user = NULL; + private $settings = array(); + + public function __construct($wordpress_user, $settings) + { + $this->wordpress_user = $wordpress_user; + $this->settings = $settings; + } + + public function buildSettings() + { + if (empty($this->wordpress_user)) + { + return $this->settings; + } + if (!empty($this->wordpress_user->user_email)) + { + $this->settings["email"] = WordPressEscaper::escJS($this->wordpress_user->user_email); + } + if (!empty($this->wordpress_user->display_name)) + { + $this->settings["name"] = WordPressEscaper::escJS($this->wordpress_user->display_name); + } + return $this->settings; + } +} + +class Validator +{ + private $inputs = array(); + private $validation; + + public function __construct($inputs, $validation) + { + $this->input = $inputs; + $this->validation = $validation; + } + + public function validAppId() + { + return $this->validate($this->input["app_id"]); + } + + public function validSecret() + { + return $this->validate($this->input["secret"]); + } + + private function validate($x) + { + return call_user_func($this->validation, $x); + } +} + +if (getenv('INTERCOM_PLUGIN_TEST') != '1') { + if (!defined('ABSPATH')) exit; +} + +function add_intercom_snippet() +{ + $options = get_option('intercom'); + $snippet_settings = new SnippetSettings( + array("app_id" => WordPressEscaper::escJS($options['app_id'])), + WordPressEscaper::escJS($options['secret']), + WordPressEscaper::escJS($options['secure_mode']), + wp_get_current_user() + ); + $snippet = new Snippet($snippet_settings); + echo $snippet->html(); +} + +function add_intercom_settings_page() +{ + add_options_page( + 'Intercom Settings', + 'Intercom', + 'manage_options', + 'intercom', + 'render_intercom_options_page' + ); +} + +function render_intercom_options_page() +{ + if (!current_user_can('manage_options')) + { + wp_die('You do not have sufficient permissions to access Intercom settings'); + } + $options = get_option('intercom'); + $settings_page = new IntercomSettingsPage(array("app_id" => $options['app_id'], "secret" => $options['secret'], "secure_mode" => $options['secure_mode'])); + echo $settings_page->htmlUnclosed(); + wp_nonce_field('intercom-update'); + echo $settings_page->htmlClosed(); +} + +function intercom_settings() { + register_setting('intercom', 'intercom'); + if (isset($_GET['state']) && wp_verify_nonce($_GET[ 'state'], 'intercom-oauth') && current_user_can('manage_options') && isset($_GET['app_id']) && isset($_GET['secret']) ) { + $validator = new Validator($_GET, function($x) { return wp_kses(trim($x), array()); }); + $secure_mode = isset($_GET['enable_secure_mode']); + update_option("intercom", array("app_id" => $validator->validAppId(), "secret" => $validator->validSecret(), "secure_mode" => $secure_mode)); + $redirect_to = $secure_mode ? 'options-general.php?page=intercom&enable_secure_mode=1' : 'options-general.php?page=intercom&authenticated=1'; + wp_safe_redirect(admin_url($redirect_to)); + } + if ( current_user_can('manage_options') && isset($_POST[ '_wpnonce']) && wp_verify_nonce($_POST[ '_wpnonce'],'intercom-update') && isset($_POST['enable_secure_mode'])) { + $options = get_option('intercom'); + $options["secure_mode"] = true; + update_option("intercom", $options); + wp_safe_redirect(admin_url('options-general.php?page=intercom&enable_secure_mode=1')); + } + if (current_user_can('manage_options') && isset($_POST['app_id']) && isset($_POST[ '_wpnonce']) && wp_verify_nonce($_POST[ '_wpnonce'],'intercom-update')) { + $options = array(); + $options["app_id"] = WordPressEscaper::escAttr($_POST['app_id']); + update_option("intercom", $options); + wp_safe_redirect(admin_url('options-general.php?page=intercom&saved=1')); + } +} +// Enable Secure Mode for customers who already copy/pasted their secret_key before the Oauth2 release. +function patch_oauth() { + $options = get_option('intercom'); + if ($options["secret"] && !isset($options["secure_mode"])) { + $options["secure_mode"] = true; + update_option("intercom", $options); + } +} + +if (getenv('INTERCOM_PLUGIN_TEST') != '1') { + add_action('wp_footer', 'add_intercom_snippet'); + add_action('admin_menu', 'add_intercom_settings_page'); + add_action('network_admin_menu', 'add_intercom_settings_page'); + add_action('admin_init', 'patch_oauth'); + add_action('admin_init', 'intercom_settings'); +} diff --git a/wordpress/wp-content/plugins/intercom/phpunit.xml.dist b/wordpress/wp-content/plugins/intercom/phpunit.xml.dist new file mode 100644 index 0000000000000000000000000000000000000000..d289b73377082ad105168077eb6c58526b7293c3 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/phpunit.xml.dist @@ -0,0 +1,9 @@ + + + + + + ./test + + + diff --git a/wordpress/wp-content/plugins/intercom/readme.md b/wordpress/wp-content/plugins/intercom/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..05ebe81775f015aac5ded2ab934fc4fc98007fd4 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/readme.md @@ -0,0 +1,46 @@ +# Intercom / WordPress + +[![Build Status](https://travis-ci.org/intercom/intercom-wordpress.svg?branch=master)](https://travis-ci.org/intercom/intercom-wordpress) + +# Compatibility + +Requires PHP 5.3 or higher. + +# Local Testing + +Running tests requires [phpunit](https://phpunit.de/). + +```php +INTERCOM_PLUGIN_TEST=1 phpunit +``` + +# Test the new version of the plugin with Intercom's Wordpress signup flow + +It is mandatory that you fully test the [intercom wordpress setup guide](https://app.intercom.io/a/start/wordpress) before you release a new update of the plugin. + +# Usage + +Installing this plugin provides a new Intercom settings page. +Authenticate with Intercom to retrieve your app_id and secure_mode_secret. + + +Once authenticated, if you have enabled [Acquire](https://www.intercom.io/live-chat), the Intercom widget will automatically appear on your site. + + + +NB: This plugin injects a Javascript snippet on your website frontend containing dynamic user data. Some caching solutions will cache entire pages and should not be used with this plugin. Doing so may cause conversations to be delivered to the wrong user. + +# Users + +If a `$current_user` is present, we use their email as an identifier in the widget. +We recommend to enable the [secure mode](https://docs.intercom.io/configuring-intercom/enable-secure-mode) in the settings page. +Otherwise the widget operates in [Acquire mode](https://www.intercom.io/live-chat) (if available). This allows you to talk with anonymous visitors on your WordPress site. + +# Contributing + +* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. +* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. +* Fork the project. +* Start a feature/bugfix branch. +* Commit and push until you are happy with your contribution. +* Make sure to add tests for it. This is important so we don't break it in a future version unintentionally. diff --git a/wordpress/wp-content/plugins/intercom/readme.txt b/wordpress/wp-content/plugins/intercom/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..062ba818ce56eb4d95a1a99af22de04754ba8585 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/readme.txt @@ -0,0 +1,26 @@ +=== Plugin Name === +Contributors: bobintercom +License: Apache 2.0 +Tags: intercom, customer, chat +Requires at least: 4.2.0 +Tested up to: 4.2.4 + +The official WordPress plugin, built by Intercom. Chat with your website visitors in real-time, capture them as leads, and convert them to customers. + +== Description == + +[Intercom](https://www.intercom.io/) is a fundamentally new way for internet businesses to communicate with customers, personally, at scale. It's a customer communication platform with a suite of integrated products for every team – including sales, marketing, product, and support. Our products enable targeted communication with customers on your website, inside your web and mobile apps, and by email. + +With this plugin, you can add the Intercom Messenger to your website in just a few clicks and start chatting to customers and visitors to your website right away ([Acquire](https://www.intercom.io/live-chat) subscription required). + +Your logged-in customers will be tracked in Intercom as users, and visitors who aren’t customers (or aren’t logged in) will be tracked as leads. + +== Installation == + +Installing Intercom on your WordPress site takes just a few minutes. + +If you aren’t already an Intercom customer, you can find full instructions on signing up and installing Intercom using the WordPress plugin [here](https://docs.intercom.io/install-on-your-product-or-site/other-ways-to-get-started/install-intercom-on-your-wordpress-site). + +If you’re already an Intercom customer, you can find instructions in the in-app [setup guide](https://app.intercom.io/a/apps/_/guide/web_integration/web_integration_users). The first thing you’ll need to do is install and activate the plugin - you must be using WordPress v4.2.0 or higher and have the ability to install plugins in order to use this method. + +Note: This plugin injects a Javascript snippet on your website frontend containing dynamic user data. Some caching solutions will cache entire pages and should not be used with this plugin. Doing so may cause conversations to be delivered to the wrong user. diff --git a/wordpress/wp-content/plugins/intercom/screenshots/settings.png b/wordpress/wp-content/plugins/intercom/screenshots/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..fd8dd155dd0ce80c8d136fc5bf4f106aac065448 Binary files /dev/null and b/wordpress/wp-content/plugins/intercom/screenshots/settings.png differ diff --git a/wordpress/wp-content/plugins/intercom/screenshots/widget.png b/wordpress/wp-content/plugins/intercom/screenshots/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..9f1ad73f8d1dd193647471568c4975dbb684cf14 Binary files /dev/null and b/wordpress/wp-content/plugins/intercom/screenshots/widget.png differ diff --git a/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php b/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0c65ee276760fdc39128b895d07b577786ed9d6a --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/SecureModeCalulatorTest.php @@ -0,0 +1,31 @@ + "test@intercom.io"); + $calculator = new SecureModeCalculator($data, "s3cre7"); + $this->assertEquals(array("user_hash" => "844240a2deab99438ade8e7477aa832e22adb0e1eb1ad7754ff8d4054fb63869"), $calculator->secureModeComponent()); + } + + public function testHashUserId() + { + $data = array("user_id" => "abcdef", "email" => "test@intercom.io"); + $calculator = new SecureModeCalculator($data, "s3cre7"); + $this->assertEquals(array("user_hash" => "532cd9cd6bfa49528cf2503db0743bb72456bda2cb7424d2894c5b11f6cad6cf"), $calculator->secureModeComponent()); + } + + public function testEmpty() + { + $data = array(); + $calculator = new SecureModeCalculator($data, "s3cre7"); + $this->assertEquals(array(), $calculator->secureModeComponent()); + } + + public function testNoSecureMode() + { + $data = array("email" => "test@intercom.io"); + $calculator = new SecureModeCalculator($data, ""); + $this->assertEquals(array(), $calculator->secureModeComponent()); + } +} diff --git a/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php b/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b7d82e342af319cdd368a903fdd4799fdee42e49 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/SettingsPageTest.php @@ -0,0 +1,57 @@ + NULL, "secret" => NULL)); + $expectedHtml = <<Intercom Settings + +
+ + + + + + + + + + + + +
App ID
Secret
+ +

Need an Intercom account? Get started.

+
+END; + $this->assertEquals($expectedHtml, $settings_page->html()); + } + + public function testGeneratedHtml() + { + $settings_page = new SettingsPage(array("app_id" => "foo", "secret" => "bar")); + $expectedHtml = <<Intercom Settings + +
+
+ + + + + + + + + + + +
App ID
Secret
+ +
+
+END; + $this->assertEquals($expectedHtml, $settings_page->html()); + } +} diff --git a/wordpress/wp-content/plugins/intercom/test/SnippetSettingsTest.php b/wordpress/wp-content/plugins/intercom/test/SnippetSettingsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..352eaedabcfb72bf6fdf9827d10059b193809248 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/SnippetSettingsTest.php @@ -0,0 +1,33 @@ + "bar")); + $this->assertEquals("{\"app_id\":\"bar\"}", $snippet_settings->json()); + } + public function testJSONRenderingWithSecureMode() + { + $snippet_settings = new SnippetSettings(array("app_id" => "bar"), "foo", new FakeWordpressUserForSnippetTest()); + $this->assertEquals("{\"app_id\":\"bar\",\"email\":\"foo@bar.com\",\"user_hash\":\"a95b0a1ab461c0721d91fbe32a5f5f2a27ac0bfa4bfbcfced168173fa80d4e14\"}", $snippet_settings->json()); + } + + public function testAppId() + { + $snippet_settings = new SnippetSettings(array("app_id" => "bar")); + $this->assertEquals("bar", $snippet_settings->appId()); + } + + /** + * @expectedException Exception + */ + public function testValidation() + { + $snippet = new SnippetSettings(array("foo" => "bar")); + } +} diff --git a/wordpress/wp-content/plugins/intercom/test/SnippetTest.php b/wordpress/wp-content/plugins/intercom/test/SnippetTest.php new file mode 100644 index 0000000000000000000000000000000000000000..744540181a5bc0bfe3f0308af142792ec412119f --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/SnippetTest.php @@ -0,0 +1,18 @@ + "foo", "name" => "Nikola Tesla")); + $snippet = new Snippet($settings); + + $expectedHtml = << + window.intercomSettings = JSON.parse('{"app_id":"foo","name":"Nikola Tesla"}'); + + +HTML; + + $this->assertEquals($expectedHtml, $snippet->html()); + } +} diff --git a/wordpress/wp-content/plugins/intercom/test/UserTest.php b/wordpress/wp-content/plugins/intercom/test/UserTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3023f2a0dbf053bdc2a03415bc5a63effb6b6ddf --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/UserTest.php @@ -0,0 +1,31 @@ +buildSettings(); + $this->assertEquals("foo@bar.com", $built_settings["email"]); + } + public function testNoUser() + { + $settings = array(); + $built_settings = (new User(NULL, $settings))->buildSettings(); + $this->assertEquals(false, array_key_exists('email', $built_settings)); + } + public function testNoUserEmail() + { + $settings = array(); + $built_settings = (new User(new FakeWordpressUserNoEmail(), $settings))->buildSettings(); + $this->assertEquals(false, array_key_exists('email', $built_settings)); + } +} diff --git a/wordpress/wp-content/plugins/intercom/test/ValidatorTest.php b/wordpress/wp-content/plugins/intercom/test/ValidatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..32889a10a74602e3a5923a3ad682976dc38ac2b6 --- /dev/null +++ b/wordpress/wp-content/plugins/intercom/test/ValidatorTest.php @@ -0,0 +1,13 @@ +", "", $x); + }; + $validator = new Validator(array("app_id" => "foo