CollectionTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Model\ResourceModel\Integration;
  7. /**
  8. * Unit test for \Magento\Integration\Model\ResourceModel\Integration\Collection
  9. */
  10. class CollectionTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $select;
  16. /**
  17. * @var \Magento\Integration\Model\ResourceModel\Integration\Collection|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $collection;
  20. protected function setUp()
  21. {
  22. $this->select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $connection->expects($this->any())
  29. ->method('select')
  30. ->will($this->returnValue($this->select));
  31. $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
  32. ->disableOriginalConstructor()
  33. ->setMethods(['__wakeup', 'getConnection'])
  34. ->getMockForAbstractClass();
  35. $resource->expects($this->any())
  36. ->method('getConnection')
  37. ->will($this->returnValue($connection));
  38. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  39. $arguments = $objectManagerHelper->getConstructArguments(
  40. \Magento\Integration\Model\ResourceModel\Integration\Collection::class,
  41. ['resource' => $resource]
  42. );
  43. $this->collection = $this->getMockBuilder(
  44. \Magento\Integration\Model\ResourceModel\Integration\Collection::class
  45. )->setConstructorArgs($arguments)
  46. ->setMethods(['addFilter', '_translateCondition', 'getMainTable'])
  47. ->getMock();
  48. }
  49. public function testAddUnsecureUrlsFilter()
  50. {
  51. $this->collection->expects($this->at(0))
  52. ->method('_translateCondition')
  53. ->with('endpoint', ['like' => 'http:%'])
  54. ->will($this->returnValue('endpoint like \'http:%\''));
  55. $this->collection->expects($this->at(1))
  56. ->method('_translateCondition')
  57. ->with('identity_link_url', ['like' => 'http:%'])
  58. ->will($this->returnValue('identity_link_url like \'http:%\''));
  59. $this->select->expects($this->once())
  60. ->method('where')
  61. ->with(
  62. $this->equalTo('(endpoint like \'http:%\') OR (identity_link_url like \'http:%\')'),
  63. $this->equalTo(null),
  64. $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION)
  65. );
  66. $this->collection->addUnsecureUrlsFilter();
  67. }
  68. }