Пример #1
0
 function testSend()
 {
     $client = new DemocracyInAction_Client();
     list($status, $data) = $client->send(authentication_url(), array('email' => test_user(), 'password' => test_pass()), 'post');
     $this->assertWantedPattern('/Successful Login/', $data);
     $url = 'https://' . test_node() . '/api/getObjects.sjs';
     list($status, $data) = $client->send($url, array('object' => 'supporter', 'limit' => 1));
     $this->assertWantedPattern('/organization_KEY="1"/', $data);
 }
Пример #2
0
 function testValidCredentials()
 {
     list($status, $data) = post(authentication_url(), array('email' => test_user(), 'password' => test_pass()));
     #has an interesting status code
     $this->assertEqual($status, 200);
     #has interesting success message
     $this->assertWantedPattern('/Successful Login/', $data);
     #looks like we expect
     $expected = file_get_contents(dirname(__FILE__) . '/../fixtures/auth/valid.xml');
     $this->assertEqual($data, $expected);
 }
Пример #3
0
function authenticated_curl_handle()
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
    $temp_file = tempnam(sys_get_temp_dir(), 'DIA');
    curl_setopt($ch, CURLOPT_COOKIEFILE, $temp_file);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $temp_file);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, authentication_url());
    curl_setopt($ch, CURLOPT_POSTFIELDS, "email=" . test_user() . "&password=" . test_pass());
    $data = curl_exec($ch);
    return $ch;
}
Пример #4
0
}
?>
</div>


<?php 
if (pb_backupbuddy::_POST('skip_database_import') == '1' && pb_backupbuddy::_POST('skip_database_migration') == '1') {
    $fatal_error = false;
    echo '<br><span class="pb_label pb_label-info">Important</span> Database import & migration set to be skipped based on advanced options. Any failures ignored.<br><br>';
}
?>


<div class="test" style="border-bottom: 0;">
	<div class="test_status">
		<?php 
if (false === $fatal_error) {
    test_pass();
} else {
    test_fail();
}
?>
	</div>
	<?php 
if (false !== $fatal_error) {
    echo '<div class="test_title"><b>Overall result failure. Correct errors and re-test.</b></div>';
} else {
    echo '<div class="test_title"><b>Overall result success. Proceed to next step.</b></div>';
}
?>
</div>
Пример #5
0
function run_test($test_name, $script_file, $output_file, $error_file)
{
    global $php_exe, $result_dir;
    $error = '';
    $message = '';
    # The 'done flag' file is used to determine if a script did exit(),
    # or just returned/fell off the end like it should.
    # This was originally added to detect exit() from inside the library.
    $done_file = $result_dir . DIRECTORY_SEPARATOR . $test_name . '.zzz';
    @unlink($done_file);
    # We need to run the script, then touch the 'done_file', to be able
    # to check for exit().
    # Force error reporting level to the highest value for the tests.
    $phpcmd = "error_reporting(E_ALL|E_STRICT); require '{$script_file}'; " . "touch('{$done_file}');";
    $cmd = "{$php_exe} -r \"{$phpcmd}\"";
    # Run the test command. False return means abort, True means the
    # the script ran (although it might have failed, or be a skipped test).
    $start_time = microtime(TRUE);
    if (!run_command($cmd, $script_file, $output_file, $error_file, $error, $rval)) {
        test_fail($test_name, $error);
        return;
    }
    $runtime = microtime(TRUE) - $start_time;
    # Check for skipped test:
    if ($rval == 2) {
        # Ignore $error from run_command, as this was not a test error.
        # Get skip reason from stdout - it should be one short line.
        $message = "  " . check_file($output_file);
        test_skip($test_name, $message, $runtime);
        @unlink($done_file);
        # Cleanup
        check_file($error_file);
        # Cleanup
        return;
    }
    # If $error is not empty, it represents a return status.
    if (!empty($error)) {
        $message .= $error;
    }
    # Output file might be an image, or text.
    # If image, rename, else if text, capture it and show it.
    # Remember if it made an image file, for validation.
    if (rename_imagefile($output_file)) {
        $output_text = '';
        $made_image_file = True;
    } else {
        $output_text = check_file($output_file);
        if (!empty($output_text)) {
            $message .= "Test standard output:\n------\n" . $output_text . "\n======\n";
        }
        $made_image_file = False;
    }
    # Collect error output.
    $error_text = check_file($error_file);
    if (!empty($error_text)) {
        $message .= "Test error output:\n------\n" . $error_text . "\n======\n";
    }
    # Get the validation data for the test. (This warns if there isn't any,
    # then provides the defaults.)
    $vd = get_test_validation($test_name);
    # Validate the test based on the configuration settings:
    $failures = array();
    # Was it supposed to make an image, and did it?
    if ($vd['create_image'] && !$made_image_file) {
        $failures[] = "Didn't make an image file";
    } elseif (!$vd['create_image'] && $made_image_file) {
        $failures[] = "Made an unexpected image file";
    }
    # Was the exit status as expected?
    if ($vd['exit_ok'] && $rval != 0) {
        $failures[] = "Expected successful return but got error return";
    } elseif ($vd['exit_error'] && $rval == 0) {
        $failures[] = "Expected error return but got succesful return";
    }
    # Was anything written to standard error?
    if ($vd['stderr_empty'] && !empty($error_text)) {
        $failures[] = "Unexpected output written to standard error stream";
    }
    # Does its standard error text match the pattern, if provided?
    # Note: Delimeter is \x01. Modifiers are: i (case insensitive),
    # and s (let . match newline, for multiline spanned matches).
    if (!empty($vd['stderr_match']) && !preg_match("{$vd['stderr_match']}is", $error_text)) {
        $failures[] = "Standard error did not match the expected text";
    }
    # Does its standard output text match the pattern, if provided?
    # (Note this will always be empty if create_image is True.)
    if (!empty($vd['stdout_match']) && !preg_match("{$vd['stdout_match']}is", $output_text)) {
        $failures[] = "Standard output did not match the expected text";
    }
    # Check for 'done' flag file to make sure it didn't exit inside.
    # But only report it as a failure if the test was expected to exit OK.
    if (file_exists($done_file)) {
        unlink($done_file);
    } elseif ($vd['exit_ok']) {
        $failures[] = "Script exited and did not return properly";
    }
    # Final test status:
    if (empty($failures)) {
        test_pass($test_name, $message, $runtime);
    } else {
        test_fail($test_name, $message . "Validation failure(s):\n - " . implode("\n - ", $failures), $runtime);
    }
}