public function testSplitNumberList() { $list = MiscHelpers::splitNumberList(''); //var_dump($list); $this->assertTrue(is_array($list)); $this->assertTrue(count($list) == 0); $list = MiscHelpers::splitNumberList(' 123 '); //var_dump($list); $this->assertTrue(is_array($list)); $this->assertTrue(count($list) == 1); //$a = array_search(123, $list); //var_dump($a); $this->assertTrue(0 == array_search(123, $list)); $list = MiscHelpers::splitNumberList('10 11, 12'); //var_dump($list); $this->assertTrue(is_array($list)); $this->assertTrue(count($list) == 3); $this->assertTrue(2 == array_search(12, $list)); $list = MiscHelpers::splitNumberList('10 11 12 13'); //var_dump($list); $this->assertTrue(is_array($list)); $this->assertTrue(count($list) == 4); $this->assertTrue(2 == array_search(12, $list)); $list = MiscHelpers::splitNumberList('10 f 12'); //var_dump($list); $this->assertTrue($list == false); }
/** * This method is executed before AR is saved to database. * In this method, we set some model attributes. * @return boolean True on success. */ protected function beforeSave() { if (!parent::beforeSave()) { return false; } // Check if this is a new record. if ($this->isNewRecord) { // Set project id $this->project_id = Yii::app()->user->getCurProjectId(); // Set project version $curVer = false; $versions = Yii::app()->user->getCurProjectVersions($curVer); if ($curVer != Project::PROJ_VER_ALL) { $this->appversion_id = $curVer; } else { // Project version '<all>' currently selected. // We have to determine bug version from associated // crash reports/collections. $numbers = MiscHelpers::splitNumberList($this->crashgroups); foreach ($numbers as $number) { $crashGroup = CrashGroup::model()->findByPk($number); if ($crashGroup === Null) { throw new HttpException('Invalid crash group ID'); } $curVer = $crashGroup->appversion_id; break; } if ($curVer == -1) { $numbers = MiscHelpers::splitNumberList($this->crashreports); foreach ($numbers as $number) { $crashReport = CrashReport::model()->findByPk($number); if ($crashReport === Null) { throw new HttpException('Invalid crash report ID'); } $curVer = $crashReport->appversion_id; break; } } if ($curVer == -1) { throw new CHttpException(403, 'Invalid request'); } $this->appversion_id = $curVer; } // Set date created $this->date_created = time(); // Set date last modified $this->date_last_modified = $this->date_created; // Set reported by $this->reported_by = Yii::app()->user->id; if ($this->assigned_to < 0) { unset($this->assigned_to); } } else { // Set date last modified $this->date_last_modified = time(); if ($this->status > Bug::STATUS_OPEN_MAX) { $this->date_closed = $this->date_last_modified; } else { unset($this->date_closed); } } // Success. return true; }