Skip to content
Snippets Groups Projects
Commit 6a30a677 authored by git's avatar git
Browse files

Adds SelectQueryResult and QueueHander tests

Moves functional calls to wrapper methods in QueueHandler for testability
parent 989de466
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ class QueueHandler { ...@@ -22,7 +22,7 @@ class QueueHandler {
private function __construct(RestClient $sfapi) { private function __construct(RestClient $sfapi) {
$this->sfapi = $sfapi; $this->sfapi = $sfapi;
$this->queue = \Drupal::queue('cron_salesforce_pull'); $this->setQueue();
$this->organizeMappings(); $this->organizeMappings();
} }
...@@ -70,7 +70,7 @@ class QueueHandler { ...@@ -70,7 +70,7 @@ class QueueHandler {
* of field mappings * of field mappings
*/ */
protected function organizeMappings() { protected function organizeMappings() {
$this->mappings = salesforce_mapping_load_multiple(); $this->mappings = $this->loadMultipleMappings();
$this->pull_fields = []; $this->pull_fields = [];
foreach($this->mappings as $mapping) { foreach($this->mappings as $mapping) {
$this->pull_fields[$mapping->getSalesforceObjectType()] = $this->pull_fields[$mapping->getSalesforceObjectType()] =
...@@ -155,4 +155,19 @@ class QueueHandler { ...@@ -155,4 +155,19 @@ class QueueHandler {
watchdog_exception(__CLASS__, $e); watchdog_exception(__CLASS__, $e);
} }
} }
/**
* Drupal::queue wrapper function for testability
*/
protected function setQueue() {
$this->queue = \Drupal::queue('cron_salesforce_pull');
}
/**
* salesforce_mapping_load_multiple() function for testability
*/
protected function loadMultipleMappings() {
return salesforce_mapping_load_multiple();
}
} }
<?php
namespace Drupal\Tests\salesforce;
use Drupal\Tests\UnitTestCase;
use Drupal\salesforce\SelectQueryResult;
use Drupal\salesforce\SFID;
use Drupal\salesforce\Exception;
/**
* Test Object instantitation
*
* @group salesforce_pull
*/
class SelectQueryResultTest extends UnitTestCase {
static $modules = ['salesforce'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$result = [
'totalSize' => 2,
'done' => true,
'records' => [
[
'Id' => '1234567890abcde',
'attributes' => ['type' => 'dummy',],
'name' => 'Example',
],
[
'Id' => '1234567890abcdf',
'attributes' => ['type' => 'dummy',],
'name' => 'Example2',
],
]
];
$this->sqr = new SelectQueryResult($result);
}
/**
* Test object instantiation with good resultd
*/
public function testGoodID() {
$this->assertTrue($this->sqr instanceof SelectQueryResult);
}
/**
* Test object instantiation with no ID
* @expectedException Exception
*/
public function testNoID() {
$sfid = new SFID('1234567890abcdg');
$id = $this->sqr->record($sfid);
}
}
<?php
namespace Drupal\Tests\salesforce\salesforce_pull;
use Drupal\Tests\UnitTestCase;
use Drupal\salesforce_pull\QueueHandler;
use Drupal\salesforce\SObject;
use Drupal\salesforce_mapping\Entity\SalesforceMappingInterface;
use Drupal\salesforce_pull\PullQueueItem;
/**
* Test Object instantitation
*
* @group salesforce_pull
*/
class PullQueueItemTest extends UnitTestCase {
static $modules = ['salesforce_pull'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$prophecy = $this->prophesize(RestClient::CLASS);
$sfapi = $prophecy->reveal();
$qh = QueueHandler::create($sfapi);
}
/**
* Test object instantiation
*/
public function testObject() {
$this->assertTrue($qh instanceof QueueHandler);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment