Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CartsTest.php
Go to the documentation of this file.
1 <?php
7 
13 class CartsTest extends \PHPUnit\Framework\TestCase
14 {
16  private $_block;
17 
19  private $_customerRepository;
20 
22  private $_context;
23 
25  private $_objectManager;
26 
27  public function setUp()
28  {
30  $this->_customerRepository = $this->_objectManager->get(
31  \Magento\Customer\Api\CustomerRepositoryInterface::class
32  );
33  $storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManager::class);
34  $this->_context = $this->_objectManager->get(
35  \Magento\Backend\Block\Template\Context::class,
36  ['storeManager' => $storeManager]
37  );
38  }
39 
43  public function testGetHtml()
44  {
45  $customer = $this->_customerRepository->getById(1);
46  $data = ['account' => $customer->__toArray()];
47  $this->_context->getBackendSession()->setCustomerData($data);
48 
49  $this->_block = $this->_objectManager->get(
50  \Magento\Framework\View\LayoutInterface::class
51  )->createBlock(
52  \Magento\Customer\Block\Adminhtml\Edit\Tab\Carts::class,
53  '',
54  ['context' => $this->_context]
55  );
56 
57  $html = $this->_block->toHtml();
58  $this->assertContains("<div id=\"customer_cart_grid1\"", $html);
59  $this->assertRegExp(
60  '/<div class=".*admin__data-grid-toolbar"/',
61  $html
62  );
63  $this->assertContains("customer_cart_grid1JsObject = new varienGrid(\"customer_cart_grid1\",", $html);
64  $this->assertContains(
65  'backend\u002Fcustomer\u002Fcart_product_composite_cart\u002Fconfigure\u002Fwebsite_id\u002F1',
66  $html
67  );
68  }
69 
70  public function testGetHtmlNoCustomer()
71  {
72  $data = ['account' => []];
73  $this->_context->getBackendSession()->setCustomerData($data);
74 
75  $this->_block = $this->_objectManager->get(
76  \Magento\Framework\View\LayoutInterface::class
77  )->createBlock(
78  \Magento\Customer\Block\Adminhtml\Edit\Tab\Carts::class,
79  '',
80  ['context' => $this->_context]
81  );
82 
83  $html = $this->_block->toHtml();
84  $this->assertContains("<div id=\"customer_cart_grid\"", $html);
85  $this->assertRegExp(
86  '/<div class=".*admin__data-grid-toolbar"/',
87  $html
88  );
89  $this->assertContains("customer_cart_gridJsObject = new varienGrid(\"customer_cart_grid\",", $html);
90  $this->assertContains('backend\u002Fcustomer\u002Fcart_product_composite_cart\u002Fupdate\u002Fkey', $html);
91  }
92 }
$customer
Definition: customers.php:11
$storeManager