Exemplo n.º 1
0
<?php

/**
 * Created by PhpStorm.
 * User: bill
 * Date: 16.02.15
 * Time: 16:06
 */
use app\modules\mobile\models\Document;
Document::deleteAll();
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that remove document works');
$id = Document::getCollection()->insertFile(\Yii::getAlias('@data') . '/file1.jpg');
$I->seeRecord(Document::className(), ['_id' => $id]);
$I->amOnPage(['mobile/number/detach-document', 'id' => (string) $id]);
$I->dontSeeRecord(Document::className(), ['_id' => $id]);
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQueryInterface
  */
 public function getDocuments()
 {
     return $this->hasMany(Document::className(), ['ownerId' => '_id']);
 }
Exemplo n.º 3
0
 public function testAttachDocuments()
 {
     Document::deleteAll();
     $model = new Number();
     $model->_id = 'NumberId';
     $this->specify("Error if Document model invalid.", function () use($model) {
         $model->attachDocument(Yii::getAlias('@data') . '/file2.pdf');
     }, ['throws' => new \RuntimeException()]);
     $this->specify("Error if argument not instance of UploadedFile or valid path to file.", function ($file) use($model) {
         $model->attachDocument($file);
     }, ['examples' => [["", []]], 'throws' => new \InvalidArgumentException()]);
     $model->save(false);
     $this->specify("Attachment must be save.", function ($file) use($model) {
         $model->attachDocument($file);
     }, ['examples' => [[Yii::getAlias('@data') . '/file2.pdf'], [new UploadedFile(['name' => 'file1.jpg', 'tempName' => \Yii::getAlias('@data') . '/file1.jpg', 'type' => mime_content_type(Yii::getAlias('@data') . '/file1.jpg')])]]]);
     $this->tester->seeRecord(Document::className(), ['filename' => 'file2.pdf', 'contentType' => 'application/pdf', 'ownerId' => 'NumberId']);
     $this->tester->seeRecord(Document::className(), ['filename' => 'file1.jpg', 'contentType' => 'image/jpeg', 'ownerId' => 'NumberId']);
 }