ParamOverriderCustomerIdTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Test\Unit\Controller\Rest;
  7. use Magento\Authorization\Model\UserContextInterface;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Webapi\Controller\Rest\ParamOverriderCustomerId;
  10. class ParamOverriderCustomerIdTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var ParamOverriderCustomerId
  14. */
  15. private $model;
  16. /**
  17. * @var UserContextInterface
  18. */
  19. private $userContext;
  20. protected function setUp()
  21. {
  22. $this->userContext = $this->getMockBuilder(\Magento\Authorization\Model\UserContextInterface::class)
  23. ->getMockForAbstractClass();
  24. $this->model = (new ObjectManager($this))->getObject(
  25. \Magento\Webapi\Controller\Rest\ParamOverriderCustomerId::class,
  26. [
  27. 'userContext' => $this->userContext
  28. ]
  29. );
  30. }
  31. public function testGetOverriddenValueIsCustomer()
  32. {
  33. $retValue = 'retValue';
  34. $this->userContext->expects($this->once())
  35. ->method('getUserType')
  36. ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER));
  37. $this->userContext->expects($this->once())
  38. ->method('getUserId')
  39. ->will($this->returnValue($retValue));
  40. $this->assertSame($retValue, $this->model->getOverriddenValue());
  41. }
  42. public function testGetOverriddenValueIsNotCustomer()
  43. {
  44. $this->userContext->expects($this->once())
  45. ->method('getUserType')
  46. ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN));
  47. $this->assertNull($this->model->getOverriddenValue());
  48. }
  49. }