@@ -29,6 +29,8 @@ class ChangeTest extends \PHPUnit_Framework_TestCase
29
29
protected $ tansactionMock ;
30
30
/** @var |\PHPUnit_Framework_MockObject_MockObject */
31
31
protected $ objRelationMock ;
32
+ /** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
33
+ protected $ randomMock ;
32
34
/** @var \Magento\EncryptionKey\Model\ResourceModel\Key\Change */
33
35
protected $ model ;
34
36
@@ -72,6 +74,7 @@ public function setUp()
72
74
->disableOriginalConstructor ()
73
75
->setMethods ([])
74
76
->getMock ();
77
+ $ this ->randomMock = $ this ->getMock ('Magento\Framework\Math\Random ' , [], [], '' , false );
75
78
76
79
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
77
80
@@ -85,20 +88,20 @@ public function setUp()
85
88
'adapterInterface ' => $ this ->adapterMock ,
86
89
'resource ' => $ this ->resourceMock ,
87
90
'transactionManager ' => $ this ->tansactionMock ,
88
- 'relationProcessor ' => $ this ->objRelationMock
91
+ 'relationProcessor ' => $ this ->objRelationMock ,
92
+ 'random ' => $ this ->randomMock
89
93
]
90
94
);
91
95
}
92
96
93
- public function testChangeEncryptionKey ()
97
+ private function setUpChangeEncryptionKey ()
94
98
{
95
99
$ paths = ['path1 ' , 'path2 ' ];
96
100
$ table = ['item1 ' , 'item2 ' ];
97
101
$ values = [
98
102
'key1 ' => 'value1 ' ,
99
103
'key2 ' => 'value2 '
100
104
];
101
- $ key = 'key ' ;
102
105
103
106
$ this ->writerMock ->expects ($ this ->once ())->method ('checkIfWritable ' )->willReturn (true );
104
107
$ this ->resourceMock ->expects ($ this ->atLeastOnce ())->method ('getConnection ' )->willReturn ($ this ->adapterMock );
@@ -112,10 +115,23 @@ public function testChangeEncryptionKey()
112
115
$ this ->selectMock ->expects ($ this ->any ())->method ('update ' )->willReturnSelf ();
113
116
$ this ->writerMock ->expects ($ this ->once ())->method ('saveConfig ' );
114
117
$ this ->adapterMock ->expects ($ this ->once ())->method ('getTransactionLevel ' )->willReturn (1 );
118
+ }
115
119
120
+ public function testChangeEncryptionKey ()
121
+ {
122
+ $ this ->setUpChangeEncryptionKey ();
123
+ $ this ->randomMock ->expects ($ this ->never ())->method ('getRandomString ' );
124
+ $ key = 'key ' ;
116
125
$ this ->assertEquals ($ key , $ this ->model ->changeEncryptionKey ($ key ));
117
126
}
118
127
128
+ public function testChangeEncryptionKeyAutogenerate ()
129
+ {
130
+ $ this ->setUpChangeEncryptionKey ();
131
+ $ this ->randomMock ->expects ($ this ->once ())->method ('getRandomString ' )->willReturn ('abc ' );
132
+ $ this ->assertEquals (md5 ('abc ' ), $ this ->model ->changeEncryptionKey ());
133
+ }
134
+
119
135
public function testChangeEncryptionKeyThrowsException ()
120
136
{
121
137
$ key = 'key ' ;
@@ -127,6 +143,6 @@ public function testChangeEncryptionKeyThrowsException()
127
143
return ;
128
144
}
129
145
130
- $ this ->fail ('An excpected exception was not signaled. ' );
146
+ $ this ->fail ('An expected exception was not signaled. ' );
131
147
}
132
148
}
0 commit comments