getProduct(); $this->login(1); $this->prepareRequestData(); $this->dispatch('sendfriend/product/sendmail/id/' . $product->getId()); $this->assertSessionMessages( $this->equalTo(['The link to a friend was sent.']), MessageInterface::TYPE_SUCCESS ); } /** * Share the product to friend as guest customer * * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoConfigFixture default_store sendfriend/email/enabled 1 * @magentoConfigFixture default_store sendfriend/email/allow_guest 1 * @magentoDataFixture Magento/Catalog/_files/products.php */ public function testSendActionAsGuest() { $product = $this->getProduct(); $this->prepareRequestData(); $this->dispatch('sendfriend/product/sendmail/id/' . $product->getId()); $this->assertSessionMessages( $this->equalTo(['The link to a friend was sent.']), MessageInterface::TYPE_SUCCESS ); } /** * Share the product to friend as guest customer with invalid post data * * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoConfigFixture default_store sendfriend/email/enabled 1 * @magentoConfigFixture default_store sendfriend/email/allow_guest 1 * @magentoDataFixture Magento/Catalog/_files/products.php */ public function testSendActionAsGuestWithInvalidData() { $product = $this->getProduct(); $this->prepareRequestData(true); $this->dispatch('sendfriend/product/sendmail/id/' . $product->getId()); $this->assertSessionMessages( $this->equalTo(['Invalid Sender Email']), MessageInterface::TYPE_ERROR ); } /** * @return ProductInterface */ private function getProduct() { return $this->_objectManager->get(ProductRepositoryInterface::class)->get('custom-design-simple-product'); } /** * Login the user * * @param string $customerId Customer to mark as logged in for the session * @return void */ protected function login($customerId) { /** @var Session $session */ $session = Bootstrap::getObjectManager() ->get(Session::class); $session->loginById($customerId); } /** * @param bool $invalidData * @return void */ private function prepareRequestData($invalidData = false) { /** @var FormKey $formKey */ $formKey = $this->_objectManager->get(FormKey::class); $post = [ 'sender' => [ 'name' => 'Test', 'email' => 'test@example.com', 'message' => 'Message', ], 'recipients' => [ 'name' => [ 'Recipient 1', 'Recipient 2' ], 'email' => [ 'r1@example.com', 'r2@example.com' ] ], 'form_key' => $formKey->getFormKey(), ]; if ($invalidData) { unset($post['sender']['email']); } $this->getRequest()->setMethod(Request::METHOD_POST); $this->getRequest()->setPostValue($post); } }