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->getCustomerAuthHeaders($currentEmail, $currentPassword)); $this->assertFalse($response['customer']['is_subscribed']); } /** * @expectedException \Exception * @expectedExceptionMessage The current customer isn't authorized. */ public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest() { $query = <<graphQlQuery($query); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testChangeSubscriptionStatusTest() { $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $query = <<graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); $this->assertTrue($response['updateCustomer']['customer']['is_subscribed']); } /** * @expectedException \Exception * @expectedExceptionMessage The current customer isn't authorized. */ public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest() { $query = <<graphQlQuery($query); } /** * @param string $email * @param string $password * @return array */ private function getCustomerAuthHeaders(string $email, string $password): array { $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); return ['Authorization' => 'Bearer ' . $customerToken]; } protected function tearDown() { parent::tearDown(); $this->subscriberFactory->create()->loadByCustomerId(1)->delete(); } }