function test_wl_configuration_analyzer_url()
 {
     // Set the WordLift Key.
     $wordlift_key = uniqid();
     wl_configuration_set_key($wordlift_key);
     $this->assertEquals(WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key={$wordlift_key}", wl_configuration_get_analyzer_url());
     // Set the Redlink Key.
     $redlink_key = uniqid();
     $redlink_application_name = uniqid();
     $redlink_api_url = uniqid();
     wl_configuration_set_key('');
     wl_configuration_set_redlink_key($redlink_key);
     wl_configuration_set_redlink_application_name($redlink_application_name);
     wl_configuration_set_api_url($redlink_api_url);
     $this->assertStringStartsWith("{$redlink_api_url}/analysis/{$redlink_application_name}/enhance?key={$redlink_key}", wl_configuration_get_analyzer_url());
 }
Beispiel #2
0
/**
 * Configure WordPress with the test settings (may vary according to the local PHP and WordPress versions).
 */
function wl_configure_wordpress_test()
{
    add_filter('wl_write_log_handler', 'wl_test_get_write_log_handler');
    do_action('activate_wordlift/wordlift.php');
    // If the WordLift key is set, then we'll configure it, otherwise we configure Redlink.
    if (false !== getenv('WORDLIFT_KEY')) {
        // When setting the WordLift Key, the Redlink dataset URI is provisioned by WordLift Server.
        wl_configuration_set_key(getenv('WORDLIFT_KEY'));
        if ('' === wl_configuration_get_redlink_dataset_uri()) {
            die('The Redlink dataset URI is not set (maybe the WordLift key is not valid?)');
        }
    } else {
        // TODO: remove this part.
        // or use Redlink.
        // Set the dataset name to the specified dataset or define it based on the current environment.
        $dataset_name = false !== getenv('REDLINK_DATASET_NAME') ? getenv('REDLINK_DATASET_NAME') : str_replace('.', '-', sprintf('%s-php-%s.%s-wp-%s-ms-%s', 'wordlift-tests', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, getenv('WP_VERSION'), getenv('WP_MULTISITE')));
        $app_name = false !== getenv('REDLINK_APP_NAME') ? getenv('REDLINK_APP_NAME') : 'wordlift';
        // Check that the API_URL env is set.
        if (false === getenv('API_URL')) {
            die('The API_URL environment variable is not set.');
        }
        wl_configuration_set_redlink_key(getenv('REDLINK_APP_KEY'));
        wl_configuration_set_redlink_user_id(getenv('REDLINK_USER_ID'));
        wl_configuration_set_api_url(getenv('API_URL'));
        wl_configuration_set_redlink_dataset_name($dataset_name);
        wl_configuration_set_redlink_application_name($app_name);
        wl_configuration_set_redlink_dataset_uri('http://data.redlink.io/' . getenv('REDLINK_USER_ID') . '/' . $dataset_name);
    }
}