From f5e776d2dd270d9952d51aad3a9af507011bfb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Sat, 27 Mar 2021 18:23:56 +0100 Subject: [PATCH 1/2] Adding availability and expiration date --- composer.json | 3 +++ src/Product.php | 26 ++++++++++++++++++++++++++ tests/feed/ProductTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/composer.json b/composer.json index 9fa7d5d..9ada649 100644 --- a/composer.json +++ b/composer.json @@ -17,5 +17,8 @@ "psr-4": { "Vitalybaev\\GoogleMerchant\\": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "^9.5" } } diff --git a/src/Product.php b/src/Product.php index 8d38d7e..79890f9 100644 --- a/src/Product.php +++ b/src/Product.php @@ -133,6 +133,32 @@ public function setAvailability($availability) return $this; } + /** + * Sets availability date of the product. Only relevant if availability is set to 'preorder'. + * + * @param $availabilityDate + * + * @return $this + */ + public function setAvailabilityDate($availabilityDate) + { + $this->setAttribute('availability_date', $availabilityDate, false); + return $this; + } + + /** + * Sets the expiration date of the product. + * + * @param $expirationDate + * + * @return $this + */ + public function setExpirationDate($expirationDate) + { + $this->setAttribute('expiration_date', $expirationDate, false); + return $this; + } + /** * Sets price of the product. * diff --git a/tests/feed/ProductTest.php b/tests/feed/ProductTest.php index 0380320..07b48c1 100644 --- a/tests/feed/ProductTest.php +++ b/tests/feed/ProductTest.php @@ -95,6 +95,34 @@ public function testProductSetsId() ], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); } + public function testProductSetsAvailabilityDate() + { + $date = '2021-04-01'; + + $product = new Product(); + $product->setAvailabilityDate($date); + + $this->assertEquals([ + 'item' => [ + ['name' => "{http://base.google.com/ns/1.0}availability_date", "value" => $date], + ], + ], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); + } + + public function testProductSetsExpirationDate() + { + $date = '2021-05-01'; + + $product = new Product(); + $product->setExpirationDate($date); + + $this->assertEquals([ + 'item' => [ + ['name' => "{http://base.google.com/ns/1.0}expiration_date", "value" => $date], + ], + ], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); + } + /** * Tests setting Id to product. */ From 42c87df9beb9c7e2b1c3a4eab34ebc92539b2283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Sat, 27 Mar 2021 18:53:22 +0100 Subject: [PATCH 2/2] Add phpunit 9 compatible config file --- phpunit.xml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 3fadba1..53cdd83 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,16 @@ - - - - tests/feed - - - - - src - - + + + + src + + + + + tests/feed + +