MassDisableTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cms\Test\Unit\Controller\Adminhtml\Page;
  7. use Magento\Cms\Test\Unit\Controller\Adminhtml\AbstractMassActionTest;
  8. class MassDisableTest extends AbstractMassActionTest
  9. {
  10. /**
  11. * @var \Magento\Cms\Controller\Adminhtml\Page\MassDisable
  12. */
  13. protected $massDisableController;
  14. /**
  15. * @var \Magento\Cms\Model\ResourceModel\Page\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $collectionFactoryMock;
  18. /**
  19. * @var \Magento\Cms\Model\ResourceModel\Page\Collection|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $pageCollectionMock;
  22. protected function setUp()
  23. {
  24. parent::setUp();
  25. $this->collectionFactoryMock = $this->createPartialMock(
  26. \Magento\Cms\Model\ResourceModel\Page\CollectionFactory::class,
  27. ['create']
  28. );
  29. $this->pageCollectionMock = $this->createMock(\Magento\Cms\Model\ResourceModel\Page\Collection::class);
  30. $this->massDisableController = $this->objectManager->getObject(
  31. \Magento\Cms\Controller\Adminhtml\Page\MassDisable::class,
  32. [
  33. 'context' => $this->contextMock,
  34. 'filter' => $this->filterMock,
  35. 'collectionFactory' => $this->collectionFactoryMock
  36. ]
  37. );
  38. }
  39. public function testMassDisableAction()
  40. {
  41. $disabledPagesCount = 2;
  42. $collection = [
  43. $this->getPageMock(),
  44. $this->getPageMock()
  45. ];
  46. $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->pageCollectionMock);
  47. $this->filterMock->expects($this->once())
  48. ->method('getCollection')
  49. ->with($this->pageCollectionMock)
  50. ->willReturn($this->pageCollectionMock);
  51. $this->pageCollectionMock->expects($this->once())->method('getSize')->willReturn($disabledPagesCount);
  52. $this->pageCollectionMock->expects($this->once())
  53. ->method('getIterator')
  54. ->willReturn(new \ArrayIterator($collection));
  55. $this->messageManagerMock->expects($this->once())
  56. ->method('addSuccessMessage')
  57. ->with(__('A total of %1 record(s) have been disabled.', $disabledPagesCount));
  58. $this->messageManagerMock->expects($this->never())->method('addErrorMessage');
  59. $this->resultRedirectMock->expects($this->once())
  60. ->method('setPath')
  61. ->with('*/*/')
  62. ->willReturnSelf();
  63. $this->assertSame($this->resultRedirectMock, $this->massDisableController->execute());
  64. }
  65. /**
  66. * Create Cms Page Collection Mock
  67. *
  68. * @return \Magento\Cms\Model\ResourceModel\Page\Collection|\PHPUnit_Framework_MockObject_MockObject
  69. */
  70. protected function getPageMock()
  71. {
  72. $pageMock = $this->createPartialMock(
  73. \Magento\Cms\Model\ResourceModel\Page\Collection::class,
  74. ['setIsActive', 'save']
  75. );
  76. $pageMock->expects($this->once())->method('setIsActive')->with(false)->willReturn(true);
  77. $pageMock->expects($this->once())->method('save')->willReturn(true);
  78. return $pageMock;
  79. }
  80. }