CollectionTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Newsletter\Model\ResourceModel\Problem;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class CollectionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Newsletter\Model\ResourceModel\Problem\Collection
  12. */
  13. protected $_collection;
  14. protected function setUp()
  15. {
  16. $this->_collection = Bootstrap::getObjectManager()
  17. ->create(\Magento\Newsletter\Model\ResourceModel\Problem\Collection::class);
  18. }
  19. /**
  20. * @magentoDataFixture Magento/Newsletter/_files/problems.php
  21. */
  22. public function testAddCustomersData()
  23. {
  24. /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
  25. $customerRepository = Bootstrap::getObjectManager()
  26. ->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
  27. $customer = $customerRepository->getById(1);
  28. /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
  29. $subscriber = Bootstrap::getObjectManager()
  30. ->create(\Magento\Newsletter\Model\Subscriber::class)->loadByEmail($customer->getEmail());
  31. /** @var \Magento\Newsletter\Model\Problem $problem */
  32. $problem = Bootstrap::getObjectManager()
  33. ->create(\Magento\Newsletter\Model\Problem::class)->addSubscriberData($subscriber);
  34. $item = $this->_collection->addSubscriberInfo()->load()->getFirstItem();
  35. $this->assertEquals($problem->getProblemErrorCode(), $item->getErrorCode());
  36. $this->assertEquals($problem->getProblemErrorText(), $item->getErrorText());
  37. $this->assertEquals($problem->getSubscriberId(), $item->getSubscriberId());
  38. $this->assertEquals($customer->getEmail(), $item->getSubscriberEmail());
  39. $this->assertEquals($customer->getFirstname(), $item->getCustomerFirstName());
  40. $this->assertEquals($customer->getLastname(), $item->getCustomerLastName());
  41. $this->assertContains($customer->getFirstname(), $item->getCustomerName());
  42. }
  43. }