Skip to content

Commit

Permalink
Merge pull request #38 from sugarcrm/integration-tests
Browse files Browse the repository at this point in the history
Integration tests
  • Loading branch information
lschaefer-sugarcrm authored Apr 9, 2018
2 parents be516e8 + 6a0b4b4 commit 4e8f138
Show file tree
Hide file tree
Showing 43 changed files with 1,892 additions and 112 deletions.
55 changes: 52 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
stages:
- name: test
- name: Test PackageGenerator
- name: Run PHPUnit
- name: Build & Post on GitHub
if: branch = master
jobs:
include:
- stage: test
- stage: Test PackageGenerator
language: php
php: '7.1'
os: linux
before_script:
- composer install
- stage: test
- stage: Test PackageGenerator
language: node_js
node_js: '9'
before_install:
- yarn global add grunt-cli
- stage: Run PHPUnit
sudo: required
language: php
php: '7.1'
services:
- docker
env:
- SUGAR_VERSION=7.11 SUGAR_EDITION=Ent
before_script:
- composer install
- cd package
- "./pack.php -v $(date +'%Y%m%d-%H.%M.%S')"
- cd ../scripts
- sudo service mysql stop
script:
- ./SetupEnvAndRunPHPUnitTests.sh $DEV_COMMUNITY_USERNAME $DEV_COMMUNITY_PASSWORD $SUGAR_VERSION $SUGAR_EDITION $GITHUB_USERNAME $GITHUB_PASSWORD workspace/sugardocker
- stage: Run PHPUnit
sudo: required
language: php
php: '7.1'
services:
- docker
env:
- SUGAR_VERSION=7.11 SUGAR_EDITION=Pro
before_script:
- composer install
- cd package
- "./pack.php -v $(date +'%Y%m%d-%H.%M.%S')"
- cd ../scripts
- sudo service mysql stop
script:
- ./SetupEnvAndRunPHPUnitTests.sh $DEV_COMMUNITY_USERNAME $DEV_COMMUNITY_PASSWORD $SUGAR_VERSION $SUGAR_EDITION $GITHUB_USERNAME $GITHUB_PASSWORD workspace/sugardocker
- stage: Run PHPUnit
sudo: required
language: php
php: '7.1'
services:
- docker
env:
- SUGAR_VERSION=7.11 SUGAR_EDITION=Ult
before_script:
- composer install
- cd package
- "./pack.php -v $(date +'%Y%m%d-%H.%M.%S')"
- cd ../scripts
- sudo service mysql stop
script:
- ./SetupEnvAndRunPHPUnitTests.sh $DEV_COMMUNITY_USERNAME $DEV_COMMUNITY_PASSWORD $SUGAR_VERSION $SUGAR_EDITION $GITHUB_USERNAME $GITHUB_PASSWORD workspace/sugardocker
- stage: Build & Post on GitHub
language: php
php: '7.1'
Expand Down
440 changes: 385 additions & 55 deletions README.md

Large diffs are not rendered by default.

Binary file added images/jenkinsbuildpassed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsfailingbuild.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsjasminefailed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsjasminepassed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsphpunit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsphpunitfailed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsphpunitfailed2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jenkinsphpunitpassed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/nodebuildjob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/phpbuildjob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/phpunitprofm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/phpunitsugar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/travisenvvars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/travisphpunitfail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/travisphpunitjob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/travisphpunitresults.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package/pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

$packageID = "ProfessorM";
$packageLabel = "Professor M School for Gifted Coders";
$supportedVersionRegex = '7\\..*$';
$supportedVersionRegex = '(8\..*|7\.(9|10|11)\..*)';

/*
* Determine the version of the zip
Expand Down

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");
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();
}

}
83 changes: 60 additions & 23 deletions package/src/custom/modules/Contacts/Students_Gradebook.php
100755 → 100644
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
Expand All @@ -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()
{
return new SchedulersJob();
}

/**
* Returns a new instance of the SugarJobQueue class
* @return SugarJobQueue
*/
protected function getSugarJobQueue()
{
return new SugarJobQueue();
}
}
Loading

0 comments on commit 4e8f138

Please sign in to comment.