Inheritance: extends yii\db\ActiveRecord
 public function testDefaultConfigOldModel()
 {
     $comment = new Comment();
     $comment->text = 'test';
     $this->generateFiles(['png', 'jpg', 'txt']);
     $comment->save();
     Yii::$app->controller = new Controller('test', Yii::$app);
     $response = Yii::$app->controller->render('attachments-input-view', ['model' => $comment]);
     $this->assertContains("var fileInput = \$('#file-input');", $response);
     $this->assertContains("UploadForm[file][]", $response);
     $this->assertContains('jquery.js', $response);
     $this->assertContains('fileinput.js', $response);
     $this->assertContains('fileinput.css', $response);
     $this->assertContains('kv-widgets.css', $response);
     $this->assertContains('file-preview-image', $response);
     $this->assertContains('file-preview-other', $response);
     $this->assertContains('attachments%2Ffile%2Fdelete', $response);
 }
 public function testDefaultConfig()
 {
     $comment = new Comment();
     $comment->text = 'test';
     $types = ['png', 'txt', 'jpg'];
     $this->generateFiles($types);
     Yii::$app->runAction('attachments/file/upload');
     $comment->save();
     Yii::$app->controller = new Controller('test', Yii::$app, ['action' => 'test']);
     $response = Yii::$app->controller->render('attachments-table-view', ['model' => $comment]);
     $this->assertContains('table table-striped table-bordered table-condensed', $response);
     $this->assertContains("yii.gridView.js", $response);
     $this->assertContains('jquery.js', $response);
     $this->assertContains('yii.js', $response);
     $this->assertContains('yiiGridView', $response);
     $this->assertContains('file.png', $response);
     $this->assertContains('file.txt', $response);
     $this->assertContains('file.jpg', $response);
 }
Ejemplo n.º 3
0
 /**
  * Upload action test
  */
 public function testPreUpload1()
 {
     $types = ['png', 'txt', 'jpg'];
     $this->generateFiles($types);
     $response = Yii::$app->runAction('attachments/file/upload');
     $this->assertArrayHasKey('uploadedFiles', $response);
     $this->assertTrue(in_array('file.png', $response['uploadedFiles']));
     $this->checkFilesExist($types);
     foreach ($types as $type) {
         /** @var Response $response */
         $response = Yii::$app->runAction('attachments/file/download-temp', ['filename' => "file.{$type}"]);
         ob_start();
         $response->send();
         $actual = ob_get_clean();
         $response->clear();
         $expected = file_get_contents(Yii::getAlias("@tests/files/file.{$type}"));
         $this->assertEquals($expected, $actual);
         $response = Yii::$app->runAction('attachments/file/delete-temp', ['filename' => "file.{$type}"]);
         $this->assertEquals($response, []);
     }
     $this->checkFilesNotExist($types);
     $this->assertFileNotExists($this->getTempDirPath());
     $comment = new Comment();
     $comment->text = 'test';
     $this->assertTrue($comment->save());
     $file = $comment->files[0];
     /** @var Response $response */
     $response = Yii::$app->runAction('attachments/file/download', ['id' => $file->id]);
     ob_start();
     $response->send();
     $actual = ob_get_clean();
     $response->clear();
     $expected = file_get_contents(Yii::getAlias("@tests/files/file.{$file->type}"));
     $this->assertEquals($expected, $actual);
     $this->assertFileExists($file->path);
     $response = Yii::$app->runAction('attachments/file/delete', ['id' => -1]);
     $this->assertEquals($response, false);
     $response = Yii::$app->runAction('attachments/file/delete', ['id' => $file->id]);
     $this->assertEquals($response, true);
     $this->assertFileNotExists($file->path);
     $this->assertNotSame(false, $comment->delete());
 }
 /**
  * method that test if the system deleted a record
  */
 public function testDelete()
 {
     $id = $this->getLastId();
     $comment = Comment::findOne(['id' => $id]);
     $comment->delete();
 }