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