-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests #38
Changes from 5 commits
af25f27
4dcba4d
7f9c771
c27d7f6
7ae12eb
6a0b4b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
use Sugarcrm\Sugarcrm\custom\gradebook_fake\RecordManager; | ||
|
||
class StudentGradebookJob implements RunnableSchedulerJob | ||
{ | ||
|
||
/** | ||
* @var SchedulersJob | ||
*/ | ||
protected $job; | ||
/** | ||
* @param SchedulersJob $job | ||
*/ | ||
public function setJob(SchedulersJob $job) | ||
{ | ||
$this->job = $job; | ||
} | ||
|
||
/** | ||
* This function defines the job that adds a new student to the GradebookFake app | ||
* @param string $data The id for the new Student (contact) record | ||
* @return bool true if a record was successfully created in the GradebookFake app | ||
*/ | ||
public function run($data) | ||
{ | ||
if (!empty($data)) { | ||
$bean = $this->getContactBean($data); | ||
|
||
try { | ||
//Call the external GradebookFake app to create a new record in it | ||
$rm = $this->getRecordManager(); | ||
$success = $rm->createStudentRecord($bean->emailAddress->getPrimaryAddress($bean), $bean->first_name, | ||
$bean->last_name); | ||
if ($success) { | ||
$this->job->succeedJob(); | ||
return true; | ||
} else { | ||
$this->job->failJob("Record not successfully created in GradebookFake"); | ||
return false; | ||
} | ||
} catch (Exception $e) { | ||
$this->job->failJob($e->getMessage()); | ||
|
||
return false; | ||
} | ||
|
||
} | ||
|
||
$this->job->failJob("Job had no data"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We tend to use single quotes for strings unless using string interpolation. It's not a PSR rule, however. |
||
return false; | ||
} | ||
|
||
/** | ||
* Get the Contact (Student) bean for the given id | ||
* @param $id The id for which you want to retrieve a Contact (Student) bean | ||
* @return null|SugarBean | ||
*/ | ||
protected function getContactBean($id) | ||
{ | ||
return BeanFactory::retrieveBean('Contacts', $id); | ||
} | ||
|
||
/** | ||
* Get the Record Manager for the GradebookFake app | ||
* @return RecordManager The Record Manager for the GradebookFake app | ||
*/ | ||
protected function getRecordManager() | ||
{ | ||
return new RecordManager(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<?php | ||
|
||
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | ||
|
||
/** | ||
* Class Students_Gradebook | ||
* Handles creating a job for the Sugar Job Queue that adds a new student to the GradebookFake app | ||
|
@@ -15,30 +13,69 @@ class Students_Gradebook | |
* @param $event The current event | ||
* @param $arguments Additional information related to the event | ||
*/ | ||
function AddStudentToGradebook(&$bean, $event, $arguments) | ||
public function addStudentToGradebook(&$bean, $event, $arguments) | ||
{ | ||
if ($event !== 'after_save') { | ||
return; | ||
} | ||
|
||
//Check if this is a new student record or just an update to an existing record | ||
if(!$arguments['isUpdate']){ | ||
|
||
require_once('include/SugarQueue/SugarJobQueue.php'); | ||
|
||
//create the new job | ||
$job = new SchedulersJob(); | ||
//job name | ||
$job->name = "Add New Student to Gradebook Job"; | ||
//data we are passing to the job | ||
$job->data = $bean->id; | ||
//function to call | ||
$job->target = "function::AddStudentToGradebookJob"; | ||
|
||
global $current_user; | ||
//set the user the job runs as | ||
$job->assigned_user_id = $current_user->id; | ||
|
||
//push into the queue to run | ||
$jq = new SugarJobQueue(); | ||
$jobid = $jq->submitJob($job); | ||
if ($arguments['isUpdate']) { | ||
return; | ||
} | ||
|
||
$job = $this->defineJob($bean); | ||
|
||
$this->scheduleJob($job); | ||
} | ||
|
||
/** | ||
* Define the job that adds a new student to the GradebookFake app | ||
* @param SugarBean $bean The Student (Contact) bean | ||
* @return SchedulersJob The job that was defined | ||
*/ | ||
protected function defineJob(\SugarBean $bean) | ||
{ | ||
//create the new job | ||
$job = $this->getSchedulersJob(); | ||
//job name | ||
$job->name = "Add New Student to Gradebook Job"; | ||
//data we are passing to the job | ||
$job->data = $bean->id; | ||
//function to call | ||
$job->target = "class::StudentGradebookJob"; | ||
//set the user the job runs as | ||
$job->assigned_user_id = $GLOBALS['current_user']->id; | ||
|
||
return $job; | ||
} | ||
|
||
/** | ||
* Schedule the job to run by submitting it to the Sugar Job Queue | ||
* @param SchedulersJob $job The job to submit | ||
* @return string Response from submitting the job | ||
*/ | ||
protected function scheduleJob(\SchedulersJob $job) | ||
{ | ||
$jq = $this->getSugarJobQueue(); | ||
return $jq->submitJob($job); | ||
} | ||
|
||
/** | ||
* Returns a new instance of the SchedulersJob class | ||
* @return SchedulersJob | ||
*/ | ||
protected function getSchedulersJob() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing doc block. |
||
{ | ||
return new SchedulersJob(); | ||
} | ||
|
||
/** | ||
* Returns a new instance of the SugarJobQueue class | ||
* @return SugarJobQueue | ||
*/ | ||
protected function getSugarJobQueue() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing doc block. |
||
{ | ||
return new SugarJobQueue(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running tests on ent, pro, and ult seems overkill? The Professor M code doesn't come in different flavors. I assume you're doing this to run the core unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes from our chat: We're going to continue running on ent, pro, and ult as this tests the install into each version. I'm going to remove the running of the Sugar provided unit tests.