@@ -140,21 +140,106 @@ public function testDeleteProduct() {
140140 }
141141
142142 /**
143- * Tests that anonymous users cannot see the admin/commerce/products page.
143+ * Tests viewing the admin/commerce/products page.
144144 */
145145 public function testAdminProducts () {
146146 $ this ->drupalGet ('admin/commerce/products ' );
147147 $ this ->assertSession ()->statusCodeEquals (200 );
148148 $ this ->assertSession ()->pageTextNotContains ('You are not authorized to access this page. ' );
149149 $ this ->assertNotEmpty ($ this ->getSession ()->getPage ()->hasLink ('Add product ' ));
150150
151+ // Create a default type product.
152+ $ product = $ this ->createEntity ('commerce_product ' , [
153+ 'type ' => 'default ' ,
154+ 'title ' => 'First product ' ,
155+ 'status ' => TRUE ,
156+ ]);
157+ // Create a second product type and products for that type.
158+ $ values = [
159+ 'id ' => 'random ' ,
160+ 'label ' => 'Random ' ,
161+ 'description ' => 'My random product type ' ,
162+ 'variationType ' => 'default ' ,
163+ ];
164+ $ product_type = $ this ->createEntity ('commerce_product_type ' , $ values );
165+ commerce_product_add_stores_field ($ product_type );
166+ commerce_product_add_variations_field ($ product_type );
167+ $ this ->createEntity ('commerce_product ' , [
168+ 'type ' => 'random ' ,
169+ 'title ' => 'Second product ' ,
170+ 'status ' => FALSE ,
171+ ]);
172+ $ this ->createEntity ('commerce_product ' , [
173+ 'type ' => 'random ' ,
174+ 'title ' => 'Third product ' ,
175+ 'status ' => TRUE ,
176+ ]);
177+
178+ $ this ->drupalGet ('admin/commerce/products ' );
179+ $ this ->assertSession ()->statusCodeEquals (200 );
180+ $ this ->assertSession ()->pageTextNotContains ('You are not authorized to access this page. ' );
181+ $ row_count = $ this ->getSession ()->getPage ()->findAll ('xpath ' , '//table/tbody/tr ' );
182+ $ this ->assertEquals (3 , count ($ row_count ), 'Table has 3 rows. ' );
183+
184+ // Confirm that product titles are displayed.
185+ $ page = $ this ->getSession ()->getPage ();
186+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="First product"] ' );
187+ $ this ->assertEquals (1 , count ($ product_count ), 'First product is displayed. ' );
188+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="Second product"] ' );
189+ $ this ->assertEquals (1 , count ($ product_count ), 'Second product is displayed. ' );
190+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="Third product"] ' );
191+ $ this ->assertEquals (1 , count ($ product_count ), 'Third product is displayed. ' );
192+
193+ // Confirm that product types are displayed.
194+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Default")] ' );
195+ $ this ->assertEquals (1 , count ($ product_count ), 'Default product type exists in the table. ' );
196+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Random")] ' );
197+ $ this ->assertEquals (2 , count ($ product_count ), 'Random product types exist in the table. ' );
198+
199+ // Confirm that product statuses are displayed.
200+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Unpublished")] ' );
201+ $ this ->assertEquals (1 , count ($ product_count ), 'Unpublished product exists in the table. ' );
202+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Published")] ' );
203+ $ this ->assertEquals (2 , count ($ product_count ), 'Published products exist in the table. ' );
204+
151205 // Logout and check that anonymous users cannot see the products page
152206 // and receive a 403 error code.
153207 $ this ->drupalLogout ();
154208 $ this ->drupalGet ('admin/commerce/products ' );
155209 $ this ->assertSession ()->statusCodeEquals (403 );
156210 $ this ->assertSession ()->pageTextContains ('You are not authorized to access this page. ' );
157211 $ this ->assertNotEmpty (!$ this ->getSession ()->getPage ()->hasLink ('Add product ' ));
212+
213+ // Login and confirm access for 'access commerce_product overview' permission.
214+ $ user = $ this ->drupalCreateUser (['access commerce_product overview ' ]);
215+ $ this ->drupalLogin ($ user );
216+ $ this ->drupalGet ('admin/commerce/products ' );
217+ $ this ->assertSession ()->statusCodeEquals (200 );
218+ $ this ->assertSession ()->pageTextNotContains ('You are not authorized to access this page. ' );
219+ $ this ->assertNotEmpty (!$ this ->getSession ()->getPage ()->hasLink ('Add product ' ));
220+ $ row_count = $ this ->getSession ()->getPage ()->findAll ('xpath ' , '//table/tbody/tr ' );
221+ $ this ->assertEquals (3 , count ($ row_count ), 'Table has 3 rows. ' );
222+
223+ // Confirm that product titles are displayed.
224+ $ page = $ this ->getSession ()->getPage ();
225+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="First product"] ' );
226+ $ this ->assertEquals (1 , count ($ product_count ), 'First product is displayed. ' );
227+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="Second product"] ' );
228+ $ this ->assertEquals (1 , count ($ product_count ), 'Second product is displayed. ' );
229+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td/a[text()="Third product"] ' );
230+ $ this ->assertEquals (1 , count ($ product_count ), 'Third product is displayed. ' );
231+
232+ // Confirm that product types are displayed.
233+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Default")] ' );
234+ $ this ->assertEquals (1 , count ($ product_count ), 'Default product type exists in the table. ' );
235+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Random")] ' );
236+ $ this ->assertEquals (2 , count ($ product_count ), 'Random product types exist in the table. ' );
237+
238+ // Confirm that product statuses are displayed.
239+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Unpublished")] ' );
240+ $ this ->assertEquals (1 , count ($ product_count ), 'Unpublished product exists in the table. ' );
241+ $ product_count = $ page ->findAll ('xpath ' , '//table/tbody/tr/td[starts-with(text(), "Published")] ' );
242+ $ this ->assertEquals (2 , count ($ product_count ), 'Published products exist in the table. ' );
158243 }
159244
160245}
0 commit comments