From bf474858c0d43613c25d18666efe26b93ac66e0c Mon Sep 17 00:00:00 2001 From: Cristian Pontes Date: Mon, 13 Mar 2017 16:24:46 +0000 Subject: [PATCH] new method getSearchRecordsByPDC --- Request/GetRecords.php | 2 +- Request/GetSearchRecordsByPDC.php | 106 ++++++++++++++++++++ Tests/Request/GetSearchRecordsByPDCTest.php | 65 ++++++++++++ ZohoCRMClient.php | 8 ++ composer.json | 2 +- 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 Request/GetSearchRecordsByPDC.php create mode 100644 Tests/Request/GetSearchRecordsByPDCTest.php diff --git a/Request/GetRecords.php b/Request/GetRecords.php index cbaf5b9..c572078 100644 --- a/Request/GetRecords.php +++ b/Request/GetRecords.php @@ -22,7 +22,7 @@ protected function configureRequest() * Column names to select i.e, ['Last Name', 'Website', 'Email'] * When not set defaults to all columns * - * @param array $columns + * @param array|string $columns * @return GetRecords */ public function selectColumns($columns) diff --git a/Request/GetSearchRecordsByPDC.php b/Request/GetSearchRecordsByPDC.php new file mode 100644 index 0000000..7efd521 --- /dev/null +++ b/Request/GetSearchRecordsByPDC.php @@ -0,0 +1,106 @@ +request + ->setMethod('getRelatedRecords') + ->setParam('newFormat', '1') + ->setParam('selectColumns', 'All'); + } + + /** + * @param int $index + * @return GetSearchRecordsByPDC + */ + public function fromIndex($index) + { + $this->request->setParam('fromIndex', (int) $index); + return $this; + } + + /** + * @param int $index + * @return GetSearchRecordsByPDC + */ + public function toIndex($index) + { + $this->request->setParam('toIndex', (int) $index); + return $this; + } + + /** + * Column names to select i.e, ['Last Name', 'Website', 'Email'] + * When not set defaults to all columns + * + * @param array|string $columns + * @return GetSearchRecordsByPDC + */ + public function selectColumns($columns) + { + if (!is_array($columns)) { + $columns = func_get_args(); + } + $this->request->setParam( + 'selectColumns', + $this->request->getModule() . '(' . implode(',', $columns) . ')' + ); + return $this; + } + + /** + * Include the empty fields in the response. + * + * @return GetSearchRecordsByPDC + */ + public function withEmptyFields() + { + $this->request->setParam('newFormat', "2"); + return $this; + } + + /** + * Specify the predefined search column + * @see https://www.zoho.com/crm/help/api/getsearchrecordsbypdc.html#Default_Predefined_Columns + * + * @param $column string + * @return GetSearchRecordsByPDC + */ + public function searchColumn($column) + { + $this->request->setParam('searchColumn', $column); + return $this; + } + + /** + * Specify the value to be searched + * + * @param $value string + * @return GetSearchRecordsByPDC + */ + public function searchValue($value) + { + $this->request->setParam('searchValue', $value); + return $this; + } + + /** + * @return Record[] + */ + public function request() + { + return $this->request + ->request(); + } +} diff --git a/Tests/Request/GetSearchRecordsByPDCTest.php b/Tests/Request/GetSearchRecordsByPDCTest.php new file mode 100644 index 0000000..c51d496 --- /dev/null +++ b/Tests/Request/GetSearchRecordsByPDCTest.php @@ -0,0 +1,65 @@ +getSearchRecordsByPDC->fromIndex(10); + + $this->assertEquals(10, $this->request->getParam('fromIndex')); + } + + public function testToIndex() + { + $this->getSearchRecordsByPDC->toIndex(-10); + + $this->assertEquals(-10, $this->request->getParam('toIndex')); + } + + public function testWithEmptyFields() + { + $this->getSearchRecordsByPDC->withEmptyFields(); + $this->assertEquals( + '2', + $this->request->getParam('newFormat') + ); + } + + public function testSelectColumns() + { + $key = 'selectColumns'; + + $this->assertEquals('All', $this->request->getParam($key)); + + $this->getSearchRecordsByPDC->selectColumns('Last Name', 'Email'); + + $this->assertEquals('SomeModuleName(Last Name,Email)', $this->request->getParam($key)); + } + + public function testSearchValue() + { + $this->getSearchRecordsByPDC->searchValue('123'); + $this->assertEquals('123', $this->request->getParam('searchValue')); + } + + public function testSearchColumn() + { + $this->getSearchRecordsByPDC->searchColumn('SomeColumn'); + $this->assertEquals('SomeColumn', $this->request->getParam('searchColumn')); + } + + protected function setUp() + { + $this->request = new TransportRequest('SomeModuleName'); + $this->getSearchRecordsByPDC = new Request\GetSearchRecordsByPDC($this->request); + } +} diff --git a/ZohoCRMClient.php b/ZohoCRMClient.php index 31a5ed1..d378324 100644 --- a/ZohoCRMClient.php +++ b/ZohoCRMClient.php @@ -137,6 +137,14 @@ public function searchRecords() return new Request\SearchRecords($this->request()); } + /** + * @return Request\GetSearchRecordsByPDC + */ + public function getSearchRecordsByPDC() + { + return new Request\GetSearchRecordsByPDC($this->request()); + } + /** * @return Request\GetRelatedRecords */ diff --git a/composer.json b/composer.json index d505c05..38b08ef 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "psr/log": "~1.0.0" }, "require-dev":{ - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "4.8.*" }, "autoload": { "psr-0": {"CristianPontes\\ZohoCRMClient": ""}