55 */
66namespace Magento \OfflinePayments \Test \Unit \Model ;
77
8+ use Magento \Framework \App \Config \ScopeConfigInterface ;
9+ use Magento \Framework \DataObject ;
10+ use Magento \Framework \Event \ManagerInterface as EventManagerInterface ;
11+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12+ use Magento \OfflinePayments \Model \Purchaseorder ;
13+ use Magento \Payment \Helper \Data as PaymentHelper ;
14+ use Magento \Payment \Model \Info as PaymentInfo ;
15+ use Magento \Sales \Api \Data \OrderAddressInterface ;
16+ use Magento \Sales \Api \Data \OrderInterface ;
17+ use Magento \Sales \Model \Order \Payment ;
18+
819class PurchaseorderTest extends \PHPUnit \Framework \TestCase
920{
1021 /**
11- * @var \Magento\OfflinePayments\Model\ Purchaseorder
22+ * @var Purchaseorder
1223 */
1324 protected $ _object ;
1425
@@ -19,15 +30,15 @@ class PurchaseorderTest extends \PHPUnit\Framework\TestCase
1930
2031 protected function setUp ()
2132 {
22- $ objectManagerHelper = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
23- $ eventManager = $ this ->createMock (\ Magento \ Framework \ Event \ManagerInterface ::class);
24- $ paymentDataMock = $ this ->createMock (\ Magento \ Payment \ Helper \Data ::class);
33+ $ objectManagerHelper = new ObjectManager ($ this );
34+ $ eventManager = $ this ->createMock (EventManagerInterface ::class);
35+ $ paymentDataMock = $ this ->createMock (PaymentHelper ::class);
2536 $ this ->_scopeConfig = $ this ->createPartialMock (
26- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface::class,
37+ ScopeConfigInterface::class,
2738 ['getValue ' , 'isSetFlag ' ]
2839 );
2940 $ this ->_object = $ objectManagerHelper ->getObject (
30- \ Magento \ OfflinePayments \ Model \ Purchaseorder::class,
41+ Purchaseorder::class,
3142 [
3243 'eventManager ' => $ eventManager ,
3344 'paymentData ' => $ paymentDataMock ,
@@ -38,13 +49,37 @@ protected function setUp()
3849
3950 public function testAssignData ()
4051 {
41- $ data = new \ Magento \ Framework \ DataObject ([
52+ $ data = new DataObject ([
4253 'po_number ' => '12345 '
4354 ]);
4455
45- $ instance = $ this ->createMock (\ Magento \ Payment \ Model \Info ::class);
56+ $ instance = $ this ->createMock (PaymentInfo ::class);
4657 $ this ->_object ->setData ('info_instance ' , $ instance );
4758 $ result = $ this ->_object ->assignData ($ data );
4859 $ this ->assertEquals ($ result , $ this ->_object );
4960 }
61+
62+ /**
63+ * @expectedException \Magento\Framework\Exception\LocalizedException
64+ * @expectedExceptionMessage Purchase order number is a required field.
65+ */
66+ public function testValidate ()
67+ {
68+ $ data = new DataObject ([]);
69+
70+ $ addressMock = $ this ->createMock (OrderAddressInterface::class);
71+ $ addressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn ('UY ' );
72+
73+ $ orderMock = $ this ->createMock (OrderInterface::class);
74+ $ orderMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ addressMock );
75+
76+ $ instance = $ this ->createMock (Payment::class);
77+
78+ $ instance ->expects ($ this ->once ())->method ('getOrder ' )->willReturn ($ orderMock );
79+
80+ $ this ->_object ->setData ('info_instance ' , $ instance );
81+ $ this ->_object ->assignData ($ data );
82+
83+ $ this ->_object ->validate ();
84+ }
5085}
0 commit comments