-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented method updateRelatedRecords
- Loading branch information
Cristian Pontes
authored and
Cristian Pontes
committed
Aug 14, 2017
1 parent
b88e39e
commit 5f75257
Showing
7 changed files
with
253 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
namespace CristianPontes\ZohoCRMClient\Request; | ||
|
||
use CristianPontes\ZohoCRMClient\Response\MutationResult; | ||
|
||
/** | ||
* UpdateRelatedRecords API Call | ||
* | ||
* You can use the updateRelatedRecords method to update records related to another record. | ||
* | ||
* @see https://www.zoho.eu/crm/help/api/updaterelatedrecords.html | ||
*/ | ||
class UpdateRelatedRecords extends AbstractRequest | ||
{ | ||
/** @var array */ | ||
private $records = array(); | ||
|
||
/** | ||
* | ||
*/ | ||
protected function configureRequest() | ||
{ | ||
$this->request | ||
->setMethod('updateRelatedRecords') | ||
->setParam('version', 4); | ||
} | ||
|
||
/** | ||
* @param array $record Record as a simple associative array | ||
* @return UpdateRelatedRecords | ||
*/ | ||
public function addRecord(array $record) | ||
{ | ||
$this->records[] = $record; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRecords() | ||
{ | ||
return $this->records; | ||
} | ||
|
||
/** | ||
* @param array $records array containing records otherwise added by addRecord() | ||
* @return UpdateRelatedRecords | ||
*/ | ||
public function setRecords(array $records) | ||
{ | ||
$this->records = $records; | ||
return $this; | ||
} | ||
|
||
/** | ||
* The ID of the record to be updated. | ||
* @param $id | ||
* @return UpdateRelatedRecords | ||
*/ | ||
public function id($id) | ||
{ | ||
$this->request->setParam('id', $id); | ||
return $this; | ||
} | ||
|
||
/** | ||
* The module to which a record is related. | ||
* i.e: If a lead related to a campaign needs to be updated, the value for this parameter will be Leads. | ||
* @param $module | ||
* @return UpdateRelatedRecords | ||
*/ | ||
public function relatedModule($module) | ||
{ | ||
$this->request->setParam('relatedModule', $module); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return MutationResult[] | ||
*/ | ||
public function request() | ||
{ | ||
return $this->request | ||
->setParam('xmlData', $this->records) | ||
->request(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
namespace CristianPontes\ZohoCRMClient\Tests\Request; | ||
|
||
use CristianPontes\ZohoCRMClient\Request; | ||
use CristianPontes\ZohoCRMClient\Transport\MockTransport; | ||
use CristianPontes\ZohoCRMClient\Transport\TransportRequest; | ||
|
||
class UpdateRelatedRecordsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var MockTransport */ | ||
private $transport; | ||
|
||
/** @var TransportRequest */ | ||
private $request; | ||
|
||
/** @var Request\UpdateRelatedRecords */ | ||
private $updateRelatedRecords; | ||
|
||
protected function setUp() | ||
{ | ||
$this->transport = new MockTransport(); | ||
$this->request = new TransportRequest('Products'); | ||
$this->request->setTransport($this->transport); | ||
$this->updateRelatedRecords = new Request\UpdateRelatedRecords($this->request); | ||
} | ||
|
||
public function testInitial() | ||
{ | ||
$this->assertEquals('updateRelatedRecords', $this->request->getMethod()); | ||
$this->assertEquals( | ||
4, | ||
$this->request->getParam('version') | ||
); | ||
} | ||
|
||
public function testRecords() | ||
{ | ||
$record = array( | ||
'PRODUCTID' => '508020000000061987', | ||
'list_price' => '100.00' | ||
); | ||
|
||
$this->updateRelatedRecords->addRecord($record); | ||
|
||
$this->transport->response = true; | ||
|
||
$this->assertTrue($this->updateRelatedRecords->request()); | ||
$this->assertEquals(array('version' => 4, 'xmlData' => array($record)), $this->transport->paramList); | ||
} | ||
|
||
public function testRelatedModule() | ||
{ | ||
$this->updateRelatedRecords->relatedModule('Leads'); | ||
$this->assertEquals( | ||
'Leads', | ||
$this->request->getParam('relatedModule') | ||
); | ||
} | ||
|
||
public function testId() | ||
{ | ||
$this->updateRelatedRecords->id('123'); | ||
$this->assertEquals( | ||
123, | ||
$this->request->getParam('id') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.