/**
  * @expectedException Api\Library\Shared\Palaso\Exception\UserUnauthorizedException
  */
 public function testDeleteProjects_NotProjectOwner_Throw()
 {
     self::$environ->clean();
     $user1Id = self::$environ->createUser("user1name", "User1 Name", "*****@*****.**");
     $user2Id = self::$environ->createUser("user2name", "User2 Name", "*****@*****.**");
     $user1 = new UserModel($user1Id);
     $user2 = new UserModel($user2Id);
     $projectId = ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, SfProjectModel::SFCHECKS_APP, $user1->id->asString(), self::$environ->website);
     $project = new ProjectModel($projectId);
     $project->addUser($user2->id->asString(), ProjectRoles::MANAGER);
     ProjectCommands::deleteProjects(array($projectId), $user2Id);
 }
 public function testLexEntryCrud_CreateUpdateDeleteListOk()
 {
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     // create an user and add to the project
     $userId = self::$environ->getProjectMember($projectId, 'user1');
     $entry = new LexEntryModel($project);
     $entry->lexeme->form('th', 'SomeEntry');
     $sense = new LexSense();
     $sense->definition->form('en', 'red fruit');
     $sense->partOfSpeech->value = 'noun';
     $example = new LexExample();
     $example->sentence->form('th', 'example1');
     $example->translation->form('en', 'trans1');
     $sense->examples[] = $example;
     $entry->senses[] = $sense;
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEquals(0, $dto->count);
     // Create
     $params = JsonEncoder::encode($entry);
     $result1 = LexEntryCommands::updateEntry($projectId, $params, $userId);
     $entryId = $result1['id'];
     $this->assertNotNull($entryId);
     $this->assertEquals(24, strlen($entryId));
     // Read
     $result2 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result2['id']);
     $this->assertEquals('SomeEntry', $result2['lexeme']['th']['value']);
     // Update
     $result2['lexeme']['th']['value'] = 'OtherEntry';
     $result3 = LexEntryCommands::updateEntry($projectId, $result2, $userId);
     $this->assertNotNull($result3);
     $this->assertEquals($entryId, $result3['id']);
     // Read back
     $result4 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result4['id']);
     $this->assertEquals('OtherEntry', $result4['lexeme']['th']['value']);
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEquals(1, $dto->count);
     // Delete
     $result5 = LexEntryCommands::removeEntry($projectId, $entryId, $userId);
     $this->assertTrue($result5);
     // List to confirm delete
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEquals(0, $dto->count);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId), $project->ownerRef->asString());
 }
 /**
  * Clear out the session projectId and permanently delete selected list of projects.
  *
  * @param array<string> $projectIds Default to current projectId
  * @return int Total number of projects removed.
  */
 public function project_delete($projectIds)
 {
     if (empty($projectIds)) {
         $projectIds = array($this->projectId);
     }
     $this->app['session']->set('projectId', "");
     return ProjectCommands::deleteProjects($projectIds, $this->userId);
 }
 public function testTextCRUD_CRUDOK()
 {
     $projectId = self::$environ->makeProject();
     $project = new ProjectModel($projectId);
     $userId = self::$environ->getProjectMember($projectId, 'user1');
     // Initial List
     $result = self::$environ->fixJson(ProjectPageDto::encode($projectId, $userId));
     $count = count($result['texts']);
     // Create
     $model = array('id' => '', 'title' => 'SomeText');
     $id = TextCommands::updateText($projectId, $model);
     $this->assertNotNull($id);
     $this->assertEquals(24, strlen($id));
     // Read
     $result = self::$environ->fixJson(TextCommands::readText($projectId, $id));
     $this->assertNotNull($result['id']);
     $this->assertEquals('SomeText', $result['title']);
     // Update
     $result['title'] = 'OtherText';
     $id = TextCommands::updateText($projectId, $result);
     $this->assertNotNull($id);
     $this->assertEquals($result['id'], $id);
     // Read back
     $result = self::$environ->fixJson(TextCommands::readText($projectId, $id));
     $this->assertEquals('OtherText', $result['title']);
     // List
     $result = self::$environ->fixJson(ProjectPageDto::encode($projectId, $userId));
     $this->assertCount($count + 1, $result['texts']);
     // Delete
     $result = TextCommands::deleteTexts($projectId, array($id));
     $this->assertTrue($result > 0);
     // List to confirm delete
     $result = self::$environ->fixJson(ProjectPageDto::encode($projectId, $userId));
     $this->assertCount($count, $result['texts']);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId), $project->ownerRef->asString());
 }