Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SalesTest.php
Go to the documentation of this file.
1 <?php
7 
10 
16 class SalesTest extends \PHPUnit\Framework\TestCase
17 {
18  const MAIN_WEBSITE = 1;
19 
25  private $block;
26 
32  private $coreRegistry;
33 
39  private $html;
40 
44  public function setUp()
45  {
47  $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
48 
49  $this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
50  $this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
51 
52  $this->block = $objectManager->get(
53  \Magento\Framework\View\LayoutInterface::class
54  )->createBlock(
55  \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Sales::class,
56  'sales_' . mt_rand(),
57  ['coreRegistry' => $this->coreRegistry]
58  )->setTemplate(
59  'tab/view/sales.phtml'
60  );
61  $this->html = $this->block->toHtml();
62  }
63 
67  public function tearDown()
68  {
69  $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
70  $this->html = '';
71  }
72 
76  public function testFormatCurrency()
77  {
78  $this->assertEquals(
79  '<span class="price">$10.00</span>',
80  $this->block->formatCurrency(10.00, self::MAIN_WEBSITE)
81  );
82  }
83 
87  public function testIsSingleStoreMode()
88  {
89  $this->assertFalse($this->block->isSingleStoreMode());
90  }
91 
95  public function testGetTotals()
96  {
97  $this->assertEquals(
98  ['lifetime' => 0, 'base_lifetime' => 0, 'base_avgsale' => 0, 'num_orders' => 0],
99  $this->block->getTotals()->getData()
100  );
101  }
102 
106  public function testGetRows()
107  {
108  $this->assertEmpty($this->block->getRows());
109  }
110 
114  public function testGetWebsiteCount()
115  {
116  $this->assertEquals(0, $this->block->getWebsiteCount(self::MAIN_WEBSITE));
117  }
118 
122  public function testToHtml()
123  {
124  $this->assertContains('<span class="title">Sales Statistics</span>', $this->html);
125  $this->assertContains('<strong>All Store Views</strong>', $this->html);
126  }
127 }
$objectManager
Definition: bootstrap.php:17