ProductTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Catalog\Controller\Product (bundle product type)
  8. */
  9. namespace Magento\Bundle\Controller;
  10. class ProductTest extends \Magento\TestFramework\TestCase\AbstractController
  11. {
  12. /**
  13. * @magentoDataFixture Magento/Bundle/_files/product.php
  14. * @magentoDbIsolation disabled
  15. */
  16. public function testViewAction()
  17. {
  18. /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
  19. $productRepository = $this->_objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
  20. $product = $productRepository->get('bundle-product');
  21. $this->dispatch('catalog/product/view/id/' . $product->getEntityId());
  22. $responseBody = $this->getResponse()->getBody();
  23. $this->assertContains('Bundle Product', $responseBody);
  24. $this->assertContains(
  25. 'In stock',
  26. $responseBody,
  27. 'Bundle Product Detailed Page does not contain In Stock field'
  28. );
  29. $addToCartCount = substr_count($responseBody, '<span>Add to Cart</span>');
  30. $this->assertEquals(1, $addToCartCount, '"Add to Cart" button should appear on the page exactly once.');
  31. $actualLinkCount = substr_count($responseBody, '>Bundle Product Items<');
  32. $this->assertEquals(1, $actualLinkCount, 'Bundle product options should appear on the page exactly once.');
  33. $this->assertNotContains('class="options-container-big"', $responseBody);
  34. $this->assertEquals(
  35. 1,
  36. \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
  37. '//*[@id="product-options-wrapper"]',
  38. $responseBody
  39. )
  40. );
  41. }
  42. }