OpenFlyers SSO WordPress plugin 1.2.0
Read the member name and email from a custom report (profile_report_id).
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
<?php
|
||||
|
||||
// Command-line only: this script rewrites settings and accounts, it must never run from a web request.
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit;
|
||||
}
|
||||
/**
|
||||
* Smoke test for the WordPress plugin protocol client, run outside WordPress.
|
||||
* Checks the HTTP signature generation and the response verification (Digest + Signature)
|
||||
@@ -180,5 +175,54 @@ check('an HTML certificate refusal is reported as a failure', $result === false)
|
||||
check('it is recognized as a certificate problem', $client->getLastErrorCode() === 'ssl_certificate_error');
|
||||
check('the reason reaches the error message', strpos($client->getLastError(), 'SSL certificate error') !== false);
|
||||
|
||||
// --- member report (name and e-mail) ------------------------------------------
|
||||
// Body exactly as the OpenFlyers resource server returns a custom report: the CSV text, JSON encoded.
|
||||
$reportBody = '"first_name;last_name;email\nÉlodie;D\'Artagnan;elodie.test@example.org\n"';
|
||||
$reportResp = "HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n" . $reportBody;
|
||||
$csv = $parse->invoke($client, $reportResp, $config['resource_uri'], false);
|
||||
check('a report response is decoded to its CSV text', is_string($csv) && strpos($csv, 'first_name;') === 0);
|
||||
|
||||
$row = OF_SSO_Client::parseReportCsv($csv);
|
||||
check('the report row is keyed by column name', $row === array('first_name' => 'Élodie', 'last_name' => "D'Artagnan", 'email' => 'elodie.test@example.org'));
|
||||
check('a report without data row gives an empty row', OF_SSO_Client::parseReportCsv("first_name;last_name;email\n") === array());
|
||||
check('an empty report gives an empty row', OF_SSO_Client::parseReportCsv("\n") === array());
|
||||
check('a row that does not match the header is ignored', OF_SSO_Client::parseReportCsv("first_name;last_name\nA;B;C\n") === array());
|
||||
|
||||
/**
|
||||
* Client whose report call is answered locally, to check the mapping to WordPress fields.
|
||||
*/
|
||||
class OF_SSO_Report_Stub_Client extends OF_SSO_Client
|
||||
{
|
||||
public $answer;
|
||||
public $lastCall;
|
||||
|
||||
public function getReport(array $token, $reportId, $resourceType = 'report', array $replacementList = array())
|
||||
{
|
||||
$this->lastCall = array($reportId, $resourceType, $replacementList);
|
||||
return $this->answer;
|
||||
}
|
||||
}
|
||||
|
||||
$stub = new OF_SSO_Report_Stub_Client($config);
|
||||
$stub->answer = $csv;
|
||||
$profile = $stub->getMemberProfile(array('access_token' => 'abc'), 12, 24);
|
||||
check('the report is called without any member identifier', $stub->lastCall === array(12, 'report', array()));
|
||||
check('the profile maps to WordPress fields', $profile === array(
|
||||
'first_name' => 'Élodie',
|
||||
'last_name' => "D'Artagnan",
|
||||
'user_email' => 'elodie.test@example.org',
|
||||
'display_name' => "Élodie D'Artagnan",
|
||||
));
|
||||
|
||||
$stub->answer = "first_name;last_name;email\nJean;MARTIN;\n";
|
||||
$profile = $stub->getMemberProfile(array('access_token' => 'abc'), 12, 25);
|
||||
check('an empty e-mail is left out', $profile === array('first_name' => 'Jean', 'last_name' => 'MARTIN', 'display_name' => 'Jean MARTIN'));
|
||||
|
||||
$stub->answer = "first_name;last_name;email\n";
|
||||
check('a member missing from the report is a failure', $stub->getMemberProfile(array('access_token' => 'abc'), 12, 26) === false);
|
||||
|
||||
$stub->answer = false;
|
||||
check('a refused report call is a failure', $stub->getMemberProfile(array('access_token' => 'abc'), 12, 24) === false);
|
||||
|
||||
echo $fail === 0 ? "\nAll checks passed.\n" : "\n$fail check(s) failed.\n";
|
||||
exit($fail === 0 ? 0 : 1);
|
||||
|
||||
Reference in New Issue
Block a user