Inheritance: extends yii\base\Module
示例#1
0
 public function testInit()
 {
     Yii::$app->setModule('attachments', ['class' => Module::className()]);
     /** @var Module $module */
     $module = Yii::$app->getModule('attachments');
     $this->assertEquals(['maxFiles' => 3], $module->rules);
     $newRules = ['maxFiles' => 10, 'mimeTypes' => 'image/png', 'maxSize' => 1024];
     Yii::$app->setModule('attachments', ['class' => Module::className(), 'rules' => $newRules]);
     $module = Yii::$app->getModule('attachments');
     $this->assertEquals($newRules, $module->rules);
 }
 public function testPreUpload5()
 {
     Yii::$app->setModule('attachments', ['class' => Module::className(), 'rules' => ['maxFiles' => 3, 'mimeTypes' => ['image/png', 'image/jpeg']]]);
     $types = ['png', 'jpg', 'zip'];
     $this->generateFiles($types);
     $response = Yii::$app->runAction('attachments/file/upload');
     $this->assertArrayHasKey('error', $response);
     $errorMessage = 'Only files with these MIME types are allowed: image/png, image/jpeg.';
     $this->assertTrue(in_array($errorMessage, $response['error']));
 }
示例#3
0
 protected function mockApplication($config = [], $appClass = '\\yii\\web\\Application')
 {
     new $appClass(ArrayHelper::merge(['id' => 'test-app', 'basePath' => Yii::getAlias('@tests'), 'vendorPath' => Yii::getAlias('@tests/../vendor'), 'modules' => ['attachments' => ['class' => \nemmo\attachments\Module::className()]], 'components' => ['request' => ['cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', 'scriptFile' => Yii::getAlias('@tests/index.php'), 'scriptUrl' => '/index.php'], 'db' => ['class' => \yii\db\Connection::className(), 'dsn' => 'sqlite:' . Yii::getAlias('@tests/data/db.sqlite')], 'assetManager' => ['basePath' => '@tests/assets', 'baseUrl' => '/']]], $config));
 }