10
10
*/
11
11
namespace Magento \Bundle \Model ;
12
12
13
+ use Magento \Bundle \Model \Product \Price ;
14
+ use Magento \Bundle \Model \Product \Type as BundleType ;
15
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
16
+ use Magento \Catalog \Model \Product ;
17
+ use Magento \Catalog \Model \Product \Attribute \Source \Status ;
18
+ use Magento \Catalog \Model \Product \Type ;
19
+ use Magento \Catalog \Model \Product \Visibility ;
20
+ use Magento \Framework \ObjectManagerInterface ;
21
+ use Magento \Store \Api \StoreRepositoryInterface ;
22
+ use Magento \TestFramework \Entity ;
23
+ use Magento \TestFramework \Helper \Bootstrap ;
24
+
13
25
class ProductTest extends \PHPUnit_Framework_TestCase
14
26
{
15
27
/**
16
- * @var \Magento\Catalog\Model\Product
28
+ * @var Product
29
+ */
30
+ private $ model ;
31
+
32
+ /**
33
+ * @var ObjectManagerInterface
17
34
*/
18
- protected $ _model ;
35
+ private $ objectManager ;
19
36
20
37
protected function setUp ()
21
38
{
22
- $ this ->_model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
23
- \Magento \Catalog \Model \Product::class
24
- );
25
- $ this ->_model ->setTypeId (\Magento \Catalog \Model \Product \Type::TYPE_BUNDLE );
26
- }
39
+ $ this ->objectManager = Bootstrap::getObjectManager ();
27
40
28
- public function testGetTypeId ()
29
- {
30
- $ this ->assertEquals (\Magento \Catalog \Model \Product \Type::TYPE_BUNDLE , $ this ->_model ->getTypeId ());
41
+ $ this ->model = $ this ->objectManager ->create (Product::class);
42
+ $ this ->model ->setTypeId (Type::TYPE_BUNDLE );
31
43
}
32
44
33
45
public function testGetSetTypeInstance ()
34
46
{
35
47
// model getter
36
- $ typeInstance = $ this ->_model ->getTypeInstance ();
37
- $ this ->assertInstanceOf (\ Magento \ Bundle \ Model \ Product \Type ::class, $ typeInstance );
38
- $ this ->assertSame ($ typeInstance , $ this ->_model ->getTypeInstance ());
48
+ $ typeInstance = $ this ->model ->getTypeInstance ();
49
+ $ this ->assertInstanceOf (BundleType ::class, $ typeInstance );
50
+ $ this ->assertSame ($ typeInstance , $ this ->model ->getTypeInstance ());
39
51
40
52
// singleton getter
41
- $ otherProduct = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
42
- \Magento \Catalog \Model \Product::class
43
- );
44
- $ otherProduct ->setTypeId (\Magento \Catalog \Model \Product \Type::TYPE_BUNDLE );
53
+ $ otherProduct = $ this ->objectManager ->create (Product::class);
54
+ $ otherProduct ->setTypeId (Type::TYPE_BUNDLE );
45
55
$ this ->assertSame ($ typeInstance , $ otherProduct ->getTypeInstance ());
46
56
47
57
// model setter
48
- $ customTypeInstance = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
49
- \Magento \Bundle \Model \Product \Type::class
50
- );
51
- $ this ->_model ->setTypeInstance ($ customTypeInstance );
52
- $ this ->assertSame ($ customTypeInstance , $ this ->_model ->getTypeInstance ());
58
+ $ customTypeInstance = $ this ->objectManager ->create (BundleType::class);
59
+ $ this ->model ->setTypeInstance ($ customTypeInstance );
60
+ $ this ->assertSame ($ customTypeInstance , $ this ->model ->getTypeInstance ());
53
61
}
54
62
55
63
/**
@@ -59,41 +67,55 @@ public function testGetSetTypeInstance()
59
67
*/
60
68
public function testCRUD ()
61
69
{
62
- $ this ->_model ->setTypeId (
63
- \Magento \Catalog \Model \Product \Type::TYPE_BUNDLE
64
- )->setAttributeSetId (
65
- 4
66
- )->setName (
67
- 'Bundle Product '
68
- )->setSku (
69
- uniqid ()
70
- )->setPrice (
71
- 10
72
- )->setMetaTitle (
73
- 'meta title '
74
- )->setMetaKeyword (
75
- 'meta keyword '
76
- )->setMetaDescription (
77
- 'meta description '
78
- )->setVisibility (
79
- \Magento \Catalog \Model \Product \Visibility::VISIBILITY_BOTH
80
- )->setStatus (
81
- \Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED
82
- );
83
- $ crud = new \Magento \TestFramework \Entity ($ this ->_model , ['sku ' => uniqid ()]);
70
+ $ this ->model ->setTypeId (Type::TYPE_BUNDLE )
71
+ ->setAttributeSetId (4 )
72
+ ->setName ('Bundle Product ' )
73
+ ->setSku (uniqid ())
74
+ ->setPrice (10 )
75
+ ->setMetaTitle ('meta title ' )
76
+ ->setMetaKeyword ('meta keyword ' )
77
+ ->setMetaDescription ('meta description ' )
78
+ ->setVisibility (Visibility::VISIBILITY_BOTH )
79
+ ->setStatus (Status::STATUS_ENABLED );
80
+ $ crud = new Entity ($ this ->model , ['sku ' => uniqid ()]);
84
81
$ crud ->testCrud ();
85
82
}
86
83
87
84
public function testGetPriceModel ()
88
85
{
89
- $ this ->_model ->setTypeId (\ Magento \ Catalog \ Model \ Product \ Type::TYPE_BUNDLE );
90
- $ type = $ this ->_model ->getPriceModel ();
91
- $ this ->assertInstanceOf (\ Magento \ Bundle \ Model \ Product \ Price::class, $ type );
92
- $ this ->assertSame ($ type , $ this ->_model ->getPriceModel ());
86
+ $ this ->model ->setTypeId (Type::TYPE_BUNDLE );
87
+ $ type = $ this ->model ->getPriceModel ();
88
+ $ this ->assertInstanceOf (Price::class, $ type );
89
+ $ this ->assertSame ($ type , $ this ->model ->getPriceModel ());
93
90
}
94
91
95
92
public function testIsComposite ()
96
93
{
97
- $ this ->assertTrue ($ this ->_model ->isComposite ());
94
+ $ this ->assertTrue ($ this ->model ->isComposite ());
95
+ }
96
+
97
+ /**
98
+ * Checks a case when bundle product is should be available per multiple stores.
99
+ *
100
+ * @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options.php
101
+ * @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
102
+ */
103
+ public function testMultipleStores ()
104
+ {
105
+ /** @var ProductRepositoryInterface $productRepository */
106
+ $ productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
107
+ $ bundle = $ productRepository ->get ('bundle-product ' );
108
+
109
+ /** @var StoreRepositoryInterface $storeRepository */
110
+ $ storeRepository = $ this ->objectManager ->get (StoreRepositoryInterface::class);
111
+ $ store = $ storeRepository ->get ('fixture_second_store ' );
112
+
113
+ self ::assertNotEquals ($ store ->getId (), $ bundle ->getStoreId ());
114
+
115
+ $ bundle ->setStoreId ($ store ->getId ())
116
+ ->setCopyFromView (true );
117
+ $ updatedBundle = $ productRepository ->save ($ bundle );
118
+
119
+ self ::assertEquals ($ store ->getId (), $ updatedBundle ->getStoreId ());
98
120
}
99
121
}
0 commit comments