From 776f6bc525afea19784bd9a771212f88f015d8c1 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 29 Dec 2014 09:05:29 +0100 Subject: [PATCH] Fix issue when looking up by ASIN number This prevents the following error: AWS.RestrictedParameterValueCombination "Your request contained a restricted parameter combination. When IdType equals ASIN, SearchIndex cannot be present." --- lib/ApaiIO/Operations/Lookup.php | 2 +- .../Test/Operations/Types/LookupTest.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/ApaiIO/Operations/Lookup.php b/lib/ApaiIO/Operations/Lookup.php index 3501c25..4bbc4d0 100644 --- a/lib/ApaiIO/Operations/Lookup.php +++ b/lib/ApaiIO/Operations/Lookup.php @@ -80,7 +80,7 @@ public function setIdType($idType) $this->parameter['IdType'] = $idType; - if (empty($this->parameter['SearchIndex'])) { + if (empty($this->parameter['SearchIndex']) && $idType != self::TYPE_ASIN) { $this->parameter['SearchIndex'] = 'All'; } diff --git a/tests/ApaiIO/Test/Operations/Types/LookupTest.php b/tests/ApaiIO/Test/Operations/Types/LookupTest.php index 1241f77..a196a31 100644 --- a/tests/ApaiIO/Test/Operations/Types/LookupTest.php +++ b/tests/ApaiIO/Test/Operations/Types/LookupTest.php @@ -55,6 +55,40 @@ public function testGetIdType() } } + /** + * @dataProvider providerSetIdTypeAffectsSearchIndex + * + * @param string $idType + * @param string|null $expectedSearchIndex + */ + public function testSetIdTypeAffectsSearchIndex($idType, $expectedSearchIndex) + { + $lookup = new Lookup(); + $lookup->setIdType($idType); + + $parameters = $lookup->getOperationParameter(); + + if ($expectedSearchIndex === null) { + $this->assertArrayNotHasKey('SearchIndex', $parameters); + } else { + $this->assertSame($expectedSearchIndex, $parameters['SearchIndex']); + } + } + + /** + * @return array + */ + public function providerSetIdTypeAffectsSearchIndex() + { + return array( + array(Lookup::TYPE_ASIN, null), + array(Lookup::TYPE_SKU, 'All'), + array(Lookup::TYPE_UPC, 'All'), + array(Lookup::TYPE_EAN, 'All'), + array(Lookup::TYPE_ISBN, 'All') + ); + } + /** * @expectedException InvalidArgumentException */