public function testEncode_userProjectHasNoUserProfileProperties_noProjectSettings()
 {
     $environ = new MongoTestEnvironment();
     $environ->clean();
     $userId = $environ->createUser("User", "Name", "*****@*****.**");
     $user = new UserProfileModel($userId);
     $user->role = SiteRoles::USER;
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $project->addUser($userId, ProjectRoles::CONTRIBUTOR);
     $user->addProject($projectId);
     // user profile has data; but the encode method ignores it because the project has not enabled the 'city' property
     $projectUserProfile = new SfchecksUserProfile();
     $projectUserProfile->city = 'myCity';
     $user->projectUserProfiles[$projectId] = $projectUserProfile;
     $user->write();
     $project->write();
     $dto = UserProfileDto::encode($userId, $environ->website);
     $this->assertInternalType('array', $dto['userProfile']);
     $this->assertEquals($userId, $dto['userProfile']['id']);
     $this->assertEquals('Name', $dto['userProfile']['name']);
     $this->assertEquals(SiteRoles::USER, $dto['userProfile']['role']);
     $this->assertArrayHasKey('avatar_shape', $dto['userProfile']);
     $this->assertArrayHasKey('avatar_color', $dto['userProfile']);
     $this->assertFalse(isset($dto['userProfile']['projects']));
     $this->assertInternalType('array', $dto['projectsSettings']);
     $this->assertEquals(0, count($dto['projectsSettings']));
 }
 public function testEncode_Project_DtoCorrect()
 {
     $environ = new LexiconMongoTestEnvironment();
     $environ->clean();
     $userId = $environ->createUser('User', 'Name', '*****@*****.**');
     $user = new UserProfileModel($userId);
     $user->role = SystemRoles::USER;
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $project->addUser($userId, ProjectRoles::CONTRIBUTOR);
     $user->addProject($projectId);
     $user->interfaceLanguageCode = 'th';
     $user->write();
     $project->write();
     $dto = LexBaseViewDto::encode($projectId, $userId);
     // test for a few default values
     $this->assertEquals('en', $dto['config']['inputSystems']['en']['tag']);
     $this->assertTrue($dto['config']['tasks']['dbe']['visible']);
     $this->assertEquals('fields', $dto['config']['entry']['type'], 'dto config is not valid');
     $this->assertEquals('Word', $dto['config']['entry']['fields']['lexeme']['label']);
     $this->assertEquals('Word', $dto['config']['entry']['fields']['lexeme']['label']);
     $this->assertEquals('Part of Speech', $dto['config']['entry']['fields']['senses']['fields']['partOfSpeech']['label']);
     $this->assertTrue($dto['config']['roleViews']['contributor']['fields']['lexeme']['show']);
     $this->assertTrue($dto['config']['roleViews']['contributor']['showTasks']['dbe']);
     // todo re-enable this after userLanguageCode feature is mature
     //$this->assertEquals('th', $dto['interfaceConfig']['userLanguageCode']);
     $this->assertEquals('English', $dto['interfaceConfig']['selectLanguages']['options']['en']);
 }