public function testDeleteProjects_NoThrow()
 {
     $this->environ->clean();
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     ProjectCommands::deleteProjects(array($projectId));
 }
 public function testLexEntryCrud_CreateUpdateDeleteListOk()
 {
     $e = new LexiconMongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     // create an user and add to the project
     $userId = $e->getProjectMember($projectId, 'user1');
     $entry = new LexEntryModel($project);
     $entry->lexeme->form('th', 'SomeEntry');
     $sense = new Sense();
     $sense->definition->form('en', 'red fruit');
     $sense->partOfSpeech->value = 'noun';
     $example = new Example();
     $example->sentence->form('th', 'example1');
     $example->translation->form('en', 'trans1');
     $sense->examples[] = $example;
     $entry->senses[] = $sense;
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 0);
     // Create
     $params = JsonEncoder::encode($entry);
     $result1 = LexEntryCommands::updateEntry($projectId, $params, $userId);
     $entryId = $result1['id'];
     $this->assertNotNull($entryId);
     $this->assertEqual(24, strlen($entryId));
     // Read
     $result2 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result2['id']);
     $this->assertEqual('SomeEntry', $result2['lexeme']['th']['value']);
     // Update
     $result2['lexeme']['th']['value'] = 'OtherEntry';
     $result3 = LexEntryCommands::updateEntry($projectId, $result2, $userId);
     $this->assertNotNull($result3);
     $this->assertEqual($result3['id'], $entryId);
     // Read back
     $result4 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result4['id']);
     $this->assertEqual('OtherEntry', $result4['lexeme']['th']['value']);
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 1);
     // Delete
     $result5 = LexEntryCommands::removeEntry($projectId, $entryId, $userId);
     $this->assertTrue($result5);
     // List to confirm delete
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 0);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId));
 }
Exemplo n.º 3
0
 public function testTextCRUD_CRUDOK()
 {
     $e = new ApiCrudTestEnvironment();
     $projectId = $e->makeProject();
     $userId = $e->getProjectMember($projectId, 'user1');
     // Initial List
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $count = count($result['texts']);
     // Create
     $model = array('id' => '', 'title' => 'SomeText');
     $id = TextCommands::updateText($projectId, $model);
     $this->assertNotNull($id);
     $this->assertEqual(24, strlen($id));
     // Read
     $result = $e->json(TextCommands::readText($projectId, $id));
     $this->assertNotNull($result['id']);
     $this->assertEqual('SomeText', $result['title']);
     // Update
     $result['title'] = 'OtherText';
     $id = TextCommands::updateText($projectId, $result);
     $this->assertNotNull($id);
     $this->assertEqual($result['id'], $id);
     // Read back
     $result = $e->json(TextCommands::readText($projectId, $id));
     $this->assertEqual('OtherText', $result['title']);
     // List
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $this->assertEqual($count + 1, count($result['texts']));
     // Delete
     $result = TextCommands::deleteTexts($projectId, array($id));
     $this->assertTrue($result);
     // List to confirm delete
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $this->assertEqual($count, count($result['texts']));
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId));
 }