5
5
*/
6
6
namespace Magento \OfflinePayments \Test \Unit \Model ;
7
7
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
+
8
19
class PurchaseorderTest extends \PHPUnit \Framework \TestCase
9
20
{
10
21
/**
11
- * @var \Magento\OfflinePayments\Model\ Purchaseorder
22
+ * @var Purchaseorder
12
23
*/
13
24
protected $ _object ;
14
25
@@ -19,15 +30,15 @@ class PurchaseorderTest extends \PHPUnit\Framework\TestCase
19
30
20
31
protected function setUp ()
21
32
{
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);
25
36
$ this ->_scopeConfig = $ this ->createPartialMock (
26
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface::class,
37
+ ScopeConfigInterface::class,
27
38
['getValue ' , 'isSetFlag ' ]
28
39
);
29
40
$ this ->_object = $ objectManagerHelper ->getObject (
30
- \ Magento \ OfflinePayments \ Model \ Purchaseorder::class,
41
+ Purchaseorder::class,
31
42
[
32
43
'eventManager ' => $ eventManager ,
33
44
'paymentData ' => $ paymentDataMock ,
@@ -38,13 +49,37 @@ protected function setUp()
38
49
39
50
public function testAssignData ()
40
51
{
41
- $ data = new \ Magento \ Framework \ DataObject ([
52
+ $ data = new DataObject ([
42
53
'po_number ' => '12345 '
43
54
]);
44
55
45
- $ instance = $ this ->createMock (\ Magento \ Payment \ Model \Info ::class);
56
+ $ instance = $ this ->createMock (PaymentInfo ::class);
46
57
$ this ->_object ->setData ('info_instance ' , $ instance );
47
58
$ result = $ this ->_object ->assignData ($ data );
48
59
$ this ->assertEquals ($ result , $ this ->_object );
49
60
}
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
+ }
50
85
}
0 commit comments