@@ -45,6 +45,47 @@ public function testSaveActionRedirectsSuccessfully()
45
45
$ this ->assertTrue ($ isRedirectPresent );
46
46
}
47
47
48
+ /**
49
+ * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
50
+ *
51
+ * @dataProvider saveActionVisibilityAttrDataProvider
52
+ * @param array $attributes
53
+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
54
+ */
55
+ public function testSaveActionChangeVisibility ($ attributes )
56
+ {
57
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
58
+ $ repository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
59
+ \Magento \Catalog \Model \ProductRepository::class
60
+ );
61
+ $ product = $ repository ->get ('simple ' );
62
+ $ product ->setOrigData ();
63
+ $ product ->setVisibility (\Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE );
64
+ $ product ->save ();
65
+
66
+ /** @var $session \Magento\Backend\Model\Session */
67
+ $ session = $ objectManager ->get (\Magento \Backend \Model \Session::class);
68
+ $ session ->setProductIds ([$ product ->getId ()]);
69
+ $ this ->getRequest ()->setParam ('attributes ' , $ attributes );
70
+
71
+ $ this ->dispatch ('backend/catalog/product_action_attribute/save/store/0 ' );
72
+ /** @var \Magento\Catalog\Model\Category $category */
73
+ $ categoryFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
74
+ \Magento \Catalog \Model \CategoryFactory::class
75
+ );
76
+ /** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
77
+ $ listProduct = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
78
+ \Magento \Catalog \Block \Product \ListProduct::class
79
+ );
80
+
81
+ $ category = $ categoryFactory ->create ()->load (2 );
82
+ $ layer = $ listProduct ->getLayer ();
83
+ $ layer ->setCurrentCategory ($ category );
84
+ $ productCollection = $ layer ->getProductCollection ();
85
+ $ productItem = $ productCollection ->getFirstItem ();
86
+ $ this ->assertEquals ($ session ->getProductIds (), [$ productItem ->getId ()]);
87
+ }
88
+
48
89
/**
49
90
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute
50
91
*
@@ -97,4 +138,17 @@ public function validateActionDataProvider()
97
138
]
98
139
];
99
140
}
141
+
142
+ /**
143
+ * Data Provider for save with visibility attribute
144
+ *
145
+ * @return array
146
+ */
147
+ public function saveActionVisibilityAttrDataProvider ()
148
+ {
149
+ return [
150
+ ['arguments ' => ['visibility ' => \Magento \Catalog \Model \Product \Visibility::VISIBILITY_BOTH ]],
151
+ ['arguments ' => ['visibility ' => \Magento \Catalog \Model \Product \Visibility::VISIBILITY_IN_CATALOG ]]
152
+ ];
153
+ }
100
154
}
0 commit comments