customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); $this->subscriberFactory = Bootstrap::getObjectManager()->get(SubscriberFactory::class); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testGetSubscriptionStatusTest() { $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $query = <<graphQlQuery($query, [], '', $this->getHeaderMap($currentEmail, $currentPassword)); $this->assertFalse($response['customer']['is_subscribed']); } /** */ public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The current customer isn\'t authorized.'); $query = <<graphQlQuery($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testSubscribeCustomer() { $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $query = <<graphQlMutation( $query, [], '', $this->getHeaderMap($currentEmail, $currentPassword) ); $this->assertTrue($response['updateCustomer']['customer']['is_subscribed']); } /** */ public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest() { $this->expectException(\Exception::class); $this->expectExceptionMessage('The current customer isn\'t authorized.'); $query = <<graphQlMutation($query); } /** * @magentoApiDataFixture Magento/Newsletter/_files/subscribers.php */ public function testUnsubscribeCustomer() { $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $query = <<graphQlMutation($query, [], '', $this->getHeaderMap($currentEmail, $currentPassword)); $this->assertFalse($response['updateCustomer']['customer']['is_subscribed']); } /** * @magentoConfigFixture default_store customer/account_share/scope 0 * @magentoApiDataFixture Magento/Customer/_files/customer_for_second_website_with_address.php */ public function testSubscriptionStatusInMultiWebsiteSetup(): void { $currentEmail = 'customer_second_ws_with_addr@example.com'; $currentPassword = 'Apassword1'; $query = << 'default', 'Authorization' => sprintf( 'Bearer %s', $this->customerTokenService->createCustomerAccessToken($currentEmail, $currentPassword) ), ]; $response = $this->graphQlMutation($query, [], '', $headers); $this->assertTrue($response['updateCustomer']['customer']['is_subscribed']); } /** * @param string $email * @param string $password * * @return array * @throws AuthenticationException */ private function getHeaderMap(string $email, string $password): array { $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); return ['Authorization' => 'Bearer ' . $customerToken]; } protected function tearDown(): void { parent::tearDown(); $this->subscriberFactory->create()->loadByCustomerId(1)->delete(); } }