diff --git a/apps/basic/tests/unit/models/UserTest.php b/apps/basic/tests/unit/models/UserTest.php index 3ff3c831ed..109da730d3 100644 --- a/apps/basic/tests/unit/models/UserTest.php +++ b/apps/basic/tests/unit/models/UserTest.php @@ -3,12 +3,9 @@ namespace tests\unit\models; use yii\codeception\TestCase; -use yii\test\DbTestTrait; class UserTest extends TestCase { - use DbTestTrait; - protected function setUp() { parent::setUp(); diff --git a/docs/guide/authorization.md b/docs/guide/authorization.md index 568b3b46ad..df40f2fae4 100644 --- a/docs/guide/authorization.md +++ b/docs/guide/authorization.md @@ -57,10 +57,10 @@ class SiteController extends Controller return [ 'access' => [ 'class' => \yii\web\AccessControl::className(), - 'only' => ['special'], + 'only' => ['special-callback'], 'rules' => [ [ - 'actions' => ['special'], + 'actions' => ['special-callback'], 'allow' => true, 'matchCallback' => function ($rule, $action) { return date('d-m') === '31-10'; @@ -68,6 +68,17 @@ class SiteController extends Controller ], ``` +And the action: + +```php + // ... + // Match callback called! This page can be accessed only each October 31st + public function actionSpecialCallback() + { + return $this->render('happy-halloween'); + } +``` + Sometimes you want a custom action to be taken when access is denied. In this case you can specify `denyCallback`. Role based access control (RBAC) diff --git a/docs/internals/report-an-issue.md b/docs/internals/report-an-issue.md index a41153a3f4..99c9aa31b6 100644 --- a/docs/internals/report-an-issue.md +++ b/docs/internals/report-an-issue.md @@ -1,14 +1,17 @@ -Creating issues +Report an Issue =============== -You got into rough corner while working with yii, or you found a bug? We are very sorry for that, but we can sort that -out together. +Please follow the guidelines below when creating an issue so that your issue can be more promptly resolved: -- If you are unsure about a function, you may ask on IRC or the forums. If the documentation is unclear, open a separate - issue. -- Please use English if possible. -- Make sure it is clear what is the problem and how to reproduce it. +* Provide information including: the version of PHP and Yii, the type of operating system and Web server, browser type and version; +* Provide the **complete** error call stack if available. A screenshot to explain the issue is very welcome. +* Describe the steps for reproducing the issue. It would be even better if you could provide code to reproduce the issue. -If you are going to report security issue please **do not** use the issue tracker and instead -[contact us directly](http://www.yiiframework.com/security/). +**Do not report an issue if** +* you are asking how to use some Yii feature. You should use [the forum](http://www.yiiframework.com/forum/index.php/forum/42-general-discussions-for-yii-20/) or [chat room](http://www.yiiframework.com/chat/) for this purpose. +* your issue is about security. Please [contact us directly](http://www.yiiframework.com/security/) to report security issues. + +**Avoid duplicated issues** + +Before you report an issue, please search through [existing issues](https://github.com/yiisoft/yii2/issues) to see if your issue is already reported or fixed to make sure you are not reporting a duplicated issue. Also make sure you have the latest version of Yii and see if the issue still exists. diff --git a/framework/classes.php b/framework/classes.php index 1dfc40a2d2..ea50822b22 100644 --- a/framework/classes.php +++ b/framework/classes.php @@ -174,7 +174,6 @@ return [ 'yii\rbac\Manager' => YII_PATH . '/rbac/Manager.php', 'yii\rbac\PhpManager' => YII_PATH . '/rbac/PhpManager.php', 'yii\requirements\YiiRequirementChecker' => YII_PATH . '/requirements/YiiRequirementChecker.php', - 'yii\test\DbTestTrait' => YII_PATH . '/test/DbTestTrait.php', 'yii\validators\BooleanValidator' => YII_PATH . '/validators/BooleanValidator.php', 'yii\validators\CompareValidator' => YII_PATH . '/validators/CompareValidator.php', 'yii\validators\DateValidator' => YII_PATH . '/validators/DateValidator.php', diff --git a/framework/test/ActiveFixture.php b/framework/test/ActiveFixture.php index 30c1f1a248..c86b9d35cd 100644 --- a/framework/test/ActiveFixture.php +++ b/framework/test/ActiveFixture.php @@ -100,16 +100,13 @@ class ActiveFixture extends BaseActiveFixture */ protected function getData() { - if ($this->dataFile === false) { - return []; - } - if ($this->dataFile !== null) { - $dataFile = Yii::getAlias($this->dataFile); - } else { + if ($this->dataFile === null) { $class = new \ReflectionClass($this); $dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php'; + return is_file($dataFile) ? require($dataFile) : []; + } else { + return parent::getData(); } - return is_file($dataFile) ? require($dataFile) : []; } /** diff --git a/framework/test/BaseActiveFixture.php b/framework/test/BaseActiveFixture.php index 26c4f75879..35240fdb9c 100644 --- a/framework/test/BaseActiveFixture.php +++ b/framework/test/BaseActiveFixture.php @@ -30,6 +30,11 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate * @var array the data rows. Each array element represents one row of data (column name => column value). */ public $data = []; + /** + * @var string|boolean the file path or path alias of the data file that contains the fixture data + * to be returned by [[getData()]]. You can set this property to be false to prevent loading any data. + */ + public $dataFile; /** * @var \yii\db\ActiveRecord[] the loaded AR models */ @@ -66,4 +71,37 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate } return $this->_models[$name] = $modelClass::find($keys); } + + /** + * Loads the fixture. + * + * The default implementation simply stores the data returned by [[getData()]] in [[data]]. + * You should usually override this method by putting the data into the underlying database. + */ + public function load() + { + $this->data = $this->getData(); + } + + /** + * Returns the fixture data. + * + * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. + * The file should return the data array that will be stored in [[data]] after inserting into the database. + * + * @return array the data to be put into the database + * @throws InvalidConfigException if the specified data file does not exist. + */ + protected function getData() + { + if ($this->dataFile === false || $this->dataFile === null) { + return []; + } + $dataFile = Yii::getAlias($this->dataFile); + if (is_file($dataFile)) { + return require($dataFile); + } else { + throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}"); + } + } }