public function testSaveDirectory() { $directory = new FileDirectory(); $fileDirectory = FileDirectory::findOne((int) 1); $directory->attachBehavior('DirectorySave', array('class' => DirectoryBehavior::className(), 'directoryName' => self::$directoryName, 'directoryPath' => $fileDirectory->path)); $directory->parent_id = $fileDirectory->id; $this->assertTrue($directory->save()); }
public function actionDeleteDirectory() { $request = Yii::$app->request; if ($request->post('id')) { $id = (int) $request->post('id'); if (!$id) { throw new HttpException(404, Yii::t('Admin', 'Directory Id not found')); } $model = FileDirectory::findOne($id); if ($model === null) { throw new HttpException(404, Yii::t('Admin', 'Directory not found')); } if (!$model->delete()) { $request->headers->add('HTTP/1.1 400 Bad request', ''); return $this->renderAjax('deleteFile_json', ['model' => $model, 'status' => false]); } if ($request->isAjax) { $this->deleteDir($this->getPathByModel($model)); $request->headers->add('HTTP/1.1 201 Created', ''); return $this->renderAjax('deleteFile_json', ['model' => $model, 'status' => true]); } } else { throw new HttpException(403, Yii::t('yii', 'You are not authorized to perform this action.')); } }