Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a screen reader user. Note: It should not be the image file name.
Alternative Text (Alt Text) is an alternative (non-visual) way to describe the meaning of an image. Please provide a brief (under 100 characters) description of the image for a screen reader user. Note: It should not be the image file name.
',
],
[
@@ -244,7 +244,7 @@
'title' => 'Avoid using color alone for emphasis',
'desc' => '
When emphasizing text, you may use color with sufficient contrast as long as you also apply some other form of emphasis, such as bold or italics. This ensures that screen reader users are aware of the text\'s importance.
This example shows how to use the em and strong elements to emphasize text. The em and strong elements were designed to indicate structural emphasis that may be rendered in a variety of ways (font style changes, speech inflection changes, etc.).
diff --git a/lib/Udoit.php b/lib/Udoit.php
index 11a0b20ec..a0bce8fc9 100755
--- a/lib/Udoit.php
+++ b/lib/Udoit.php
@@ -17,19 +17,20 @@
*
* Primary Author Contact: Jacob Bates
*/
-require_once(__DIR__.'/../config/settings.php');
-require_once(__DIR__.'/quail/quail/quail.php');
use Httpful\Request;
-class Udoit {
+class Udoit
+{
/**
* Retrieves an entire group of content by type and scans it
* @param string api_key - API Key of the user were acting as
* @param string content_type - The group of content types we'll retrieve EX: 'pages' or 'assignments'
+ *
* @return array - Results of the scan
*/
- public static function retrieveAndScan($api_key, $canvas_api_url, $course_id, $content_type){
+ public static function retrieveAndScan($api_key, $canvas_api_url, $course_id, $content_type)
+ {
$items_with_issues = [];
$totals = ['errors' => 0, 'warnings' => 0, 'suggestions' => 0];
$module_urls = [];
@@ -43,8 +44,10 @@ public static function retrieveAndScan($api_key, $canvas_api_url, $course_id, $c
$content['amount'] = count($content['items']);
// remove results w/o issues and count the totals
- foreach ($content['items'] as $item){
- if ($item['amount'] == 0) continue;
+ foreach ($content['items'] as $item) {
+ if ($item['amount'] == 0) {
+ continue;
+ }
$items_with_issues[] = $item;
$totals['errors'] += count($item['error']);
@@ -53,10 +56,10 @@ public static function retrieveAndScan($api_key, $canvas_api_url, $course_id, $c
}
// format results
- if ($content['module_urls']){
+ if ($content['module_urls']) {
$module_urls = array_merge($module_urls, $content['module_urls']);
}
- if ($content['unscannable']){
+ if ($content['unscannable']) {
$unscannables = array_merge($unscannables, $content['unscannable']);
}
@@ -69,24 +72,28 @@ public static function retrieveAndScan($api_key, $canvas_api_url, $course_id, $c
'title' => $content_type,
'items' => $items_with_issues,
'amount' => $content['amount'],
- 'time' => $content['time']
- ]
- ]
+ 'time' => $content['time'],
+ ],
+ ],
];
}
/**
* Calls the Quail library to generate a UDOIT report
* @param array $scanned_content - The items from whatever type of Canvas content was scanned
+ *
* @return array - The report results
*/
- public static function scanContent(Array $content_items) {
+ public static function scanContent(array $content_items)
+ {
+ require_once(__DIR__.'/quail/quail/quail.php');
$report = [];
// Runs each item through the Quail accessibility checker
foreach ($content_items as $item) {
-
- if (empty($item['content'])) continue;
+ if (empty($item['content'])) {
+ continue;
+ }
$quail = new quail($item['content'], 'wcag2aaa', 'string', 'static');
$quail->runCheck();
@@ -99,8 +106,9 @@ public static function scanContent(Array $content_items) {
// loop over the items returning from Quail
foreach ($quail_report['report'] as $quail_issue) {
-
- if (empty($quail_issue['severity_num'])) continue;
+ if (empty($quail_issue['severity_num'])) {
+ continue;
+ }
$issue_count++;
@@ -140,9 +148,11 @@ public static function scanContent(Array $content_items) {
* @param string $api_key - Api key for the user we're acting as
* @param string $canvas_api_url - Base uri for your canvas api
* @param string $type - The type of course content to be scanned
+ *
* @return array - The report results
*/
- public static function getCourseContent($api_key, $canvas_api_url, $course_id, $type) {
+ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $type)
+ {
global $logger;
$api_url = "{$canvas_api_url}/api/v1/courses/{$course_id}/";
@@ -162,7 +172,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $c->id,
'content' => $c->message,
'title' => $c->title,
- 'url' => $c->html_url
+ 'url' => $c->html_url,
];
}
break;
@@ -174,7 +184,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $c->id,
'content' => $c->description,
'title' => $c->name,
- 'url' => $c->html_url
+ 'url' => $c->html_url,
];
}
break;
@@ -186,7 +196,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $c->id,
'content' => $c->message,
'title' => $c->title,
- 'url' => $c->html_url
+ 'url' => $c->html_url,
];
}
break;
@@ -194,31 +204,33 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
case 'files':
$contents = static::apiGetAllLinks($api_key, "{$api_url}files?");
foreach ($contents as $c) {
- if (substr($c->display_name, 0, 2) == '._') continue;
+ if (substr($c->display_name, 0, 2) === '._') {
+ continue;
+ }
$extension = pathinfo($c->filename, PATHINFO_EXTENSION);
- if($c->size > 50000000) {
+ if ($c->size > 50000000) {
$content_result['unscannable'][] = [
'title' => $c->display_name,
'url' => $c->url,
- 'big' => true
- ];
+ 'big' => true,
+ ];
} else {
if (in_array($extension, ['html', 'htm'])) {
$content_result['items'][] = [
'id' => $c->id,
'content' => Request::get($c->url)->followRedirects()->expectsHtml()->send()->body,
'title' => $c->display_name,
- 'url' => $c->url
+ 'url' => $c->url,
];
}
// filters non html files
- if (in_array($extension, ['pdf', 'doc', 'docx', 'ppt', 'pptx'])){
+ if (in_array($extension, ['pdf', 'doc', 'docx', 'ppt', 'pptx'])) {
$content_result['unscannable'][] = [
'title' => $c->display_name,
'url' => $c->url,
- 'big' => false
+ 'big' => false,
];
}
}
@@ -235,7 +247,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $wiki_page->body->url,
'content' => $wiki_page->body->body,
'title' => $wiki_page->body->title,
- 'url' => $wiki_page->body->html_url
+ 'url' => $wiki_page->body->html_url,
];
}
break;
@@ -254,7 +266,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $c->id,
'external_url' => $c->external_url,
'title' => $c->title,
- 'url' => $c->html_url
+ 'url' => $c->html_url,
];
}
}
@@ -269,7 +281,7 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
'id' => $c->id,
'content' => $c->syllabus_body,
'title' => 'Syllabus',
- 'url' => "{$canvas_api_url}/courses/{$course_id}/assignments/syllabus"
+ 'url' => "{$canvas_api_url}/courses/{$course_id}/assignments/syllabus",
];
}
break;
@@ -279,7 +291,8 @@ public static function getCourseContent($api_key, $canvas_api_url, $course_id, $
}
// get every page from the Canvas API till there's none left
- protected static function apiGetAllLinks($api_key, $url){
+ protected static function apiGetAllLinks($api_key, $url)
+ {
global $logger;
$limit = 500;
$per_page = 100;
@@ -289,13 +302,20 @@ protected static function apiGetAllLinks($api_key, $url){
$req_url = "{$url}page=1&per_page={$per_page}&access_token={$api_key}";
$logger->addInfo("Requesting {$req_url}");
$response = Request::get($req_url)->send();
- if($response->status > 400){
+ if ($response->status > 400) {
$logger->addError("Error response from {$req_url}");
break;
}
+
$links = static::apiParseLinks($response->headers->toArray()['link']);
- foreach ($response->body as $thing) $results[] = $thing;
- if (isset($links['next'])) $url = "{$links['next']}&access_token={$api_key}";
+ foreach ($response->body as $thing) {
+ $results[] = $thing;
+ }
+
+ if (isset($links['next'])) {
+ $url = "{$links['next']}&access_token={$api_key}";
+ }
+
usleep(250000); // 1/4 sec
} while (isset($links['next']) && $cur_page < $limit);
@@ -305,9 +325,11 @@ protected static function apiGetAllLinks($api_key, $url){
/**
* Parses pagination links returned from Canvas
* @param string $links - The pagination links
+ *
* @return array - An array of the separated links
*/
- protected static function apiParseLinks($links) {
+ protected static function apiParseLinks($links)
+ {
$links = explode(',', $links);
$pretty = [];
diff --git a/lib/UdoitDB.php b/lib/UdoitDB.php
index 857871aa9..1729cee49 100755
--- a/lib/UdoitDB.php
+++ b/lib/UdoitDB.php
@@ -18,7 +18,8 @@
* Primary Author Contact: Jacob Bates
*/
-class UdoitDB{
+class UdoitDB
+{
const TEST_EXPIRE_TIME = 5; // 5 seconds, may need to be adjusted
@@ -30,7 +31,8 @@ class UdoitDB{
private static $pdo = null;
private static $last_test_time = 0;
- public static function setup($db_type, $dsn, $db_user, $db_password){
+ public static function setup($db_type, $dsn, $db_user, $db_password)
+ {
static::$type = $db_type;
static::$user = $db_user;
static::$dsn = $dsn;
@@ -38,10 +40,11 @@ public static function setup($db_type, $dsn, $db_user, $db_password){
}
// acts as a pass through for pdo that checks the connection
- public static function __callStatic($name, $args){
+ public static function __callStatic($name, $args)
+ {
static::testAndReconnect();
// test to see if the method exists on pdo
- if ( ! method_exists(static::$pdo, $name)){
+ if (!method_exists(static::$pdo, $name)) {
throw new \RuntimeException("{$name} method does not exist on PDO object");
}
@@ -49,49 +52,64 @@ public static function __callStatic($name, $args){
return call_user_func_array([static::$pdo, $name], $args);
}
- public static function testAndReconnect($force_test = false){
+ public static function testAndReconnect($force_test = false)
+ {
// make sure we're still connected
- if ( ! static::test($force_test)) static::connect();
+ if (!static::test($force_test)) {
+ static::connect();
+ }
}
// runs a very basic query on the db to verify connection status
- public static function test($force = false){
- if(empty(static::$pdo)) return false;
+ public static function test($force = false)
+ {
+ if (empty(static::$pdo)) {
+ return false;
+ }
+
try {
$now = time();
// check if forced or the last test time expired
- if($force || (static::$last_test_time + self::TEST_EXPIRE_TIME) < $now){
+ if ($force || (static::$last_test_time + self::TEST_EXPIRE_TIME) < $now) {
static::$last_test_time = $now;
static::$pdo->query('SELECT version()');
}
+
return true;
} catch (\Exception $e) {
error_log("Database Test Connection Error");
error_log($e->getMessage());
+
return false;
}
}
- public static function disconnect(){
+ public static function disconnect()
+ {
static::$pdo = null; // there's no disconnect w/ pdo, it's cleaned up when garbage collected
}
- protected static function connect(){
+ protected static function connect()
+ {
try {
- switch(static::$type) {
+ switch (static::$type) {
case 'test':
$db = new PDO('sqlite::memory:');
break;
+
case 'pgsql':
- $db = new static::$dbClass(static::$dsn);
+ $db = new static::$dbClass(static::$dsn);
break;
+
case 'mysql':
$db = new static::$dbClass(static::$dsn, static::$user, static::$password);
break;
+
default:
throw new \RuntimeException("Database type ".static::$type." not supported.");
break;
}
+
static::$last_test_time = time();
static::$pdo = $db;
} catch (\RuntimeException $e) {
diff --git a/lib/UdoitJob.php b/lib/UdoitJob.php
index ebc0a15ea..09d6227aa 100644
--- a/lib/UdoitJob.php
+++ b/lib/UdoitJob.php
@@ -1,14 +1,17 @@
execute();
// RUN NOW if the background worker isn't enabled
- if ( ! static::$background_worker_enabled){
+ if (!static::$background_worker_enabled) {
static::runNextJob();
}
}
- public static function countJobsRemaining(){
+ public static function countJobsRemaining()
+ {
$sql = "SELECT COUNT(*) FROM job_queue WHERE status = 'new'";
$query = UdoitDB::query($sql);
+
return $query ? (int) $query->fetchColumn() : 0;
}
- public static function runNextJob() {
+ public static function runNextJob()
+ {
$job_failed = false;
try {
- if($job = static::getNextJob()) {
- if ($job->job_type === 'finalize_report') {
+ if ($job = static::getNextJob()) {
+ if ('finalize_report' === $job->job_type) {
$result = static::finalizeReport($job);
- }
- else {
+ } else {
$api_key = UdoitUtils::instance()->getValidRefreshedApiKey($job->user_id);
- if(empty($api_key)) throw new Exception("No valid api key for job"); // @TODO: mark job as unrunnable
+ if (empty($api_key)) {
+ throw new Exception("No valid api key for job"); // @TODO: mark job as unrunnable
+ }
$job_data = json_decode($job->data, true);
$canvas_api_url = $job_data['base_uri'];
$result = Udoit::retrieveAndScan($api_key, $canvas_api_url, $job_data['course_id'], $job_data['scan_item']);
@@ -54,18 +61,21 @@ public static function runNextJob() {
static::finishJobWithResults($job->id, $result);
}
- } catch(Exception $e) {
+ } catch (Exception $e) {
$job_failed = true;
global $logger;
$logger->addError($e->getMessage());
$logger->addError(print_r($job, true));
- if($job) self::updateJobStatus($job_record, 'error');
+ if ($job) {
+ self::updateJobStatus($job_record, 'error');
+ }
}
return $job_failed;
}
- protected static function finalizeReport($job) {
+ protected static function finalizeReport($job)
+ {
$report = static::combineJobResults($job->job_group);
$report['course'] = $job_data['course_title'];
$job_data = json_decode($job->data, true);
@@ -79,7 +89,9 @@ protected static function finalizeReport($job) {
(:userid, :courseid, :report_json, :errors, :suggestions)";
// if using postgres, ask to get the id back since lastInsertId won't work
- if(UdoitDB::$type === 'pgsql') $sql .= ' RETURNING id';
+ if ('pgsql' === UdoitDB::$type) {
+ $sql .= ' RETURNING id';
+ }
$sth = UdoitDB::prepare($sql);
$sth->bindValue(':userid', $job->user_id, PDO::PARAM_INT);
@@ -88,34 +100,32 @@ protected static function finalizeReport($job) {
$sth->bindValue(':errors', $report['total_results']['errors'], PDO::PARAM_STR);
$sth->bindValue(':suggestions', $report['total_results']['suggestions'], PDO::PARAM_STR);
- if ( ! $sth->execute()) {
+ if (!$sth->execute()) {
error_log(print_r($sth->errorInfo(), true));
throw new Exception('Error inserting report into database');
}
- if(UdoitDB::$type === 'pgsql'){
+ if ('pgsql' === UdoitDB::$type) {
$res = $sth->fetch(PDO::FETCH_ASSOC);
$report_id = $res['id'];
-
- }
- else{
+ } else {
$report_id = UdoitDB::lastInsertId();
}
return ['report_id' => $report_id ];
}
- protected static function combineJobResults($job_group) {
+ protected static function combineJobResults($job_group)
+ {
$totals = ['errors' => 0, 'warnings' => 0, 'suggestions' => 0];
- $module_urls = [];
+ $module_urls = [];
$unscannables = [];
- $content = [];
+ $content = [];
// combine the data from each job's results
$sql = "SELECT * FROM job_queue WHERE job_group = '{$job_group}' AND job_type != 'finalize_report'";
$rows = UdoitDB::query($sql)->fetchAll();
foreach ($rows as $row) {
-
$results = json_decode($row['results'], true);
$totals['errors'] += $results['total_results']['errors'];
@@ -123,11 +133,12 @@ protected static function combineJobResults($job_group) {
$totals['suggestions'] += $results['total_results']['suggestions'];
- if (!empty($results['scan_results']['module_urls'])){
+ if (!empty($results['scan_results']['module_urls'])) {
$module_urls = array_merge($module_urls, $results['scan_results']['module_urls']);
}
- if (!empty($results['scan_results']['unscannable'])){
- $unscannables = array_merge($unscannables , $results['scan_results']['unscannable']);
+
+ if (!empty($results['scan_results']['unscannable'])) {
+ $unscannables = array_merge($unscannables, $results['scan_results']['unscannable']);
}
unset($results['module_urls']);
@@ -157,23 +168,30 @@ protected static function combineJobResults($job_group) {
];
}
- protected static function getNextJob() {
+ protected static function getNextJob()
+ {
// it's important that this claims the next job, not allowing other processes to grab it.
// we LOCK this row using 'FOR UPDATE' then update it's status so other queries don't find it
UdoitDB::beginTransaction();
$sql = "SELECT * FROM job_queue WHERE status = 'new'";
- if(UdoitDB::$type !== 'test') $sql .= " FOR UPDATE"; // SQLITE doesn't support SELECT... FOR UPDATE
- if( ! ($query = UdoitDB::query($sql))) return false; // return false if theres nothing
+ if ('test' !== UdoitDB::$type) {
+ $sql .= " FOR UPDATE"; // SQLITE doesn't support SELECT... FOR UPDATE
+ }
+ if (!($query = UdoitDB::query($sql))) {
+ return false; // return false if theres nothing
+ }
$job = $query->fetchObject();
$sql = "UPDATE job_queue SET status = 'running' WHERE id = '{$job->id}' AND status = 'new'";
UdoitDB::query($sql);
UdoitDB::commit();
+
return $job;
}
- protected static function finishJobWithResults($job_id, $result) {
- $sql ="UPDATE job_queue SET status = :status, results = :results, date_completed = CURRENT_TIMESTAMP WHERE id = :job_id";
+ protected static function finishJobWithResults($job_id, $result)
+ {
+ $sql = "UPDATE job_queue SET status = :status, results = :results, date_completed = CURRENT_TIMESTAMP WHERE id = :job_id";
$sth = UdoitDB::prepare($sql);
$sth->bindValue(':job_id', $job_id);
$sth->bindValue(':status', 'finished');
@@ -181,7 +199,8 @@ protected static function finishJobWithResults($job_id, $result) {
$sth->execute();
}
- protected static function updateJobStatus($job, $status) {
+ protected static function updateJobStatus($job, $status)
+ {
$sql = "UPDATE job_queue SET status = '{$status}' WHERE id = {$job->id}";
UdoitDB::query($sql);
}
diff --git a/lib/UdoitUtils.php b/lib/UdoitUtils.php
index 47158fc88..ba2a40f43 100644
--- a/lib/UdoitUtils.php
+++ b/lib/UdoitUtils.php
@@ -38,12 +38,17 @@ class UdoitUtils
private static $instance;
- public static function instance(){
- if(!isset(self::$instance)) self::$instance = new UdoitUtils();
+ public static function instance()
+ {
+ if (!isset(self::$instance)) {
+ self::$instance = new UdoitUtils();
+ }
+
return self::$instance;
}
- public static function setupOauth($id, $key, $uri, $consumer_key, $secret){
+ public static function setupOauth($id, $key, $uri, $consumer_key, $secret)
+ {
self::$canvas_oauth_id = $id;
self::$canvas_oauth_key = $key;
self::$canvas_oauth_uri = $uri;
@@ -54,75 +59,81 @@ public static function setupOauth($id, $key, $uri, $consumer_key, $secret){
public function getYouTubeId($link_url)
{
$matches = null;
- foreach(self::$regex as $pattern) {
+ foreach (self::$regex as $pattern) {
if (preg_match($pattern, $link_url, $matches)) {
return $matches[1];
}
}
+
return null;
}
- public function exitWithPageError($error) {
+ public function exitWithPageError($error)
+ {
$templates = new League\Plates\Engine(__DIR__.'/../templates');
echo($templates->render('error', ['error' => $error]));
error_log($error);
exit();
}
- public function exitWithPartialError($error) {
+ public function exitWithPartialError($error)
+ {
$templates = new League\Plates\Engine(__DIR__.'/../templates');
echo($templates->render('partials/error', ['error' => $error]));
error_log($error);
exit();
}
- protected function curlOauthToken($base_url, $post_data) {
- // @TODO - why not use Httpful here?
- $ch = curl_init("{$base_url}/login/oauth2/token");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch);
- curl_close($ch);
-
- return json_decode($result);
- }
-
- public function getLocalApiKey($user_id){
+ public function getLocalApiKey($user_id)
+ {
global $db_user_table;
$sth = UdoitDB::prepare("SELECT api_key, canvas_url FROM {$db_user_table} WHERE id = :userid LIMIT 1");
$sth->bindValue(':userid', $user_id, PDO::PARAM_INT);
$sth->execute();
- if ($result = $sth->fetchObject()){
+ if ($result = $sth->fetchObject()) {
self::$canvas_base_url = $result->canvas_url;
+
return $result->api_key;
}
+
return false;
}
- public function getValidRefreshedApiKey($user_id){
+ public function getValidRefreshedApiKey($user_id)
+ {
// check our db for an existing api key
$api_key = UdoitUtils::instance()->getLocalApiKey($user_id);
- if( ! empty($api_key)){
- if(UdoitUtils::instance()->validateApiKey($user_id, $api_key)) return $api_key;
- if($api_key = UdoitUtils::instance()->refreshApiKey($user_id)) return $api_key;
+ if (!empty($api_key)) {
+ if (UdoitUtils::instance()->validateApiKey($user_id, $api_key)) {
+ return $api_key;
+ }
+ if ($api_key = UdoitUtils::instance()->refreshApiKey($user_id)) {
+ return $api_key;
+ }
}
+
return false;
}
- public function validateApiKey($user_id, $api_key) {
+ public function validateApiKey($user_id, $api_key)
+ {
global $UDOIT_ENV;
- if(empty($user_id) || empty($api_key)) return false;
+ if (empty($user_id) || empty($api_key)) {
+ return false;
+ }
// return false for testing
- if ($UDOIT_ENV !== ENV_PROD) return false;
+ if (ENV_PROD !== $UDOIT_ENV) {
+ return false;
+ }
// @TODO use self
$url = self::$canvas_base_url."api/v1/users/{$user_id}/profile";
$resp = Httpful\Request::get($url)
->addHeader('Authorization', "Bearer {$api_key}")
->send();
+
return isset($resp->body->id);
}
@@ -131,59 +142,70 @@ public function getRefreshToken($user_id)
{
global $db_user_table;
- if ($UDOIT_ENV !== ENV_PROD) return "test-token"; // return false for testing
+ if (ENV_PROD !== $UDOIT_ENV) {
+ return "test-token"; // return false for testing
+ }
$sth = UdoitDB::prepare("SELECT refresh_token FROM {$db_user_table} WHERE id = :userid LIMIT 1");
$sth->bindValue(':userid', $user_id, PDO::PARAM_INT);
$sth->execute();
- if ($result = $sth->fetchObject()) return $result->refresh_token;
+ if ($result = $sth->fetchObject()) {
+ return $result->refresh_token;
+ }
+
return false;
}
- public function refreshApiKey($user_id) {
+ public function refreshApiKey($user_id)
+ {
global $UDOIT_ENV;
global $db_user_table;
$refresh_token = $this->getRefreshToken($user_id);
- if( ! $refresh_token) return false;
+ if (!$refresh_token) {
+ return false;
+ }
$post_data = [
'grant_type' => 'refresh_token',
'client_id' => self::$canvas_oauth_id,
'redirect_uri' => self::$canvas_oauth_uri,
'client_secret' => self::$canvas_oauth_key,
- 'refresh_token' => $refresh_token
+ 'refresh_token' => $refresh_token,
];
$json_result = $this->curlOauthToken(self::$canvas_base_url, $post_data);
// update the token in the database
- if(isset($json_result->access_token) && $this->validateApiKey($user_id, $json_result->access_token)){
+ if (isset($json_result->access_token) && $this->validateApiKey($user_id, $json_result->access_token)) {
$sth = UdoitDB::prepare("UPDATE {$db_user_table} set api_key = :api_key, refresh_token = :refresh_token WHERE id = :userid LIMIT 1");
$sth->bindValue(':userid', $userID, PDO::PARAM_INT);
$sth->bindValue(':api_key', $json_result->access_token, PDO::PARAM_STR);
$sth->bindValue(':refresh_token', $json_result->refresh_token, PDO::PARAM_STR);
$sth->execute();
+
return $json_result->access_token;
}
return false;
}
- public function authorizeNewApiKey($base_url, $code) {
+ public function authorizeNewApiKey($base_url, $code)
+ {
$post_data = [
'grant_type' => 'authorization_code',
'client_id' => self::$canvas_oauth_id,
'redirect_uri' => self::$canvas_oauth_uri,
'client_secret' => self::$canvas_oauth_key,
- 'code' => $code
+ 'code' => $code,
];
return $this->curlOauthToken($base_url, $post_data);
}
- public function createOrUpdateUser($user_id, $api_key, $refresh_token, $canvas_url){
+ public function createOrUpdateUser($user_id, $api_key, $refresh_token, $canvas_url)
+ {
global $db_user_table;
$sth = UdoitDB::prepare("SELECT * FROM {$db_user_table} WHERE id = :userid AND canvas_url = :canvas_url LIMIT 1");
@@ -205,9 +227,24 @@ public function createOrUpdateUser($user_id, $api_key, $refresh_token, $canvas_u
return $sth->execute();
}
- public function verifyBasicLTILaunch(){
+ public function verifyBasicLTILaunch()
+ {
require_once(__DIR__.'/ims-blti/blti.php');
$context = new BLTI(self::$canvas_consumer_key, self::$canvas_secret_key, false, false);
+
return isset($context->valid) && $context->valid;
}
+
+ protected function curlOauthToken($base_url, $post_data)
+ {
+ // @TODO - why not use Httpful here?
+ $ch = curl_init("{$base_url}/login/oauth2/token");
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ $result = curl_exec($ch);
+ curl_close($ch);
+
+ return json_decode($result);
+ }
}
diff --git a/lib/Ufixit.php b/lib/Ufixit.php
index 2ee3ad98a..ae4f44e21 100755
--- a/lib/Ufixit.php
+++ b/lib/Ufixit.php
@@ -17,7 +17,6 @@
*
* Primary Author Contact: Jacob Bates
*/
-require_once(__DIR__.'/quail/quail/quail.php');
use Httpful\Request;
use zz\Html\HTMLMinify;
@@ -80,7 +79,7 @@ class Ufixit
/**
* How many times str_replace should do the job
- * @var integer
+ * @var int
*/
public $replacement_count = 1;
@@ -102,11 +101,12 @@ public function __construct($data)
* @param string $error_html - The bad html that needs to be fixed
* @param string $new_content - The new content from the user
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_img - The image with new alt text
*/
public function fixAltText($error_html, $new_content, $submitting_again = false)
{
- $this->dom->loadHTML('' . $error_html);
+ $this->dom->loadHTML("{$error_html}");
$imgs = $this->dom->getElementsByTagName('img');
$fixed_img = null;
@@ -129,6 +129,7 @@ public function fixAltText($error_html, $new_content, $submitting_again = false)
* @param bool $bold - Boolean whether resulting text should be stylized bold
* @param bool $italic - Boolean whether resulting text should be stylized italicised
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_css - The html with corrected CSS
*/
public function fixCssColor($error_html, $new_content, $bold, $italic, $submitting_again = false)
@@ -136,18 +137,18 @@ public function fixCssColor($error_html, $new_content, $bold, $italic, $submitti
preg_match_all('/<(\w+)\s+\w+.*?>/s', $error_html, $matches);
$fixed_css = $error_html;
-
+
$fixed_css = preg_replace('/background:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/background-color:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/color:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/font-weight:\s*([a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/font-style:\s*([a-z0-9]*)\s*;*\s*/', '', $fixed_css);
- $fixed_css = preg_replace('/style="/', 'style="background-color: ' . $new_content[0] . '; color: ' . $new_content[1] . ';', $fixed_css);
+ $fixed_css = preg_replace('/style="/', 'style="background-color: '.$new_content[0].'; color: '.$new_content[1].';', $fixed_css);
+
+ $this->dom->loadHTML(''.$fixed_css);
- $this->dom->loadHTML('' . $fixed_css );
+ $tag = $this->dom->getElementsByTagName($matches[1][0])->item(0);
- $tag = $this->dom->getElementsByTagName( $matches[1][0] )->item(0);
-
if ($bold) {
$tag->setAttribute('style', $tag->getAttribute('style').' font-weight: bold;');
} else {
@@ -161,6 +162,7 @@ public function fixCssColor($error_html, $new_content, $bold, $italic, $submitti
}
$fixed_css = $this->dom->saveHTML($tag);
+
return $fixed_css;
}
@@ -171,6 +173,7 @@ public function fixCssColor($error_html, $new_content, $bold, $italic, $submitti
* @param bool $bold - Boolean whether resulting text should be stylized bold
* @param bool $italic - Boolean whether resulting text should be stylized italicised
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_css - The html with corrected CSS
*/
public function fixCssEmphasize($error_html, $bold, $italic, $remove_color, $submitting_again = false)
@@ -179,15 +182,15 @@ public function fixCssEmphasize($error_html, $bold, $italic, $remove_color, $sub
$fixed_css = $error_html;
- if($remove_color) {
+ if ($remove_color) {
$fixed_css = preg_replace('/background:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/background-color:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
$fixed_css = preg_replace('/color:\s*([#a-z0-9]*)\s*;*\s*/', '', $fixed_css);
}
- $this->dom->loadHTML('' . $fixed_css );
+ $this->dom->loadHTML(''.$fixed_css);
- $tag = $this->dom->getElementsByTagName( $matches[1][0] )->item(0);
+ $tag = $this->dom->getElementsByTagName($matches[1][0])->item(0);
if ($bold) {
$tag->setAttribute('style', $tag->getAttribute('style').' font-weight: bold;');
@@ -211,20 +214,21 @@ public function fixCssEmphasize($error_html, $bold, $italic, $remove_color, $sub
* @param string $error_html - The bad html that needs to be fixed
* @param string|array $new_content - The new Heading text from the user
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_css - The html with corrected Link
*/
public function fixLink($error_html, $new_content, $submitting_again = false)
{
$fixed_link = '';
- if ($new_content == '') {
+ if ('' === $new_content) {
return $fixed_link;
}
- $this->dom->loadHTML('' . $error_html);
+ $this->dom->loadHTML(''.$error_html);
$tag = $this->dom->getElementsByTagName('a')->item(0);
- $linkText = $this->dom->createTextNode( htmlspecialchars($new_content) );
+ $linkText = $this->dom->createTextNode(htmlspecialchars($new_content));
$tag->nodeValue = "";
$tag->appendChild($linkText);
@@ -239,23 +243,24 @@ public function fixLink($error_html, $new_content, $submitting_again = false)
* @param string $error_html - The bad html that needs to be fixed
* @param string|array $new_content - The new Heading text from the user
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_heading - The html with corrected Heading
*/
public function fixHeading($error_html, $new_content, $submitting_again = false)
{
$fixed_heading = '';
- if ($new_content == '') {
+ if ('' === $new_content) {
return $fixed_heading;
}
- $matches = array();
+ $matches = [];
preg_match('/h[0-6]/i', $error_html, $matches);
- $this->dom->loadHTML('' . $error_html);
+ $this->dom->loadHTML(''.$error_html);
- $tag = $this->dom->getElementsByTagName( $matches[0] )->item(0);
+ $tag = $this->dom->getElementsByTagName($matches[0])->item(0);
- $headingText = $this->dom->createTextNode( htmlspecialchars($new_content) );
+ $headingText = $this->dom->createTextNode(htmlspecialchars($new_content));
$tag->appendChild($headingText);
@@ -269,17 +274,17 @@ public function fixHeading($error_html, $new_content, $submitting_again = false)
* @param string $error_html - The unmodified table without proper headings
* @param string $selected_header - The selected table row or column
* @param boolean $submitting_again - If the user is resubmitting their error fix
+ *
* @return array $new_data - Array of the corrected error and the original table row/column
*/
public function fixTableHeaders($error_html, $selected_header, $submitting_again = false)
{
-
$new_data = [
'old' => '',
- 'fixed' => ''
+ 'fixed' => '',
];
- $this->dom->loadHTML('' . $error_html);
+ $this->dom->loadHTML(''.$error_html);
switch ($selected_header) {
case 'col':
@@ -297,8 +302,8 @@ public function fixTableHeaders($error_html, $selected_header, $submitting_again
$new_data['fixed'] .= $this->dom->saveHTML($tr);
}
-
break;
+
case 'row':
$tr = $this->dom->getElementsByTagName('tr')->item(0);
$new_data['old'] = $this->dom->saveHTML($tr);
@@ -314,8 +319,8 @@ public function fixTableHeaders($error_html, $selected_header, $submitting_again
}
$new_data['fixed'] = $this->dom->saveHTML($tr);
-
break;
+
case 'both':
$first = true;
$trs = $this->dom->getElementsByTagName('tr');
@@ -361,11 +366,12 @@ public function fixTableHeaders($error_html, $selected_header, $submitting_again
* @param string $error_html - The color(s) that need to be replaced
* @param string $new_content - The new CSS color(s) from the user
* @param bool $submitting_again - If the user is resubmitting their error fix
+ *
* @return string $fixed_ths - The html with corrected th scopes
*/
public function fixTableThScopes($error_html, $new_content, $submitting_again = false)
{
- $this->dom->loadHTML('' . $error_html);
+ $this->dom->loadHTML(''.$error_html);
$ths = $this->dom->getElementsByTagName('th');
@@ -389,7 +395,7 @@ public function getFile($start_id)
$folder = Request::get($folder_uri)->send();
$curled_file = [];
- if ($start_id == "root") {
+ if ("root" === $start_id) {
$start_id = $folder->body->id;
}
@@ -411,7 +417,7 @@ public function getFile($start_id)
foreach ($files->body as $file) {
$mac_check = (substr($file->display_name, 0, 2)); // Don't capture mac files, ._
- if ($mac_check !== "._" and $file->id == $this->content_id) {
+ if ("._" !== $mac_check and $this->content_id == $file->id) {
$curled_file['id'] = $file->id;
$curled_file['name'] = $file->display_name;
$curled_file['parent_folder_path'] = $folder_name;
@@ -423,17 +429,14 @@ public function getFile($start_id)
$page_num++;
}
-
} //if there are files in the current folder
if ($num_folders > 0) {
$subfolders = Request::get($this->base_uri."/api/v1/folders/".$start_id."/folders?access_token=".$this->api_key)->send();
foreach ($subfolders->body as $subfolder) {
- $foo = $this->getFile($subfolder->id);
-
- if ($foo !== false) {
- return $foo;
+ if ($file = $this->getFile($subfolder->id)) {
+ return $file;
}
}
} //if there are subfolders
@@ -445,6 +448,7 @@ public function getFile($start_id)
* Renames an element and preserves its attributes
* @param object $node - The DOMElement object you wish to rename
* @param string $name - The new name for the element
+ *
* @return object - The renamed DOMElement
*/
public function renameElement($node, $name)
@@ -466,8 +470,9 @@ public function renameElement($node, $name)
if (!is_null($attribute->namespaceURI)) {
$renamed->setAttributeNS('http://www.w3.org/2000/xmlns/',
- 'xmlns:'.$attribute->prefix,
- $attribute->namespaceURI);
+ 'xmlns:'.$attribute->prefix,
+ $attribute->namespaceURI
+ );
}
$renamed->setAttributeNode($attribute);
@@ -483,6 +488,7 @@ public function renameElement($node, $name)
* @param string $html - html from page being edited
* @param string $error - original html of error being fixed
* @param string $corrected - resulting html or error after fix
+ *
* @return string $html - html after corrected html has replaced error html
*/
public function replaceContent($html, $error, $corrected)
@@ -533,6 +539,7 @@ public function uploadFixedDiscussions($corrected_error, $error_html)
* [uploadFixedFiles description]
* @param [type] $corrected_error [description]
* @param [type] $error_html [description]
+ *
* @return [type] [description]
*/
public function uploadFixedFiles($corrected_error, $error_html)
@@ -565,7 +572,7 @@ public function uploadFixedFiles($corrected_error, $error_html)
'size' => filesize($file),
'content_type' => "text/html",
'parent_folder_path' => $this->curled_file['parent_folder_path'],
- 'on_duplicate' => "overwrite"
+ 'on_duplicate' => "overwrite",
];
$uri = $this->base_uri."/api/v1/courses/".$this->course_id."/files?&access_token=".$this->api_key;
@@ -576,7 +583,7 @@ public function uploadFixedFiles($corrected_error, $error_html)
$upload_uri = $response->upload_url;
//send everything again
- $post_data = (array)$response->upload_params;
+ $post_data = (array) $response->upload_params;
$f = fopen($file, "r");
$post_data['file'] = fread($f, filesize($file));
@@ -587,7 +594,7 @@ public function uploadFixedFiles($corrected_error, $error_html)
preg_match('/Location\: (.*)\\n/', $response->raw_headers, $matches);
//error
- if ( ! isset($matches[1])) {
+ if (!isset($matches[1])) {
error_log(print_r($response, true));
}
@@ -619,8 +626,7 @@ public function uploadFixedPages($corrected_error, $error_html)
// get the current page content
$get_uri = "{$this->base_uri}/api/v1/courses/{$this->course_id}/pages/{$this->content_id}?access_token={$this->api_key}";
$page_resp = Request::get($get_uri)->send();
- if($page_resp->hasErrors() || ! $page_resp->hasBody())
- {
+ if ($page_resp->hasErrors() || !$page_resp->hasBody()) {
throw new \Exception("Error getting page to update: course: {$this->course_id} page: {$this->content_id}");
}
@@ -630,8 +636,7 @@ public function uploadFixedPages($corrected_error, $error_html)
$put_uri = "{$this->base_uri}/api/v1/courses/{$this->course_id}/pages/{$this->content_id}?&access_token={$this->api_key}";
$put_resp = Request::put($put_uri)->body(['wiki_page[body]' => $html])->sendsType(\Httpful\Mime::FORM)->send();
- if($put_resp->hasErrors() || ! $put_resp->hasBody())
- {
+ if ($put_resp->hasErrors() || !$put_resp->hasBody()) {
throw new \Exception("Error updating: course: {$this->course_id} page: {$this->content_id}");
}
}
diff --git a/lib/worker.php b/lib/worker.php
index 94bf129f4..40b738277 100644
--- a/lib/worker.php
+++ b/lib/worker.php
@@ -19,24 +19,21 @@
*/
require_once(__DIR__.'/../config/settings.php');
-if (php_sapi_name() !== "cli"){
+if (php_sapi_name() !== "cli") {
$logger->addError('This worker can only be run on the command line.');
echo('This worker can only be run on the command line.');
}
-while(true)
-{
+while (true) {
// run the next job
UdoitJob::runNextJob();
// take a nap if there's no more work to do
- if(UdoitJob::countJobsRemaining() < 1)
- {
+ if (UdoitJob::countJobsRemaining() < 1) {
$logger->addInfo('Worker Sleeping');
UdoitDB::disconnect(); // allow the db to disconnect
sleep($worker_sleep_seconds);
- }
- else{
+ } else {
sleep(1);
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 000000000..0090d0221
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,129 @@
+
+
+ The UCFCDL coding standard based.
+
+
+
+
+
+
+
+
+
+
+
+ */vendor/*
+ */lib/quail/*
+ */ims-blti/*
+ */templates/*
+ public/udoit.xml.php
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+ 0
+
+
+
+ warning
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+
+ 0
+
+
+
+ warning
+
+
+
+ error
+
+
+
+ error
+
+
+
+ 0
+
+
+
+ There should always be a description, followed by a blank line, before the tags of a class comment.
+
+
+
+
+
diff --git a/public/assets/js/default.js b/public/assets/js/default.js
index 7c57b8293..023fd4afb 100755
--- a/public/assets/js/default.js
+++ b/public/assets/js/default.js
@@ -33,7 +33,7 @@ function killButton(callback) {
});
}
- $('#udoitForm button.submit').removeClass('disabled').html('Scan This Course');
+ $('#udoitForm button.submit').removeClass('disabled').html('Scan This Course Again');
$('#waitMsg').fadeOut();
diff --git a/public/cached.php b/public/cached.php
index 19f4471d5..63d54f665 100755
--- a/public/cached.php
+++ b/public/cached.php
@@ -1,21 +1,21 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
require_once('../config/settings.php');
@@ -27,22 +27,22 @@
session_write_close();
if (!$sth->execute()) {
- UdoitUtils::instance()->exitWithError('Could not complete database query');
+ UdoitUtils::instance()->exitWithError('Could not complete database query');
}
$reports = $sth->fetchAll();
// Add the test report if not in production mode
-if ($UDOIT_ENV != ENV_PROD) {
- $reports[] = [
- 'id' => 'TEST',
- 'user_id' => 0,
- 'course_id' => 'TEST',
- 'file_path' => 'reports/test.json',
- 'date_run' => 'TEST: 1998 (when section 508 was ammended)',
- 'errors' => 64,
- 'suggestions' => 32
- ];
+if (ENV_PROD !== $UDOIT_ENV) {
+ $reports[] = [
+ 'id' => 'TEST',
+ 'user_id' => 0,
+ 'course_id' => 'TEST',
+ 'file_path' => 'reports/test.json',
+ 'date_run' => 'TEST: 1998 (when section 508 was ammended)',
+ 'errors' => 64,
+ 'suggestions' => 32,
+ ];
}
$templates = new League\Plates\Engine(__DIR__.'/../templates');
diff --git a/public/index.php b/public/index.php
index b910d233c..a30776925 100755
--- a/public/index.php
+++ b/public/index.php
@@ -1,21 +1,21 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
require_once(__DIR__.'/../config/settings.php');
@@ -27,16 +27,16 @@
print_r($post_input);
// verify we have the variables we need from the LTI launch
-$expect = ['oauth_consumer_key','custom_canvas_api_domain','custom_canvas_user_id','custom_canvas_course_id'];
+$expect = ['oauth_consumer_key', 'custom_canvas_api_domain', 'custom_canvas_user_id', 'custom_canvas_course_id'];
foreach ($expect as $key) {
- if(empty($post_input[$key])){
- UdoitUtils::instance()->exitWithPageError("Missing LTI launch information. Please ensure that your instance of UDOIT is installed to Canvas correctly. Missing: {$key}");
- }
+ if (empty($post_input[$key])) {
+ UdoitUtils::instance()->exitWithPageError("Missing LTI launch information. Please ensure that your instance of UDOIT is installed to Canvas correctly. Missing: {$key}");
+ }
}
// verify LTI launch
-if ( ! UdoitUtils::instance()->verifyBasicLTILaunch()) {
- UdoitUtils::instance()->exitWithPageError('LTI/Oauth verification problem, please ensure that your instance of UDOIT is configured correctly.');
+if (!UdoitUtils::instance()->verifyBasicLTILaunch()) {
+ UdoitUtils::instance()->exitWithPageError('LTI/Oauth verification problem, please ensure that your instance of UDOIT is configured correctly.');
}
// store LTI launch variables
@@ -45,10 +45,10 @@
UdoitUtils::$canvas_base_url = "https://{$post_input['custom_canvas_api_domain']}/";
$_SESSION['base_url'] = UdoitUtils::$canvas_base_url;
$_SESSION['launch_params'] = [
- 'custom_canvas_user_id' => $post_input['custom_canvas_user_id'],
- 'custom_canvas_course_id' => $post_input['custom_canvas_course_id'],
- 'context_label' => $post_input['context_label'],
- 'context_title' => $post_input['context_title'],
+ 'custom_canvas_user_id' => $post_input['custom_canvas_user_id'],
+ 'custom_canvas_course_id' => $post_input['custom_canvas_course_id'],
+ 'context_label' => $post_input['context_label'],
+ 'context_title' => $post_input['context_title'],
];
$api_key = UdoitUtils::instance()->getValidRefreshedApiKey($user_id);
diff --git a/public/oauth2response.php b/public/oauth2response.php
index 3eedc307e..679ba5e9f 100755
--- a/public/oauth2response.php
+++ b/public/oauth2response.php
@@ -1,45 +1,45 @@
-.
-*
-* Primary Author Contact: Jacob Bates
-*/
-require_once('../config/settings.php');
-
-$get_input = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); // Sanitize $_GET global
-
-if (isset($get_input['error'])) {
- UdoitUtils::instance()->exitWithPageError('Authentication problem: Access Denied.');
-}
-
-if ( ! isset($get_input['code'])) {
- UdoitUtils::instance()->exitWithPageError('Authentication problem, please ensure that your instance of UDOIT is configured correctly.');
-}
-
-session_start();
-// get session variables
-$canvas_user_id = $_SESSION['launch_params']['custom_canvas_user_id'];
-$canvas_uri = $_SESSION['base_url'];
-$new_key = UdoitUtils::instance()->authorizeNewApiKey($canvas_uri, $get_input['code']);
-
-// It should have access_token and refresh_token
-if ( ! isset($new_key->access_token) || ! isset($new_key->refresh_token)) {
- UdoitUtils::instance()->exitWithPageError('Authentication problem: Please contact support.');
-}
-
-UdoitUtils::instance()->createOrUpdateUser($canvas_user_id, $new_key->access_token, $new_key->refresh_token, $canvas_uri);
-
-header('Location: scanner.php');
+.
+*
+* Primary Author Contact: Jacob Bates
+*/
+require_once('../config/settings.php');
+
+$get_input = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); // Sanitize $_GET global
+
+if (isset($get_input['error'])) {
+ UdoitUtils::instance()->exitWithPageError('Authentication problem: Access Denied.');
+}
+
+if (!isset($get_input['code'])) {
+ UdoitUtils::instance()->exitWithPageError('Authentication problem, please ensure that your instance of UDOIT is configured correctly.');
+}
+
+session_start();
+// get session variables
+$canvas_user_id = $_SESSION['launch_params']['custom_canvas_user_id'];
+$canvas_uri = $_SESSION['base_url'];
+$new_key = UdoitUtils::instance()->authorizeNewApiKey($canvas_uri, $get_input['code']);
+
+// It should have access_token and refresh_token
+if (!isset($new_key->access_token) || !isset($new_key->refresh_token)) {
+ UdoitUtils::instance()->exitWithPageError('Authentication problem: Please contact support.');
+}
+
+UdoitUtils::instance()->createOrUpdateUser($canvas_user_id, $new_key->access_token, $new_key->refresh_token, $canvas_uri);
+
+header('Location: scanner.php');
diff --git a/public/parsePdf.php b/public/parsePdf.php
index 24b635ddb..607401c3e 100755
--- a/public/parsePdf.php
+++ b/public/parsePdf.php
@@ -1,21 +1,21 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
require_once('../config/settings.php');
diff --git a/public/parsePdfProgress.php b/public/parsePdfProgress.php
index c18b39528..e7a2814a3 100755
--- a/public/parsePdfProgress.php
+++ b/public/parsePdfProgress.php
@@ -1,21 +1,21 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
session_start();
UdoitUtils::$canvas_base_url = $_SESSION['base_url'];
diff --git a/public/parseResults.php b/public/parseResults.php
index aa866645e..798e726d8 100755
--- a/public/parseResults.php
+++ b/public/parseResults.php
@@ -1,44 +1,46 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
require_once('../config/settings.php');
$get_input = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
-if ( ! isset($get_input['path'])) $get_input['path'] = '';
+if (!isset($get_input['path'])) {
+ $get_input['path'] = '';
+}
// Load the test report in test/dev mode and no other report is selected
-if ($UDOIT_ENV !== ENV_PROD && !isset($get_input['report_id'])) {
- $get_input['report_id'] = 'TEST'; // TEST is the id of the test report
+if (ENV_PROD !== $UDOIT_ENV && !isset($get_input['report_id'])) {
+ $get_input['report_id'] = 'TEST'; // TEST is the id of the test report
}
// @TODO: make sure this user's got a session
-if ( ! isset($get_input['report_id'])) {
- UdoitUtils::instance()->exitWithPartialError('No report requested');
+if (!isset($get_input['report_id'])) {
+ UdoitUtils::instance()->exitWithPartialError('No report requested');
}
$sth = UdoitDB::prepare("SELECT * FROM {$db_reports_table} WHERE id = :report_id");
$sth->bindValue(':report_id', $get_input['report_id'], PDO::PARAM_INT);
-if ( ! $sth->execute()) {
- error_log(print_r($sth->errorInfo(), true));
- UdoitUtils::instance()->exitWithPartialError('Error searching for report');
+if (!$sth->execute()) {
+ error_log(print_r($sth->errorInfo(), true));
+ UdoitUtils::instance()->exitWithPartialError('Error searching for report');
}
$report_json = $sth->fetch(PDO::FETCH_OBJ)->report_json;
@@ -46,18 +48,18 @@
$report = json_decode($report_json);
if (is_null($report)) {
- $json_error = json_last_error_msg();
- UdoitUtils::instance()->exitWithPartialError("Cannot parse this report. JSON error $json_error.");
+ $json_error = json_last_error_msg();
+ UdoitUtils::instance()->exitWithPartialError("Cannot parse this report. JSON error {$json_error}.");
}
$results = [
- 'course' => $report->course,
- 'error_count' => $report->total_results->errors,
- 'suggestion_count' => $report->total_results->suggestions,
- 'report_groups' => $report->content,
- 'post_path' => $get_input['path'],
- 'fixable_error_types' => ["cssTextHasContrast", "imgNonDecorativeHasAlt", "tableDataShouldHaveTh", "tableThShouldHaveScope", "headersHaveText", "aMustContainText", "imgAltIsDifferent", "imgAltIsTooLong"],
- 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize"]
+ 'course' => $report->course,
+ 'error_count' => $report->total_results->errors,
+ 'suggestion_count' => $report->total_results->suggestions,
+ 'report_groups' => $report->content,
+ 'post_path' => $get_input['path'],
+ 'fixable_error_types' => ["cssTextHasContrast", "imgNonDecorativeHasAlt", "tableDataShouldHaveTh", "tableThShouldHaveScope", "headersHaveText", "aMustContainText", "imgAltIsDifferent", "imgAltIsTooLong"],
+ 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize"],
];
diff --git a/public/process.php b/public/process.php
index c82f1a62e..6c1e80480 100755
--- a/public/process.php
+++ b/public/process.php
@@ -29,7 +29,7 @@
$main_action = filter_input(INPUT_POST, 'main_action', FILTER_SANITIZE_STRING);
switch ($main_action) {
case 'udoit':
- if ($UDOIT_ENV != ENV_PROD) {
+ if (ENV_PROD !== $UDOIT_ENV) {
require 'parseResults.php';
exit();
}
@@ -40,7 +40,7 @@
$job_group = uniqid('job_', true); // uniqid for this group of jobs
// No content selected
- if ($content == 'none') {
+ if ('none' === $content) {
UdoitUtils::instance()->exitWithPartialError('Please select which course content you wish to scan above.');
}
@@ -50,7 +50,7 @@
'base_uri' => $base_url,
'title' => $title,
'course_id' => $course_id,
- 'scan_item' => $scan_item
+ 'scan_item' => $scan_item,
];
// create an id to group all these jobs together
@@ -69,7 +69,6 @@
break;
case 'ufixit':
-
$data = [
'base_uri' => $base_url,
'content_id' => filter_input(INPUT_POST, 'contentid', FILTER_SANITIZE_STRING),
@@ -80,12 +79,12 @@
'italic' => (filter_input(INPUT_POST, 'add-italic', FILTER_SANITIZE_STRING) == 'italic'),
'remove_color' => (filter_input(INPUT_POST, 'remove-color', FILTER_SANITIZE_STRING) == 'true'),
'course_id' => filter_input(INPUT_POST, 'course_id', FILTER_SANITIZE_NUMBER_INT),
- 'api_key' => UdoitUtils::instance()->getLocalApiKey($user_id)
+ 'api_key' => UdoitUtils::instance()->getLocalApiKey($user_id),
];
$ufixit = new Ufixit($data);
- if (strtolower($data['content_type']) == 'files') {
+ if (strtolower($data['content_type']) === 'files') {
$ufixit->curled_file = $ufixit->getFile("root");
if ($ufixit->curled_file == false) {
diff --git a/public/progress.php b/public/progress.php
index 79b8b28f2..4c0f8abc2 100755
--- a/public/progress.php
+++ b/public/progress.php
@@ -1,61 +1,60 @@
-.
-*
-* Primary Author Contact: Jacob Bates
-*/
-
-require_once('../config/settings.php');
-
-session_start();
-$user_id = $_SESSION['launch_params']['custom_canvas_user_id'];
-UdoitUtils::$canvas_base_url = $_SESSION['base_url'];
-session_write_close();
-
-$job_group = filter_input(INPUT_GET, 'job_group', FILTER_SANITIZE_STRING);
-
-// get the non-finalize jobs
-$sth = UdoitDB::prepare("SELECT id, data, job_type, status FROM job_queue WHERE job_type != 'finalize_report' AND job_group = :job_group AND user_id = :user_id");
-$sth->bindValue(":job_group", $job_group);
-$sth->bindValue(":user_id", $user_id);
-$sth->execute();
-$jobs = $sth->fetchAll();
-
-// get the finalize job (this is done in 2 queries so we don't have to retrieve the results from the non-final jobs)
-$sth = UdoitDB::prepare("SELECT * FROM job_queue WHERE job_type = 'finalize_report' AND job_group = :job_group AND user_id = :user_id");
-$sth->bindValue(":job_group", $job_group);
-$sth->bindValue(":user_id", $user_id);
-$sth->execute();
-$final_job = $sth->fetch();
-$final_job['results'] = json_decode($final_job['results'], true);
-
-$job_status = [];
-foreach ($jobs as $job)
-{
- $json = json_decode($job['data'], true);
- $job_status[] = [
- 'type' => $json['scan_item'],
- 'status' => $job['status']
- ];
-}
-
-$result = [
- 'reportID' => isset($final_job['results']['report_id']) ? $final_job['results']['report_id'] : null,
- 'status' => $final_job['status'],
- 'jobs' => $job_status
-];
-
-echo(json_encode($result));
+.
+*
+* Primary Author Contact: Jacob Bates
+*/
+
+require_once('../config/settings.php');
+
+session_start();
+$user_id = $_SESSION['launch_params']['custom_canvas_user_id'];
+UdoitUtils::$canvas_base_url = $_SESSION['base_url'];
+session_write_close();
+
+$job_group = filter_input(INPUT_GET, 'job_group', FILTER_SANITIZE_STRING);
+
+// get the non-finalize jobs
+$sth = UdoitDB::prepare("SELECT id, data, job_type, status FROM job_queue WHERE job_type != 'finalize_report' AND job_group = :job_group AND user_id = :user_id");
+$sth->bindValue(":job_group", $job_group);
+$sth->bindValue(":user_id", $user_id);
+$sth->execute();
+$jobs = $sth->fetchAll();
+
+// get the finalize job (this is done in 2 queries so we don't have to retrieve the results from the non-final jobs)
+$sth = UdoitDB::prepare("SELECT * FROM job_queue WHERE job_type = 'finalize_report' AND job_group = :job_group AND user_id = :user_id");
+$sth->bindValue(":job_group", $job_group);
+$sth->bindValue(":user_id", $user_id);
+$sth->execute();
+$final_job = $sth->fetch();
+$final_job['results'] = json_decode($final_job['results'], true);
+
+$job_status = [];
+foreach ($jobs as $job) {
+ $json = json_decode($job['data'], true);
+ $job_status[] = [
+ 'type' => $json['scan_item'],
+ 'status' => $job['status'],
+ ];
+}
+
+$result = [
+ 'reportID' => isset($final_job['results']['report_id']) ? $final_job['results']['report_id'] : null,
+ 'status' => $final_job['status'],
+ 'jobs' => $job_status,
+];
+
+echo(json_encode($result));
diff --git a/public/scanner.php b/public/scanner.php
index 711d85840..bbf2d1658 100644
--- a/public/scanner.php
+++ b/public/scanner.php
@@ -1,21 +1,21 @@
.
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
*
-* Primary Author Contact: Jacob Bates
+* Primary Author Contact: Jacob Bates
*/
// This page is the landing page for LTI launches from canvas
@@ -35,22 +35,22 @@
$post_input['custom_canvas_course_id'] = filter_input(INPUT_POST, 'custom_canvas_course_id', FILTER_SANITIZE_NUMBER_INT);
// verify we have the variables we need from the LTI launch
-$expect = ['base_url','launch_params',];
+$expect = ['base_url', 'launch_params', ];
foreach ($expect as $key) {
- if(empty($_SESSION[$key])){
- UdoitUtils::instance()->exitWithPageError("Missing Session information. Please refresh the page. Missing: {$key}");
- }
+ if (empty($_SESSION[$key])) {
+ UdoitUtils::instance()->exitWithPageError("Missing Session information. Please refresh the page. Missing: {$key}");
+ }
}
UdoitUtils::$canvas_base_url = $_SESSION['base_url'];
// display the scanner page
$template_data = [
- 'base_url' => $_SESSION['base_url'],
- 'welcome_message' => $udoit_welcome_message,
- 'disclaimer_message' => $udoit_disclaimer_message,
- 'launch_params' => $_SESSION['launch_params'],
- 'udoit_tests' => include(__DIR__.'/../config/tests.php')
+ 'base_url' => $_SESSION['base_url'],
+ 'welcome_message' => $udoit_welcome_message,
+ 'disclaimer_message' => $udoit_disclaimer_message,
+ 'launch_params' => $_SESSION['launch_params'],
+ 'udoit_tests' => include(__DIR__.'/../config/tests.php'),
];
$templates = new League\Plates\Engine(__DIR__.'/../templates');
diff --git a/tests/BaseTest.php b/tests/BaseTest.php
index fbd34d418..da9867aa1 100644
--- a/tests/BaseTest.php
+++ b/tests/BaseTest.php
@@ -18,39 +18,37 @@
* Primary Author Contact: Jacob Bates
*/
-class MockObj {
- function __call($name, $args) {
- if (is_callable($this->$name)) {
- array_unshift($args, $this);
- return call_user_func_array($this->$name, $args);
- }
- }
-}
-
-class BaseTest extends PHPUnit_Framework_TestCase{
+class BaseTest extends PHPUnit_Framework_TestCase
+{
- protected static function getPrivateStaticPropertyValue($class, $prop){
+ protected static function getPrivateStaticPropertyValue($class, $prop)
+ {
$class = new ReflectionClass($class);
$p = $class->getProperty($prop);
$p->setAccessible(true);
+
return $p->getValue();
}
- protected static function callProtectedStaticMethod($class, $method){
+ protected static function callProtectedStaticMethod($class, $method)
+ {
$refClass = new ReflectionClass($class);
$refMethod = $refClass->getMethod($method);
$refMethod->setAccessible(true);
+
return $refMethod->invokeArgs(null, array_slice(func_get_args(), 2));
}
- protected static function setPrivateStaticPropertyValue($class, $prop, $value){
+ protected static function setPrivateStaticPropertyValue($class, $prop, $value)
+ {
$class = new ReflectionClass($class);
$p = $class->getProperty($prop);
$p->setAccessible(true);
$p->setValue($value);
}
- protected static function clearMockDBConnection(){
+ protected static function clearMockDBConnection()
+ {
self::setPrivateStaticPropertyValue('UdoitDB', 'dbClass', 'PDO');
self::setPrivateStaticPropertyValue('UdoitDB', 'type', null);
self::setPrivateStaticPropertyValue('UdoitDB', 'user', null);
@@ -60,10 +58,13 @@ protected static function clearMockDBConnection(){
self::setPrivateStaticPropertyValue('UdoitDB', 'pdo', null);
}
- protected static function assertPDOStatementBindValueCalled($stmt, $key, $value){
+ protected static function assertPDOStatementBindValueCalled($stmt, $key, $value)
+ {
$found = [];
foreach ($stmt->bind_value_calls as $call) {
- if ($call[0] == $key) $found = $call;
+ if ($call[0] == $key) {
+ $found = $call;
+ }
}
self::assertGreaterThanOrEqual(2, count($found), "Statement not found for $key");
self::assertEquals($key, $found[0]);
@@ -75,13 +76,15 @@ protected static function assertPDOStatementBindValueCalled($stmt, $key, $value)
* both arguments incriment the return value on each call
* First call returns $header_to_array_returns[0] and body_returns[0]
* Yea, this is pretty cryptic and nested, mocking chained function calls php is gnarly
+ * @return Object Mock Get Object created by Request::get()
*/
- protected static function mockGetRequestResult(Array $header_to_array_returns, Array $body_returns){
+ protected static function mockGetRequestResult(array $header_to_array_returns, array $body_returns)
+ {
$called = -1;
// mock *get()* from Httpful\Request::get()
$mock_get = new MockObj();
// mock *send()* from Httpful\Request::get()->send()
- $mock_get->send = $mock_send = function() use(&$called, $header_to_array_returns, $body_returns) {
+ $mock_get->send = $mock_send = function () use (&$called, $header_to_array_returns, $body_returns) {
$called++;
// mock *$response* from $response = Httpful\Request::get()->send()
$mock_response = new MockObj();
@@ -90,31 +93,33 @@ protected static function mockGetRequestResult(Array $header_to_array_returns, A
// mock *headers* from Httpful\Request::get()->send()->headers
$mock_response->headers = new MockObj();
// mock *toArray()* from Httpful\Request::get()->send()->headers->toArray()
- $mock_response->headers->toArray = function() use(&$called, $header_to_array_returns) {
+ $mock_response->headers->toArray = function () use (&$called, $header_to_array_returns) {
return $header_to_array_returns[$called];
};
$mock_response->body = $body_returns[$called];
+
return $mock_response;
- };
+ };
- // mock *followRedirects()* on Httpful\Request::get()->followRedirects()
- $mock_get->followRedirects = function() use(&$mock_send ) {
+ // mock *followRedirects()* on Httpful\Request::get()->followRedirects()
+ $mock_get->followRedirects = function () use (&$mock_send) {
$m = new MockObj();
// mock *expectsHtml()* on Httpful\Request::get()->followRedirects()->expectsHtml()
- $m->expectsHtml = function() use(&$mock_send) {
+ $m->expectsHtml = function () use (&$mock_send) {
// mock *send()* on Httpful\Request::get()->followRedirects()->expectsHtml()->send()
$m = new MockObj();
$m->send = $mock_send;
+
return $m;
};
+
return $m;
};
- $mock_get->addHeader = function() use(&$mock_get){
+ $mock_get->addHeader = function () use (&$mock_get) {
return $mock_get;
};
- return $mock_get;
+ return $mock_get;
}
-
}
diff --git a/tests/FunctionalTests.php b/tests/FunctionalTests.php
index 2cdc27a5a..5d865e182 100644
--- a/tests/FunctionalTests.php
+++ b/tests/FunctionalTests.php
@@ -30,7 +30,8 @@ class FunctionalTests extends PHPUnit_Framework_TestCase
* @group functional
* Tests the youtube api call to make sure a video with captions is detected as having captions
*/
- public function testYouTubeAPIHasCaptions() {
+ public function testYouTubeAPIHasCaptions()
+ {
$vid_url = 'https://www.youtube.com/watch?v=zo6aRvf-l_s';
$yt_service = new youtubeService();
@@ -43,7 +44,8 @@ public function testYouTubeAPIHasCaptions() {
* @group functional
* Tests the youtube api call to make sure a video without captions is detected as not having captions
*/
- public function testYouTubeAPINoCaptions() {
+ public function testYouTubeAPINoCaptions()
+ {
$vid_url = 'https://www.youtube.com/watch?v=nBH89Y0Xj7c';
$yt_service = new youtubeService();
diff --git a/tests/IndexTest.php b/tests/IndexTest.php
index 5517ff3df..5eda68bda 100644
--- a/tests/IndexTest.php
+++ b/tests/IndexTest.php
@@ -19,18 +19,21 @@
*/
class IndexTest extends BaseTest
{
- protected function setUp() {
+ protected function setUp()
+ {
UdoitDB::setup('test', 'b', 'c', 'd');
include(__DIR__.'/../bin/db_create_tables.php');
Mockery::close();
}
- protected function tearDown(){
+ protected function tearDown()
+ {
UdoitDB::disconnect();
Mockery::close();
}
- public function testApiParseLinksParsesLinkHeadersCorrectly() {
+ public function testApiParseLinksParsesLinkHeadersCorrectly()
+ {
// $_POST = [];
// $_POST['custom_canvas_user_id'] = 'adff';
// $_POST['custom_canvas_course_id'] = 'adff';
@@ -43,4 +46,4 @@ public function testApiParseLinksParsesLinkHeadersCorrectly() {
// $buffer = ob_get_clean();
// self::assertContains('UDOIT Accessibility Checker', $buffer);
}
-}
\ No newline at end of file
+}
diff --git a/tests/MockObj.php b/tests/MockObj.php
new file mode 100644
index 000000000..9b4cc34d8
--- /dev/null
+++ b/tests/MockObj.php
@@ -0,0 +1,31 @@
+.
+*
+* Primary Author Contact: Jacob Bates
+*/
+
+class MockObj
+{
+ public function __call($name, $args)
+ {
+ if (is_callable($this->$name)) {
+ array_unshift($args, $this);
+
+ return call_user_func_array($this->$name, $args);
+ }
+ }
+}
diff --git a/tests/PDOMock.php b/tests/PDOMock.php
new file mode 100644
index 000000000..73ba276e0
--- /dev/null
+++ b/tests/PDOMock.php
@@ -0,0 +1,77 @@
+.
+*
+* Primary Author Contact: Jacob Bates
+*/
+
+class PDOMock extends \PDO
+{
+
+ public $constructor_args = [];
+ public $query_calls = [];
+ public $prepare_calls = [];
+ public $begin_transaction_calls = [];
+ public $commit_calls = [];
+ public $statements = [];
+ public $query_returns_data = false;
+ public static $next_fetch_return = null;
+
+ public function __construct()
+ {
+ $this->constructor_args = func_get_args();
+ }
+
+ public function query()
+ {
+ $this->query_calls[] = func_get_args();
+ if ($this->query_returns_data) {
+ return self::$next_fetch_return;
+ }
+
+ return $this->_newStatement();
+ }
+
+ public function prepare($statement, $options = null)
+ {
+ $this->prepare_calls[] = func_get_args();
+
+ return $this->_newStatement();
+ }
+
+ public function beginTransaction()
+ {
+ $this->begin_transaction_calls[] = func_get_args();
+ }
+
+ public function commit()
+ {
+ $this->commit_calls[] = func_get_args();
+ }
+
+ public function nextFetchReturns($value)
+ {
+ self::$next_fetch_return = $value;
+ }
+
+ protected function _newStatement()
+ {
+ $stmt = new PDOStatementMock();
+ $this->statements[] = $stmt;
+
+ return $stmt;
+ }
+}
diff --git a/tests/PDOStatementMock.php b/tests/PDOStatementMock.php
new file mode 100644
index 000000000..6b242131b
--- /dev/null
+++ b/tests/PDOStatementMock.php
@@ -0,0 +1,61 @@
+.
+*
+* Primary Author Contact: Jacob Bates
+*/
+
+class PDOStatementMock extends \PDOStatement
+{
+
+ public $bind_value_calls = [];
+ public $execute_calls = [];
+
+ public function bindValue($paramno, $param, $type = null)
+ {
+ $this->bind_value_calls[] = func_get_args();
+ }
+
+ public function execute($bound_input_params = null)
+ {
+ $this->execute_calls[] = func_get_args();
+
+ return true;
+ }
+
+ public function fetchColumn($column_number = null)
+ {
+ return $this->mockFetch();
+ }
+
+ public function fetchObject($class_name = null, $ctor_args = null)
+ {
+ return $this->mockFetch();
+ }
+
+ public function next()
+ {
+ return $this->mockFetch();
+ }
+
+ protected function mockFetch()
+ {
+ $val = PDOMock::$next_fetch_return;
+ PDOMock::$next_fetch_return = null;
+
+ return $val;
+ }
+}
diff --git a/tests/UdoitDBTest.php b/tests/UdoitDBTest.php
index 197e7ea56..6451b3987 100644
--- a/tests/UdoitDBTest.php
+++ b/tests/UdoitDBTest.php
@@ -18,94 +18,27 @@
* Primary Author Contact: Jacob Bates
*/
-class PDOStatementMock extends \PDOStatement {
+class UdoitDBTest extends BaseTest
+{
- public $bind_value_calls = [];
- public $execute_calls = [];
-
- public function bindValue($paramno, $param, $type = NULL){
- $this->bind_value_calls[] = func_get_args();
- }
-
- public function execute($bound_input_params = NULL){
- $this->execute_calls[] = func_get_args();
- return true;
- }
-
- public function fetchColumn($column_number = NULL){
- return $this->mockFetch();
- }
-
- public function fetchObject($class_name = NULL, $ctor_args = NULL){
- return $this->mockFetch();
- }
-
- protected function mockFetch(){
- $val = PDOMock::$next_fetch_return;
- PDOMock::$next_fetch_return = null;
- return $val;
- }
-
- public function next() {
- return $this->mockFetch();
- }
-}
-
-class PDOMock extends \PDO {
- public $constructor_args = [];
- public $query_calls = [];
- public $prepare_calls = [];
- public $begin_transaction_calls = [];
- public $commit_calls = [];
- public $statements = [];
- public $query_returns_data = false;
- public static $next_fetch_return = null;
-
- public function __construct() {
- $this->constructor_args = func_get_args();
- }
-
- public function query(){
- $this->query_calls[] = func_get_args();
- if($this->query_returns_data) return self::$next_fetch_return;
- return $this->_newStatement();
- }
-
- public function prepare($statement, $options = NULL){
- $this->prepare_calls[] = func_get_args();
- return $this->_newStatement();
- }
-
- public function beginTransaction(){
- $this->begin_transaction_calls[] = func_get_args();
- }
-
- public function commit(){
- $this->commit_calls[] = func_get_args();
+ public static function setUpBeforeClass()
+ {
+ require_once(__DIR__.'/PDOMock.php');
+ require_once(__DIR__.'/PDOStatementMock.php');
}
- public function nextFetchReturns($value){
- self::$next_fetch_return = $value;
- }
-
- protected function _newStatement(){
- $stmt = new PDOStatementMock();
- $this->statements[] = $stmt;
- return $stmt;
- }
-}
-
-class UdoitDBTest extends BaseTest{
-
- protected function setUp() {
+ public function setUp()
+ {
self::setPrivateStaticPropertyValue('UdoitDB', 'dbClass', 'PDOMock');
}
- protected function tearDown(){
+ public function tearDown()
+ {
self::clearMockDBConnection();
}
- public function testMysqlSetup(){
+ public function testMysqlSetup()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::assertEquals('mysql', self::getPrivateStaticPropertyValue('UdoitDB', 'type'));
@@ -114,7 +47,8 @@ public function testMysqlSetup(){
self::assertEquals('d', self::getPrivateStaticPropertyValue('UdoitDB', 'password'));
}
- public function testPsqlSetup(){
+ public function testPsqlSetup()
+ {
UdoitDB::setup('pgsql', 'b', 'c', 'd');
self::assertEquals('pgsql', self::getPrivateStaticPropertyValue('UdoitDB', 'type'));
@@ -123,7 +57,8 @@ public function testPsqlSetup(){
self::assertEquals('d', self::getPrivateStaticPropertyValue('UdoitDB', 'password'));
}
- public function testConnectMysql(){
+ public function testConnectMysql()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
UdoitDB::testAndReconnect();
$pdo = self::getPrivateStaticPropertyValue('UdoitDB', 'pdo');
@@ -131,7 +66,8 @@ public function testConnectMysql(){
self::assertArraySubset(['b', 'c', 'd'], $pdo->constructor_args);
}
- public function testConnectPgsql(){
+ public function testConnectPgsql()
+ {
UdoitDB::setup('pgsql', 'b', 'c', 'd');
UdoitDB::testAndReconnect();
$pdo = self::getPrivateStaticPropertyValue('UdoitDB', 'pdo');
@@ -139,7 +75,8 @@ public function testConnectPgsql(){
self::assertArraySubset(['b'], $pdo->constructor_args);
}
- public function testDisconnect(){
+ public function testDisconnect()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
UdoitDB::testAndReconnect();
self::assertInstanceOf(PDOMock, self::getPrivateStaticPropertyValue('UdoitDB', 'pdo'));
@@ -147,12 +84,14 @@ public function testDisconnect(){
self::assertNull(self::getPrivateStaticPropertyValue('UdoitDB', 'pdo'));
}
- public function testConnectionTestWithoutConnection(){
+ public function testConnectionTestWithoutConnection()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::assertFalse(UdoitDB::test());
}
- public function testConnectionTestWithConnectionBeforeTimeoutDoesntRunQuery(){
+ public function testConnectionTestWithConnectionBeforeTimeoutDoesntRunQuery()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::callProtectedStaticMethod('UdoitDB', 'connect');
@@ -161,7 +100,8 @@ public function testConnectionTestWithConnectionBeforeTimeoutDoesntRunQuery(){
self::assertEmpty($pdo->query_calls);
}
- public function testConnectionTestWithConnectionBeforeTimeoutWithForceOnDoesRunQuery(){
+ public function testConnectionTestWithConnectionBeforeTimeoutWithForceOnDoesRunQuery()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::callProtectedStaticMethod('UdoitDB', 'connect');
@@ -170,7 +110,8 @@ public function testConnectionTestWithConnectionBeforeTimeoutWithForceOnDoesRunQ
self::assertCount(1, $pdo->query_calls);
}
- public function testConnectionTestWithConnectionAfterTimeoutDoesRunQuery(){
+ public function testConnectionTestWithConnectionAfterTimeoutDoesRunQuery()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::callProtectedStaticMethod('UdoitDB', 'connect');
self::setPrivateStaticPropertyValue('UdoitDB', 'last_test_time', 0);
@@ -180,7 +121,8 @@ public function testConnectionTestWithConnectionAfterTimeoutDoesRunQuery(){
self::assertCount(1, $pdo->query_calls);
}
- public function testPDOPassThroughCallsPDOFunction(){
+ public function testPDOPassThroughCallsPDOFunction()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::callProtectedStaticMethod('UdoitDB', 'connect');
@@ -189,13 +131,12 @@ public function testPDOPassThroughCallsPDOFunction(){
self::assertEquals('QUERY VALUE HERE', $pdo->query_calls[0][0]);
}
- public function testPDOPassThroughWillReconnect(){
+ public function testPDOPassThroughWillReconnect()
+ {
UdoitDB::setup('mysql', 'b', 'c', 'd');
self::assertFalse(UdoitDB::test());
UdoitDB::query('QUERY VALUE HERE');
self::assertTrue(UdoitDB::test());
}
-
}
-
diff --git a/tests/UdoitJobTest.php b/tests/UdoitJobTest.php
index 9c29c3b45..bd7f715ab 100644
--- a/tests/UdoitJobTest.php
+++ b/tests/UdoitJobTest.php
@@ -17,36 +17,40 @@
*
* Primary Author Contact: Jacob Bates
*/
-use org\bovigo\vfs\vfsStream;
-use org\bovigo\vfs\vfsStreamDirectory;
-class UdoitJobTest extends BaseTest{
-
- protected function setUp() {
- $this->exampleDir = vfsStream::setup('exampleDir'); // this resets after every test
+class UdoitJobTest extends BaseTest
+{
+ public function setUp()
+ {
Mockery::close();
UdoitDB::setup('test', 'b', 'c', 'd');
include(__DIR__.'/../bin/db_create_tables.php');
}
- protected function tearDown(){
+ public function tearDown()
+ {
self::setPrivateStaticPropertyValue('UdoitUtils', 'instance', null);
UdoitDB::disconnect();
Mockery::close();
}
// mock UdoitUtils->getValidRefreshedApiKey()
- protected function mockGetValidRefreshKey(){
+ public function mockGetValidRefreshKey()
+ {
$mock = new MockObj();
- $mock->getValidRefreshedApiKey = function(){ return 'test_api_key'; };
+ $mock->getValidRefreshedApiKey = function () {
+ return 'test_api_key';
+ };
self::setPrivateStaticPropertyValue('UdoitUtils', 'instance', $mock);
}
- public function testCreateJobGroupID(){
+ public function testCreateJobGroupID()
+ {
self::assertStringStartsWith('job_', UdoitJob::createJobGroupId());
}
- public function testAddJobToQueue(){
+ public function testAddJobToQueue()
+ {
UdoitJob::$background_worker_enabled = true;
UdoitJob::addJobToQueue('type', 55, 'job_4', ['data' => 'data_value']);
@@ -59,7 +63,8 @@ public function testAddJobToQueue(){
self::assertTrue(empty($res['results']));
}
- public function testAddJobToQueueRunsNextJob(){
+ public function testAddJobToQueueRunsNextJob()
+ {
self::mockGetValidRefreshKey();
// create a user (id will be 1)
@@ -80,7 +85,8 @@ public function testAddJobToQueueRunsNextJob(){
self::assertTrue(!empty($res['results']));
}
- public function testCountJobsRemaining(){
+ public function testCountJobsRemaining()
+ {
UdoitJob::$background_worker_enabled = true;
self::assertEquals(0, UdoitJob::countJobsRemaining());
@@ -92,7 +98,8 @@ public function testCountJobsRemaining(){
self::assertEquals(2, UdoitJob::countJobsRemaining());
}
- public function testGetNextJobChangesStatusToRunning(){
+ public function testGetNextJobChangesStatusToRunning()
+ {
UdoitJob::$background_worker_enabled = true;
UdoitJob::addJobToQueue('type', 11, 'job_4', ['data' => 'data_value']);
UdoitJob::addJobToQueue('type', 22, 'job_5', ['data' => 'data_value']);
@@ -104,17 +111,18 @@ public function testGetNextJobChangesStatusToRunning(){
// make sure it gets the next job because the first is now running
$job = self::callProtectedStaticMethod('UdoitJob', 'getNextJob');
self::assertEquals(22, $job->user_id);
-
}
- public function testGetNextJobHandlesNoJobsGracefully(){
+ public function testGetNextJobHandlesNoJobsGracefully()
+ {
UdoitJob::$background_worker_enabled = true;
$job = self::callProtectedStaticMethod('UdoitJob', 'getNextJob');
self::assertFalse($job);
}
- public function testFinalizeReportProcessesJobsAndWritesReportToDB(){
+ public function testFinalizeReportProcessesJobsAndWritesReportToDB()
+ {
self::mockGetValidRefreshKey();
// create a user (id will be 1)
UdoitDB::query("INSERT into users (api_key, refresh_token) VALUES ('sample_api_key', 'refresh_token')");
@@ -145,7 +153,8 @@ public function testFinalizeReportProcessesJobsAndWritesReportToDB(){
}
- public function testUpdateJobStatus(){
+ public function testUpdateJobStatus()
+ {
self::mockGetValidRefreshKey();
UdoitDB::query("INSERT into users (api_key, refresh_token) VALUES ('sample_api_key', 'refresh_token')");
UdoitJob::$background_worker_enabled = false;
@@ -159,7 +168,8 @@ public function testUpdateJobStatus(){
self::assertEquals('broken', $jobs[0]['status']);
}
- public function testFinalizeProperlyCombinesJobResults(){
+ public function testFinalizeProperlyCombinesJobResults()
+ {
self::mockGetValidRefreshKey();
UdoitDB::query("INSERT into users (api_key, refresh_token) VALUES ('sample_api_key', 'refresh_token')");
UdoitJob::$background_worker_enabled = false;
@@ -219,5 +229,4 @@ public function testFinalizeProperlyCombinesJobResults(){
self::assertArrayHasKey('items', $report['content']['module_urls']);
self::assertCount(2, $report['content']['module_urls']['items']);
}
-
}
diff --git a/tests/UdoitTest.php b/tests/UdoitTest.php
index 9d82c9fb0..a9e52487a 100644
--- a/tests/UdoitTest.php
+++ b/tests/UdoitTest.php
@@ -18,23 +18,21 @@
* Primary Author Contact: Jacob Bates
*/
-use org\bovigo\vfs\vfsStream;
-use org\bovigo\vfs\vfsStreamDirectory;
-
-class UdoitTest extends BaseTest{
-
- protected function setUp() {
- $this->exampleDir = vfsStream::setup('exampleDir'); // this resets after every test
+class UdoitTest extends BaseTest
+{
+ public function setUp()
+ {
Mockery::close();
}
- protected function tearDown(){
+ public function tearDown()
+ {
UdoitDB::disconnect();
Mockery::close();
}
- public function testApiParseLinksParsesLinkHeadersCorrectly() {
-
+ public function testApiParseLinksParsesLinkHeadersCorrectly()
+ {
$link_header = '; rel="current",'.
'; rel="next",'.
'; rel="first",'.
@@ -48,18 +46,19 @@ public function testApiParseLinksParsesLinkHeadersCorrectly() {
self::assertEquals('https://url.com/last', $result['last']);
}
- public function testApiGetAllLinksFollowsLinkHeadersAndReturnsExpectedResults() {
+ public function testApiGetAllLinksFollowsLinkHeadersAndReturnsExpectedResults()
+ {
$header_to_array_returns = [
['link' => '; rel="next"'], // first call
['link' => '; rel="next"'], // second call
- ['link' => '']
+ ['link' => ''],
];
$body_returns = [
["body_0_a", "body_0_b"],
["body_1_a", "body_1_b"],
- ["body_2_a", "body_2_b"]
+ ["body_2_a", "body_2_b"],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -73,14 +72,14 @@ public function testApiGetAllLinksFollowsLinkHeadersAndReturnsExpectedResults()
self::assertCount(6, $result);
self::assertArraySubset(['body_0_a', 'body_0_b', 'body_1_a', 'body_1_b', 'body_2_a', 'body_2_b'], $result);
-
}
- public function testGetCoursContentGetsMultipleItems(){
+ public function testGetCoursContentGetsMultipleItems()
+ {
$header_to_array_returns = [
['link' => '; rel="next"'], // first call
['link' => '; rel="next"'], // second call
- ['link' => '']
+ ['link' => ''],
];
$body_returns = [
@@ -89,18 +88,18 @@ public function testGetCoursContentGetsMultipleItems(){
'id' => "id_value",
'message' => 'message_value',
'title' => 'title_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
[
(object) [
'id' => "id_value2",
'message' => 'message_value2',
'title' => 'title_value2',
- 'html_url' => 'url_value2'
- ]
+ 'html_url' => 'url_value2',
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -115,10 +114,10 @@ public function testGetCoursContentGetsMultipleItems(){
self::assertCount(2, $result['items']);
self::assertEquals('id_value', $result['items'][0]['id']);
self::assertEquals('id_value2', $result['items'][1]['id']);
-
}
- public function testGetCoursContentBuildsExpectedReturnStructure(){
+ public function testGetCoursContentBuildsExpectedReturnStructure()
+ {
$body_returns = [[]];
$mock_get_result = self::mockGetRequestResult([], $body_returns);
@@ -141,17 +140,18 @@ public function testGetCoursContentBuildsExpectedReturnStructure(){
self::assertEmpty($result['items']);
}
- public function testGetCoursContentGetsAnnouncements(){
+ public function testGetCoursContentGetsAnnouncements()
+ {
$body_returns = [
[
(object) [
'id' => "id_value",
'message' => 'message_value',
'title' => 'title_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult([], $body_returns);
@@ -178,17 +178,18 @@ public function testGetCoursContentGetsAnnouncements(){
self::assertEquals('url_value', $result['items'][0]['url']);
}
- public function testGetCoursContentGetsAssignments(){
+ public function testGetCoursContentGetsAssignments()
+ {
$body_returns = [
[
(object) [
'id' => "id_value",
'description' => 'description_value',
'name' => 'name_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult([], $body_returns);
@@ -215,17 +216,18 @@ public function testGetCoursContentGetsAssignments(){
self::assertEquals('url_value', $result['items'][0]['url']);
}
- public function testGetCoursContentGetsDiscussions(){
+ public function testGetCoursContentGetsDiscussions()
+ {
$body_returns = [
[
(object) [
'id' => "id_value",
'message' => 'message_value',
'title' => 'title_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult([], $body_returns);
@@ -253,9 +255,10 @@ public function testGetCoursContentGetsDiscussions(){
}
- public function testGetCoursContentGetsUnscannableFiles(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testGetCoursContentGetsUnscannableFiles()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -265,10 +268,10 @@ public function testGetCoursContentGetsUnscannableFiles(){
'filename' => "filename.pdf",
'id' => 'id_value',
'url' => 'url_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -291,9 +294,10 @@ public function testGetCoursContentGetsUnscannableFiles(){
self::assertEquals('url_value', $result['unscannable'][0]['url']);
}
- public function testGetCoursContentGetsFiles(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testGetCoursContentGetsFiles()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -303,11 +307,11 @@ public function testGetCoursContentGetsFiles(){
'filename' => "filename.html",
'id' => 'id_value',
'url' => 'url_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
'
some html
',
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -335,9 +339,10 @@ public function testGetCoursContentGetsFiles(){
}
- public function testGetCoursContentGetsPages(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testGetCoursContentGetsPages()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -347,17 +352,16 @@ public function testGetCoursContentGetsPages(){
'filename' => "filename.html",
'id' => 'id_value',
'url' => 'url_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
(object) [
'url' => 'url_value',
'body' => 'body_value',
'title' => 'title_value',
'html_url' => 'html_url_value',
- ]
- ,
- []
+ ],
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -384,9 +388,10 @@ public function testGetCoursContentGetsPages(){
self::assertEquals('html_url_value', $result['items'][0]['url']);
}
- public function testGetCoursContentFindsNoVieosInModulesCorrectly(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testGetCoursContentFindsNoVieosInModulesCorrectly()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -397,12 +402,12 @@ public function testGetCoursContentFindsNoVieosInModulesCorrectly(){
'external_url' => "external_url_value",
'id' => 'id_value',
'url' => 'url_value',
- 'title' => 'title_value'
- ]
- ]
- ]
+ 'title' => 'title_value',
+ ],
+ ],
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -419,9 +424,10 @@ public function testGetCoursContentFindsNoVieosInModulesCorrectly(){
self::assertEmpty($result['items']);
}
- public function testGetCoursContentFindsVideosInModules(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testGetCoursContentFindsVideosInModules()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -432,24 +438,24 @@ public function testGetCoursContentFindsVideosInModules(){
'external_url' => "external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
+ 'title' => 'title_value',
],
(object) [
'external_url' => "youtube_external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
+ 'title' => 'title_value',
],
(object) [
'external_url' => "vimeo_external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
- ]
- ]
- ]
+ 'title' => 'title_value',
+ ],
+ ],
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -482,17 +488,18 @@ public function testGetCoursContentFindsVideosInModules(){
self::assertEquals('html_url_value', $m_urls[0]['url']);
}
- public function testGetCoursContentGetsSyllabus(){
- $header_to_array_returns = [];
+ public function testGetCoursContentGetsSyllabus()
+ {
+ $header_to_array_returns = [];
$body_returns = [
[
(object) [
'syllabus_body' => "content_value",
'id' => 'id_value',
- ]
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -520,7 +527,8 @@ public function testGetCoursContentGetsSyllabus(){
self::assertEquals('apiurl/courses/course/assignments/syllabus', $result['items'][0]['url']);
}
- public function testScanContentReturnsNothingWithNoCententToScan(){
+ public function testScanContentReturnsNothingWithNoCententToScan()
+ {
$content_items = [
['content' => ''],
];
@@ -528,13 +536,15 @@ public function testScanContentReturnsNothingWithNoCententToScan(){
self::assertEmpty($result);
}
- public function testScanContentReturnsNothingWithNoItems(){
+ public function testScanContentReturnsNothingWithNoItems()
+ {
$content_items = [];
$result = Udoit::scanContent($content_items);
self::assertEmpty($result);
}
- public function testScanContentReportsErrors(){
+ public function testScanContentReportsErrors()
+ {
$content_items = [
['content' => ''],
['content' => ''],
@@ -580,7 +590,8 @@ public function testScanContentReportsErrors(){
self::assertEquals('imgHasAlt', $result[0]['suggestion'][0]['type']);
}
- public function testRetrieveAndScanBuildsBasicResponse(){
+ public function testRetrieveAndScanBuildsBasicResponse()
+ {
$body_returns = [[]];
$mock_get_result = self::mockGetRequestResult([], $body_returns);
@@ -605,9 +616,10 @@ public function testRetrieveAndScanBuildsBasicResponse(){
self::assertEquals(0, $result['amount']);
}
- public function testRetrieveAndScanReturnsFiles(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testRetrieveAndScanReturnsFiles()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -617,18 +629,18 @@ public function testRetrieveAndScanReturnsFiles(){
'filename' => "filename.html",
'id' => 'id_value',
'url' => 'url_value',
- 'html_url' => 'url_value'
+ 'html_url' => 'url_value',
],
(object) [
'display_name' => "display_name_value.pdf",
'filename' => "filename.pdf",
'id' => 'id_value',
'url' => 'url_value',
- 'html_url' => 'url_value'
- ]
+ 'html_url' => 'url_value',
+ ],
],
'',
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -671,13 +683,14 @@ public function testRetrieveAndScanReturnsFiles(){
self::assertArrayHasKey('warning', $res['files']['items'][0]);
self::assertArrayHasKey('suggestion', $res['files']['items'][0]);
- self::assertCount(1 , $res['files']['items'][0]['suggestion']);
- self::assertCount(1 , $res['files']['items'][0]['suggestion']);
+ self::assertCount(1, $res['files']['items'][0]['suggestion']);
+ self::assertCount(1, $res['files']['items'][0]['suggestion']);
}
- public function testRetrieveAndScanReturnsModules(){
- $header_to_array_returns = [
- ['link' => ''] // just one page
+ public function testRetrieveAndScanReturnsModules()
+ {
+ $header_to_array_returns = [
+ ['link' => ''], // just one page
];
$body_returns = [
@@ -688,24 +701,24 @@ public function testRetrieveAndScanReturnsModules(){
'external_url' => "external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
+ 'title' => 'title_value',
],
(object) [
'external_url' => "youtube_external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
+ 'title' => 'title_value',
],
(object) [
'external_url' => "vimeo_external_url_value",
'id' => 'id_value',
'html_url' => 'html_url_value',
- 'title' => 'title_value'
- ]
- ]
- ]
+ 'title' => 'title_value',
+ ],
+ ],
+ ],
],
- []
+ [],
];
$mock_get_result = self::mockGetRequestResult($header_to_array_returns, $body_returns);
@@ -733,6 +746,4 @@ public function testRetrieveAndScanReturnsModules(){
self::assertArrayHasKey('url', $res['module_urls']['0']);
self::assertArrayHasKey('title', $res['module_urls']['0']);
}
-
}
-
diff --git a/tests/UfixitTest.php b/tests/UfixitTest.php
index a211419b4..1121ec0aa 100644
--- a/tests/UfixitTest.php
+++ b/tests/UfixitTest.php
@@ -21,25 +21,29 @@ class UfixitTest extends BaseTest
{
protected $data;
- public function setUp () {
+ public function setUp()
+ {
$this->data = [
- 'api_key' => '',
- 'base_uri' => '',
- 'content_id' => '',
- 'course_id' => ''
+ 'api_key' => '',
+ 'base_uri' => '',
+ 'content_id' => '',
+ 'course_id' => '',
];
}
- public function tearDown () {
+ public function tearDown()
+ {
unset($data);
}
- private function checkOutputBuffer() {
+ public function checkOutputBuffer()
+ {
$buffer = ob_get_clean();
$this->assertEquals('', $buffer);
}
- public function testFixAltText() {
+ public function testFixAltText()
+ {
$error_html = '';
$new_content = 'test';
$expected = '';
@@ -52,7 +56,8 @@ public function testFixAltText() {
$this->checkOutputBuffer();
}
- public function testFixCssColorOneColorBold() {
+ public function testFixCssColorOneColorBold()
+ {
$error_html = 'Bad Contrasting Text';
$new_content = ['#ffffff', '#000000'];
$expected = 'Bad Contrasting Text';
@@ -67,7 +72,8 @@ public function testFixCssColorOneColorBold() {
$this->checkOutputBuffer();
}
- public function testFixCssColorTwoColorsItalic() {
+ public function testFixCssColorTwoColorsItalic()
+ {
$error_html = 'Bad Contrasting Text';
$new_content = ['#000000', '#fffff0'];
$expected = 'Bad Contrasting Text';
@@ -82,7 +88,8 @@ public function testFixCssColorTwoColorsItalic() {
$this->checkOutputBuffer();
}
- public function testFixCssColorTwoColorsBoldItalic() {
+ public function testFixCssColorTwoColorsBoldItalic()
+ {
$error_html = 'Bad Contrasting Text';
$new_content = ['#000000', '#fffff0'];
$expected = 'Bad Contrasting Text';
@@ -97,7 +104,8 @@ public function testFixCssColorTwoColorsBoldItalic() {
$this->checkOutputBuffer();
}
- public function testFixLinkNewText() {
+ public function testFixLinkNewText()
+ {
$error_html = '';
$new_content = 'test';
$expected = 'test';
@@ -110,7 +118,8 @@ public function testFixLinkNewText() {
$this->checkOutputBuffer();
}
- public function testFixLinkDeleteLink() {
+ public function testFixLinkDeleteLink()
+ {
$error_html = '';
$new_content = '';
$expected = '';
@@ -123,7 +132,8 @@ public function testFixLinkDeleteLink() {
$this->checkOutputBuffer();
}
- public function testFixHeadingNewHeading() {
+ public function testFixHeadingNewHeading()
+ {
$error_html = '';
$new_content = 'Heading Text';
$expected = '
Heading Text
';
@@ -136,7 +146,8 @@ public function testFixHeadingNewHeading() {
$this->checkOutputBuffer();
}
- public function testFixHeadingDeleteHeading() {
+ public function testFixHeadingDeleteHeading()
+ {
$error_html = '';
$new_content = '';
$expected = '';
@@ -149,7 +160,8 @@ public function testFixHeadingDeleteHeading() {
$this->checkOutputBuffer();
}
- public function testFixTableHeadersRow() {
+ public function testFixTableHeadersRow()
+ {
$error_html = '
Header One
Header Two
1.30
4.50
';
$sel_header = 'row';
$expected = '
'."\n".'
Header One
'."\n".'
Header Two
'."\n".'
'."\n";
@@ -162,7 +174,8 @@ public function testFixTableHeadersRow() {
$this->checkOutputBuffer();
}
- public function testFixTableHeadersCol() {
+ public function testFixTableHeadersCol()
+ {
$error_html = '
Header One
Header Two
Title
4.50
';
$sel_header = 'col';
$expected = '
'."\n".'
Header One
'."\n".'
Header Two
'."\n".'
'."\n".'
'."\n".'
Title
'."\n".'
4.50
'."\n".'
';
@@ -175,7 +188,8 @@ public function testFixTableHeadersCol() {
$this->checkOutputBuffer();
}
- public function testFixTableHeadersBoth() {
+ public function testFixTableHeadersBoth()
+ {
$error_html = '
Header One
Header Two
Title
4.50
';
$sel_header = 'both';
$expected = '
'."\n".'
Header One
'."\n".'
Header Two
'."\n".'
'."\n".'
'."\n".'
Title
'."\n".'
4.50
'."\n".'
';
@@ -188,7 +202,8 @@ public function testFixTableHeadersBoth() {
$this->checkOutputBuffer();
}
- public function testFixTableThScopes() {
+ public function testFixTableThScopes()
+ {
$error_html = '
Heading One
';
$new_content = 'col';
$expected = '
Heading One
';
@@ -200,4 +215,4 @@ public function testFixTableThScopes() {
$this->assertEquals($expected, $output);
$this->checkOutputBuffer();
}
-}
\ No newline at end of file
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index ad1360ed7..c14fa6cdc 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -20,5 +20,6 @@
// add the default autoloader
require_once(__DIR__.'/../vendor/autoload.php');
+require_once(__DIR__.'/MockObj.php');
require_once(__DIR__.'/BaseTest.php');
require_once(__DIR__.'/../config/settings.php');