13
13
use Magento \TestFramework \TestCase \WebapiAbstract ;
14
14
use Magento \User \Model \User as UserModel ;
15
15
use Magento \Framework \Webapi \Exception as HTTPExceptionCodes ;
16
+ use Magento \Integration \Model \Resource \Oauth \Token \CollectionFactory ;
16
17
17
18
/**
18
19
* api-functional test for \Magento\Integration\Model\CustomerTokenService.
@@ -35,9 +36,9 @@ class CustomerTokenServiceTest extends WebapiAbstract
35
36
private $ customerAccountManagement ;
36
37
37
38
/**
38
- * @var TokenModel
39
+ * @var CollectionFactory
39
40
*/
40
- private $ tokenModel ;
41
+ private $ tokenCollection ;
41
42
42
43
/**
43
44
* @var UserModel
@@ -54,19 +55,21 @@ public function setUp()
54
55
$ this ->customerAccountManagement = Bootstrap::getObjectManager ()->get (
55
56
'Magento\Customer\Api\AccountManagementInterface '
56
57
);
57
- $ this ->tokenModel = Bootstrap::getObjectManager ()->get ('Magento\Integration\Model\Oauth\Token ' );
58
+ $ tokenCollectionFactory = Bootstrap::getObjectManager ()->get (
59
+ 'Magento\Integration\Model\Resource\Oauth\Token\CollectionFactory '
60
+ );
61
+ $ this ->tokenCollection = $ tokenCollectionFactory ->create ();
58
62
$ this ->userModel = Bootstrap::getObjectManager ()->get ('Magento\User\Model\User ' );
59
63
}
60
64
61
65
/**
62
66
* @magentoApiDataFixture Magento/Customer/_files/customer.php
63
- * @magentoAppIsolation enabled
64
- * @magentoDbIsolation enabled
65
67
*/
66
68
public function testCreateCustomerAccessToken ()
67
69
{
68
70
$ customerUserName = 'customer@example.com ' ;
69
71
$ password = 'password ' ;
72
+ $ isTokenCorrect = false ;
70
73
71
74
$ serviceInfo = [
72
75
'rest ' => [
@@ -78,9 +81,17 @@ public function testCreateCustomerAccessToken()
78
81
$ accessToken = $ this ->_webApiCall ($ serviceInfo , $ requestData );
79
82
80
83
$ customerData = $ this ->customerAccountManagement ->authenticate ($ customerUserName , $ password );
81
- /** @var $token TokenModel */
82
- $ token = $ this ->tokenModel ->loadByCustomerId ($ customerData ->getId ())->getToken ();
83
- $ this ->assertEquals ($ accessToken , $ token );
84
+
85
+ /** @var $this->tokenCollection \Magento\Integration\Model\Resource\Oauth\Token\Collection */
86
+ $ this ->tokenCollection ->addFilterByCustomerId ($ customerData ->getId ());
87
+
88
+ foreach ($ this ->tokenCollection ->getItems () as $ item ) {
89
+ /** @var $item TokenModel */
90
+ if ($ item ->getToken () == $ accessToken ) {
91
+ $ isTokenCorrect = true ;
92
+ }
93
+ }
94
+ $ this ->assertTrue ($ isTokenCorrect );
84
95
}
85
96
86
97
/**
0 commit comments