/**
  * @param string $projectId
  * @param array $object (json encoded)
  * @return string Id of text updated/added
  */
 public static function updateText($projectId, $object)
 {
     $projectModel = new ProjectModel($projectId);
     ProjectCommands::checkIfArchivedAndThrow($projectModel);
     $textModel = new TextModel($projectModel);
     $isNewText = $object['id'] == '';
     if (!$isNewText) {
         $textModel->read($object['id']);
     }
     JsonDecoder::decode($textModel, $object);
     TextCommands::makeValidRange($object);
     if (TextCommands::hasRange($object)) {
         $usxTrimHelper = new UsxTrimHelper($textModel->content, $object['startCh'] || 0, $object['startVs'] || 0, $object['endCh'] || 0, $object['endVs'] || 0);
         $textModel->content = $usxTrimHelper->trimUsx();
     }
     $textId = $textModel->write();
     if ($isNewText) {
         ActivityCommands::addText($projectModel, $textId, $textModel);
     }
     return $textId;
 }
 public function testTrim_zeroStartChapter()
 {
     // Start chapter of 0 means "from start of book"
     $usx = MongoTestEnvironment::usxSample();
     $usxHelper = new UsxTrimHelper($usx, 0, 0, 3, 16);
     $result = $usxHelper->trimUsx();
     $simple = new SimpleXMLElement($result);
     $this->assertTrue(self::hasChapter($simple, 1));
     $this->assertTrue(self::hasChapter($simple, 2));
     $this->assertTrue(self::hasChapter($simple, 3));
     $this->assertFalse(self::hasChapter($simple, 4));
     // John 1 has 51 verses; John 2 has 25 verses
     $this->assertTrue(self::hasVerse($simple, 1, 1));
     $this->assertTrue(self::hasVerse($simple, 1, 51));
     $this->assertTrue(self::hasVerse($simple, 2, 1));
     $this->assertTrue(self::hasVerse($simple, 2, 25));
     $this->assertTrue(self::hasVerse($simple, 3, 1));
     $this->assertTrue(self::hasVerse($simple, 3, 16));
     $this->assertFalse(self::hasVerse($simple, 3, 17));
     $this->assertFalse(self::hasVerse($simple, 4, 1));
 }