Skip to content

Commit

Permalink
Merge branch 'master' into mongo-fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-kate committed Jan 21, 2014
2 parents d5d810d + b85142a commit d28812e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
3 changes: 0 additions & 3 deletions apps/basic/tests/unit/models/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 13 additions & 2 deletions docs/guide/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,28 @@ 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';
}
],
```

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)
Expand Down
21 changes: 12 additions & 9 deletions docs/internals/report-an-issue.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion framework/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
'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',
Expand Down
11 changes: 4 additions & 7 deletions framework/test/ActiveFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,13 @@ public function load()
*/
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) : [];
}

/**
Expand Down
38 changes: 38 additions & 0 deletions framework/test/BaseActiveFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -66,4 +71,37 @@ public function getModel($name)
}
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}");
}
}
}

0 comments on commit d28812e

Please sign in to comment.