public function testCRUD_Works() { $environ = new MongoTestEnvironment(); $environ->clean(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); // List $list = new TextListModel($project); $list->read(); $this->assertEquals(0, $list->count); // Create $text = new TextModel($project); $text->title = "Some Text"; $usx = MongoTestEnvironment::usxSample(); $text->content = $usx; $id = $text->write(); $this->assertNotNull($id); $this->assertInternalType('string', $id); $this->assertEquals($text->id->asString(), $id); // Read back $otherText = new TextModel($project, $id); $this->assertEquals($id, $otherText->id->asString()); $this->assertEquals('Some Text', $otherText->title); $this->assertEquals($usx, $otherText->content); // Update $otherText->title = 'Other Text'; $otherText->write(); // Read back $otherText = new TextModel($project, $id); $this->assertEquals('Other Text', $otherText->title); // List $list->read(); $this->assertEquals(1, $list->count); // Delete TextModel::remove($project->databaseName(), $id); // List $list->read(); $this->assertEquals(0, $list->count); }
/** * @param string $projectId * @param array $textIds * @return int Total number of texts removed. */ public static function deleteTexts($projectId, $textIds) { $projectModel = new ProjectModel($projectId); $count = 0; foreach ($textIds as $textId) { TextModel::remove($projectModel->databaseName(), $textId); $count++; } return $count; }