public function testCheckFileAttachment() { // Create temp file $tmpfile1 = tempnam(Yii::app()->getRuntimePath(), "test"); $tmpfile = $tmpfile1 . '.zip'; $f = fopen($tmpfile, 'w'); fwrite($f, 'MZP1234567'); fclose($f); // Create new model $model = new CrashReport(); $model->md5 = '123456789012345678'; // Ensure file attachment check fails (null attachment) $this->assertFalse($model->checkFileAttachment()); $model->fileAttachment = new CUploadedFile('test.zip', $tmpfile, 'application/octet-stream', 5, 0); // Ensure file attachment check fails (md5 is incorrect) $this->assertFalse($model->checkFileAttachment()); $model->md5 = md5_file($tmpfile); // Ensure file attachment check succeeds $this->assertTrue($model->checkFileAttachment()); // Remove temp file unlink($tmpfile); unlink($tmpfile1); }