Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DashboardTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DashboardTest extends \PHPUnit\Framework\TestCase
11 {
13  private $block;
14 
16  private $customerSession;
17 
19  private $customerRepository;
20 
24  public function setUp()
25  {
26  $this->customerSession = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class);
27  $this->customerRepository = Bootstrap::getObjectManager()->get(
28  \Magento\Customer\Api\CustomerRepositoryInterface::class
29  );
30 
31  $this->block = Bootstrap::getObjectManager()->get(
32  \Magento\Framework\View\LayoutInterface::class
33  )->createBlock(
34  \Magento\Customer\Block\Account\Dashboard::class,
35  '',
36  [
37  'customerSession' => $this->customerSession,
38  'customerRepository' => $this->customerRepository
39  ]
40  );
41  }
42 
46  public function tearDown()
47  {
48  $this->customerSession->setCustomerId(null);
49 
52  ->get(\Magento\Customer\Model\CustomerRegistry::class);
53  //Cleanup customer from registry
54  $customerRegistry->remove(1);
55  }
56 
62  public function testGetCustomer()
63  {
64  $customer = $this->customerRepository->getById(1);
65  $this->customerSession->setCustomerId(1);
66  $object = $this->block->getCustomer();
67  $this->assertEquals($customer, $object);
68  $this->assertInstanceOf(\Magento\Customer\Api\Data\CustomerInterface::class, $object);
69  }
70 
77  {
78  $this->customerSession->setCustomerId(5);
79  $this->assertFalse($this->block->getPrimaryAddresses());
80  }
81 
89  {
90  $customer = $this->customerRepository->getById(1);
91  $this->customerSession->setCustomerId(1);
92  $addresses = $this->block->getPrimaryAddresses();
93  $this->assertCount(1, $addresses);
94  $address = $addresses[0];
95  $this->assertInstanceOf(\Magento\Customer\Api\Data\AddressInterface::class, $address);
96  $this->assertEquals((int)$customer->getDefaultBilling(), $address->getId());
97  $this->assertEquals((int)$customer->getDefaultShipping(), $address->getId());
98  }
99 
107  {
108  $this->customerSession->setCustomerId(1);
109  $addresses = $this->block->getPrimaryAddresses();
110  $this->assertCount(2, $addresses);
111  $this->assertNotEquals($addresses[0], $addresses[1]);
112  $this->assertTrue($addresses[0]->isDefaultBilling());
113  $this->assertTrue($addresses[1]->isDefaultShipping());
114  }
115 }
$customer
Definition: customers.php:11
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38
$customerRegistry
Definition: customers.php:12