RatingTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Model\ResourceModel;
  7. /**
  8. * Class RatingTest
  9. */
  10. class RatingTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var int
  14. */
  15. protected $id;
  16. /**
  17. * @magentoDbIsolation enabled
  18. */
  19. protected function setUp()
  20. {
  21. $storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  22. ->get(\Magento\Store\Model\StoreManagerInterface::class)
  23. ->getStore()->getId();
  24. $rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  25. \Magento\Review\Model\Rating::class
  26. );
  27. $rating->setData([
  28. 'rating_code' => 'Test Rating',
  29. 'position' => 0,
  30. 'is_active' => true,
  31. 'entity_id' => 1
  32. ]);
  33. $rating->setRatingCodes([$storeId => 'Test Rating']);
  34. $rating->setStores([$storeId]);
  35. $rating->save();
  36. $this->id = $rating->getId();
  37. }
  38. /**
  39. * @magentoDbIsolation enabled
  40. */
  41. public function testRatingLoad()
  42. {
  43. $rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  44. \Magento\Review\Model\Rating::class
  45. );
  46. $rating->load($this->id);
  47. $this->assertEquals('Test Rating', $rating->getRatingCode());
  48. }
  49. /**
  50. * @magentoDbIsolation enabled
  51. */
  52. public function testRatingEdit()
  53. {
  54. $rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  55. \Magento\Review\Model\Rating::class
  56. );
  57. $rating->load($this->id);
  58. $this->assertEquals('Test Rating', $rating->getRatingCode());
  59. $storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  60. ->get(\Magento\Store\Model\StoreManagerInterface::class)
  61. ->getStore()->getId();
  62. $rating->setRatingCode('Test Rating Edited');
  63. $rating->setRatingCodes([$storeId => 'Test Rating Edited']);
  64. $rating->save();
  65. $this->assertEquals('Test Rating Edited', $rating->getRatingCode());
  66. $this->assertEquals([$storeId => 'Test Rating Edited'], $rating->getRatingCodes());
  67. }
  68. /**
  69. * @magentoDbIsolation enabled
  70. */
  71. public function testRatingSaveWithError()
  72. {
  73. $this->expectException('Exception');
  74. $this->expectExceptionMessage('Rolled back transaction has not been completed correctly');
  75. $rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  76. \Magento\Review\Model\Rating::class
  77. );
  78. $rating->load($this->id);
  79. $rating->setRatingCodes([222 => 'Test Rating Edited']);
  80. $rating->save();
  81. }
  82. }