diff --git a/src/Passbook/PassInterface.php b/src/Passbook/PassInterface.php index 35f2f3d..4afc915 100644 --- a/src/Passbook/PassInterface.php +++ b/src/Passbook/PassInterface.php @@ -13,6 +13,7 @@ use Passbook\Pass\BarcodeInterface; use Passbook\Pass\BeaconInterface; +use Passbook\Pass\Image; use Passbook\Pass\ImageInterface; use Passbook\Pass\LocalizationInterface; use Passbook\Pass\LocationInterface; @@ -84,7 +85,7 @@ public function getStructure(); public function addImage(ImageInterface $image); /** - * {@inheritdoc} + * @return Image[] */ public function getImages(); diff --git a/src/Passbook/PassValidator.php b/src/Passbook/PassValidator.php index dfe3298..ed590f5 100644 --- a/src/Passbook/PassValidator.php +++ b/src/Passbook/PassValidator.php @@ -4,7 +4,6 @@ use Passbook\Pass\Barcode; use Passbook\Pass\Beacon; -use Passbook\Pass\Image; use Passbook\Pass\Location; /** @@ -43,6 +42,7 @@ class PassValidator const WEB_SERVICE_AUTHENTICATION_TOKEN_INVALID = 'authenticationToken is invalid; must be at least 16 characters'; const ASSOCIATED_STORE_IDENTIFIER_INVALID = 'associatedStoreIdentifiers is invalid; must be an integer'; const ASSOCIATED_STORE_IDENTIFIER_REQUIRED = 'appLaunchURL is required when associatedStoreIdentifiers is present'; + const IMAGE_TYPE_INVALID = 'image files must be PNG format'; public function validate(Pass $pass) { @@ -53,7 +53,8 @@ public function validate(Pass $pass) $this->validateLocationKeys($pass); $this->validateBarcodeKeys($pass); $this->validateWebServiceKeys($pass); - $this->validateImages($pass); + $this->validateIcon($pass); + $this->validateImageType($pass); $this->validateAssociatedStoreIdentifiers($pass); return count($this->errors) === 0; @@ -189,12 +190,9 @@ private function validateWebServiceKeys(Pass $pass) } } - private function validateImages(Pass $pass) + private function validateIcon(PassInterface $pass) { - $images = $pass->getImages(); - - foreach ($images as $image) { - /* @var Image $image */ + foreach ($pass->getImages() as $image) { if ($image->getContext() === 'icon') { return; } @@ -203,6 +201,16 @@ private function validateImages(Pass $pass) $this->addError(self::ICON_REQUIRED); } + private function validateImageType(PassInterface $pass) + { + foreach ($pass->getImages() as $image) { + $ext = pathinfo($image->getFilename(), PATHINFO_EXTENSION); + if (strcasecmp('png', $ext)) { + $this->addError(self::IMAGE_TYPE_INVALID); + } + } + } + private function validateAssociatedStoreIdentifiers(Pass $pass) { //appLaunchURL diff --git a/tests/Passbook/Tests/PassValidatorTest.php b/tests/Passbook/Tests/PassValidatorTest.php index d9d20b5..32febcf 100644 --- a/tests/Passbook/Tests/PassValidatorTest.php +++ b/tests/Passbook/Tests/PassValidatorTest.php @@ -215,6 +215,19 @@ public function testPassAssociatedStoreIdentifiers() $this->assertFails($this->pass, PassValidator::ASSOCIATED_STORE_IDENTIFIER_INVALID); } + public function testPassImageType() + { + $this->assertPasses($this->pass, PassValidator::IMAGE_TYPE_INVALID); + + $png = new Image(__DIR__ . '/../../img/icon.PNG', 'icon'); + $this->pass->addImage($png); + $this->assertPasses($this->pass, PassValidator::IMAGE_TYPE_INVALID); + + $jpg = new Image(__DIR__ . '/../../img/icon.jpg', 'icon'); + $this->pass->addImage($jpg); + $this->assertFails($this->pass, PassValidator::IMAGE_TYPE_INVALID); + } + private function assertFails($pass, $expectedError) { $validator = new PassValidator(); diff --git a/tests/img/icon.jpg b/tests/img/icon.jpg new file mode 100644 index 0000000..f191cda Binary files /dev/null and b/tests/img/icon.jpg differ