Skip to content

Commit

Permalink
Improvements to gradebook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lschaefer-sugarcrm committed Apr 6, 2018
1 parent c27d7f6 commit 7ae12eb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public function run($data)
try {
//Call the external GradebookFake app to create a new record in it
$rm = $this->getRecordManager();
$success = $rm->createStudentRecord($bean->email1, $bean->first_name, $bean->last_name);
if ($success){
$success = $rm->createStudentRecord($bean->emailAddress->getPrimaryAddress($bean), $bean->first_name,
$bean->last_name);
if ($success) {
$this->job->succeedJob();
return true;
} else{
} else {
$this->job->failJob("Record not successfully created in GradebookFake");
return false;
}
Expand All @@ -57,7 +58,7 @@ public function run($data)
*/
protected function getContactBean($id)
{
return BeanFactory::getBean('Contacts', $id);
return BeanFactory::retrieveBean('Contacts', $id);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion package/src/custom/modules/Contacts/Students_Gradebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function addStudentToGradebook(&$bean, $event, $arguments)
}

//Check if this is a new student record or just an update to an existing record
if($arguments['isUpdate']){
if ($arguments['isUpdate']) {
return;
}

Expand Down Expand Up @@ -61,11 +61,19 @@ protected function scheduleJob(\SchedulersJob $job)
return $jq->submitJob($job);
}

/**
* Returns a new instance of the SchedulersJob class
* @return SchedulersJob
*/
protected function getSchedulersJob()
{
return new SchedulersJob();
}

/**
* Returns a new instance of the SugarJobQueue class
* @return SugarJobQueue
*/
protected function getSugarJobQueue()
{
return new SugarJobQueue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ protected function setUp()
$this->student->id = Uuid::uuid1();
$this->student->first_name = 'John';
$this->student->last_name = 'Doe';
$this->student->email1 = 'jdoe@example.com';

$this->emailAddress = TestMockHelper::createMock($this, '\\SugarEmailAddress');
$this->student->emailAddress = $this->emailAddress;
$this->emailAddress->method('getPrimaryAddress')->willReturn('jdoe@example.com');

// Create a new SchedulersJob and set the job's data to the student's id
$this->job = TestMockHelper::createPartialMock($this, '\\SchedulersJob', ['succeedJob', 'failJob']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Class RecordManagerTest
* Tests the RecordManager for the GradebookFake app
* @coversDefaultClass \RecordManager
* @coversDefaultClass Sugarcrm\Sugarcrm\custom\gradebook_fake\RecordManager
*/
class RecordManagerTest extends TestCase
{
Expand Down
7 changes: 5 additions & 2 deletions package/src/custom/tests/School/unit-php/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../../</directory>
<whitelist addUncoveredFilesFromWhitelist="false" processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../../..</directory>
<exclude>
<directory suffix=".php">../..</directory>
</exclude>
</whitelist>
</filter>
<listeners>
Expand Down

0 comments on commit 7ae12eb

Please sign in to comment.