From 04a81e514213801ff02cd15c12b5f1c55972754b Mon Sep 17 00:00:00 2001
From: Alex Akimov <aakimov@ebay.com>
Date: Thu, 22 Jan 2015 13:54:17 +0200
Subject: [PATCH] MAGETWO-32811: GET /V1/carts/:cartId/selected-payment-methods
 service always return "cc_exp_year" even if it not needed

---
 .../Magento/Quote/Model/Quote/Payment.php     |  3 +-
 .../Magento/Quote/Model/Quote/PaymentTest.php | 48 +++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 dev/tests/unit/testsuite/Magento/Quote/Model/Quote/PaymentTest.php

diff --git a/app/code/Magento/Quote/Model/Quote/Payment.php b/app/code/Magento/Quote/Model/Quote/Payment.php
index a6b5657263d..6eedc8b8925 100644
--- a/app/code/Magento/Quote/Model/Quote/Payment.php
+++ b/app/code/Magento/Quote/Model/Quote/Payment.php
@@ -279,7 +279,8 @@ class Payment extends \Magento\Payment\Model\Info implements \Magento\Quote\Api\
      */
     public function getCcExpYear()
     {
-        return $this->getData('cc_exp_year');
+        $expirationYear = $this->getData('cc_exp_year') ?: null;
+        return $expirationYear;
     }
 
     /**
diff --git a/dev/tests/unit/testsuite/Magento/Quote/Model/Quote/PaymentTest.php b/dev/tests/unit/testsuite/Magento/Quote/Model/Quote/PaymentTest.php
new file mode 100644
index 00000000000..6d0bc8694a5
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Quote/Model/Quote/PaymentTest.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Quote\Model\Quote;
+
+use Magento\TestFramework\Helper\ObjectManager;
+
+class PaymentTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Payment
+     */
+    private $model;
+
+    protected function setUp()
+    {
+        $objectManager = new ObjectManager($this);
+        $this->model = $objectManager->getObject(
+            '\Magento\Quote\Model\Quote\Payment'
+        );
+    }
+
+    /**
+     * @param int|string|null $databaseValue
+     * @param int|string|null $expectedValue
+     * @dataProvider yearValueDataProvider
+     */
+    public function testGetCcExpYearReturnsValidValue($databaseValue, $expectedValue)
+    {
+        $this->model->setData('cc_exp_year', $databaseValue);
+        $this->assertEquals($expectedValue, $this->model->getCcExpYear());
+    }
+
+    /**
+     * @return array
+     */
+    public function yearValueDataProvider()
+    {
+        return array(
+            array(null, null),
+            array(0, null),
+            array('0', null),
+            array(1939, 1939),
+        );
+    }
+}
-- 
GitLab