installEntitySchema('node'); $this->installEntitySchema('user'); $this->installSchema('node', ['node_access']); $this->installConfig([ 'dotsoft_config_user' ]); } /** @test */ public function member_account_is_created_when_export_directory_exists(): void { $exportDirectory = $this->createNode(['type' => 'export_directory']); $uri = Url::fromRoute('dotsoft.users.register')->toString(); $request = Request::create($uri, 'POST', [], [], [], [], '{"email":"johndoe@example.com","password":"12345","export_directory":' . $exportDirectory->id() . '}'); $response = $this->container->get('http_kernel')->handle($request); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); $this->assertEquals('"Member account is created successfully"', $response->getContent()); $account = current(\Drupal::entityTypeManager() ->getStorage('user') ->loadByProperties(['mail' => 'johndoe@example.com'])); $this->assertNotEmpty($account); $this->assertEquals(['member'], $account->getRoles(true)); $this->assertNotEmpty($account->get('field_export_directory')->getValue()); $this->assertEquals($exportDirectory->id(), $account->get('field_export_directory')->getValue()[0]['target_id']); } /** @test */ public function member_account_is_created_when_export_directory_does_not_exist(): void { $uri = Url::fromRoute('dotsoft.users.register')->toString(); $request = Request::create($uri, 'POST', [], [], [], [], '{"email":"johndoe@example.com","password":"12345","export_directory_title":"DOTSOFT"}'); $response = $this->container->get('http_kernel')->handle($request); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode(), $response->getContent()); $this->assertEquals('"Member account is created successfully"', $response->getContent()); $account = current(\Drupal::entityTypeManager() ->getStorage('user') ->loadByProperties(['mail' => 'johndoe@example.com'])); $this->assertNotEmpty($account); $this->assertEquals(['member'], $account->getRoles(true)); $exportDirectory = current(\Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties([ 'type' => 'export_directory', 'title' => 'DOTSOFT' ])); $this->assertNotEmpty($exportDirectory); $this->assertEquals($account->id(), $exportDirectory->get('uid')->getValue()[0]['target_id']); $this->assertNotEmpty($account->get('field_export_directory')->getValue()); $this->assertEquals($exportDirectory->id(), $account->get('field_export_directory')->getValue()[0]['target_id']); } }