/** * Callback for creating the plugin header. * * @param unknown $args */ function ibm_sbtk_header($args = array()) { $settings = new SBTSettings(); $store = SBTCredentialStore::getInstance(); $endpoints = $settings->getEndpoints(); if ($endpoints == null || empty($endpoints)) { return; } foreach ($endpoints as $endpoint) { if (($settings->getAuthenticationMethod($endpoint['name']) == 'oauth1' || $settings->getAuthenticationMethod($endpoint['name']) == 'oauth2') && $store->getOAuthAccessToken($endpoint['name']) == null && (!isset($_COOKIE['IBMSBTKOAuthLogin']) || $_COOKIE['IBMSBTKOAuthLogin'] != 'yes')) { $deploy_url = $settings->getSDKDeployURL($endpoint['name']); $authentication_method = $settings->getAuthenticationMethod($endpoint['name']); $js_library = $settings->getJSLibrary($endpoint['name']); $url = $settings->getURL($endpoint['name']); $name = $settings->getName($endpoint['name']); $api_version = $settings->getAPIVersion($endpoint['name']); $type = $settings->getServerType($endpoint['name']); $allow_client_access = $settings->allowClientAccess($endpoint['name']); $endpoints = $settings->getEndpoints(); // Load the header view require BASE_PATH . '/views/includes/header.php'; return; } } $plugin = new SBTPlugin($endpoints[0]['name']); $plugin->createHeader(); }
/** * Tests whether settings are saved correctly by simulating post * requests using mock data. */ function test_endpoint_save_settings() { // Load mock data require 'mock_data.php'; if (!class_exists('SBTEndpointUpdate')) { require BASE_PATH . '/controllers/SBTEndpointUpdate.php'; } // Fake post request - populate it with mock data $_POST['endpoint_name'] = $config['wp_endpoint_2_name']; $_POST['endpoint_url'] = $config['wp_endpoint_2_url']; $_POST['consumer_key'] = $config['wp_endpoint_2_consumer_key']; $_POST['consumer_secret'] = $config['wp_endpoint_2_consumer_secret']; $_POST['authorization_url'] = $config['wp_endpoint_2_authorization_url']; $_POST['access_token_url'] = $config['wp_endpoint_2_access_token_url']; $_POST['request_token_url'] = $config['wp_endpoint_2_request_token_url']; $_POST['authentication_method'] = $config['wp_endpoint_2_authentication_method']; $_POST['basic_auth_username'] = $config['wp_endpoint_2_basic_auth_username']; $_POST['basic_auth_password'] = $config['wp_endpoint_2_basic_auth_password']; $_POST['basic_auth_method'] = $config['wp_endpoint_2_basic_auth_method']; $_POST['sdk_deploy_url'] = $config['sdk_deploy_url']; $_POST['delete_endpoint'] = 'no'; $_POST['libraries_list'] = $config['js_library']; // Update the endpoint $update = new SBTEndpointUpdate(); // Load settings if (!class_exists('SBTSettings')) { require BASE_PATH . '/core/models/SBTSettings.php'; } $settings = new SBTSettings(); // Check that settings have been saved $this->assertEquals($config['wp_endpoint_2_name'], $settings->getName()); $this->assertEquals($config['wp_endpoint_2_url'], $settings->getURL()); $this->assertEquals($config['wp_endpoint_2_consumer_key'], $settings->getConsumerKey()); $this->assertEquals($config['wp_endpoint_2_consumer_secret'], $settings->getConsumerSecret()); $this->assertEquals($config['wp_endpoint_2_authorization_url'], $settings->getAuthorizationURL()); $this->assertEquals($config['wp_endpoint_2_access_token_url'], $settings->getAccessTokenURL()); $this->assertEquals($config['wp_endpoint_2_request_token_url'], $settings->getRequestTokenURL()); $this->assertEquals($config['wp_endpoint_2_authentication_method'], $settings->getAuthenticationMethod()); $this->assertEquals($config['wp_endpoint_2_basic_auth_username'], $settings->getBasicAuthUsername()); $this->assertEquals($config['wp_endpoint_2_basic_auth_password'], $settings->getBasicAuthPassword()); $this->assertEquals($config['wp_endpoint_2_basic_auth_method'], $settings->getBasicAuthMethod()); $this->assertEquals($config['sdk_deploy_url'], $settings->getSDKDeployURL()); $this->assertEquals($config['js_library'], $settings->getJSLibrary()); // Now delete the endpoint $_POST['delete_endpoint'] = 'yes'; // Perform update $update = new SBTEndpointUpdate(); // Make sure that the endpoint has been deleted $settings = new SBTSettings(); $this->assertNotEquals($config['wp_endpoint_2_name'], $settings->getName()); }
function test_js_libraries() { // Load mock data require 'mock_data.php'; // Load settings if (!class_exists('SBTSettings')) { require BASE_PATH . '/core/models/SBTSettings.php'; } $settings = new SBTSettings(); $libs = $config['js_libraries']; foreach ($libs as $lib) { $viewData['deploy_url'] = $settings->getSDKDeployURL(); $viewData['authentication_method'] = $settings->getAuthenticationMethod(); $viewData['js_library'] = $lib; $viewData['url'] = $settings->getURL(); $viewData['name'] = $settings->getName(); $file = '../views/includes/header.php'; @(include $file); } }
/** * Creates the header for the SBTK plugin. */ public function createHeader() { $this->loadModel('SBTSettings'); $settings = new SBTSettings(); $viewData['deploy_url'] = $settings->getSDKDeployURL($this->endpointName); $viewData['authentication_method'] = $settings->getAuthenticationMethod($this->endpointName); $viewData['js_library'] = $settings->getJSLibrary($this->endpointName); $viewData['url'] = $settings->getURL($this->endpointName); $viewData['name'] = $settings->getName($this->endpointName); $viewData['api_version'] = $settings->getAPIVersion($this->endpointName); $viewData['type'] = $settings->getServerType($this->endpointName); $viewData['allow_client_access'] = $settings->allowClientAccess($this->endpointName); $viewData['endpoints'] = $settings->getEndpoints(); // Load the header view return $this->loadView('includes/header', $viewData); }