Skip to content

Commit 89b5a6f

Browse files
committed
Complete another test
1 parent e08b802 commit 89b5a6f

File tree

16 files changed

+304
-14
lines changed

16 files changed

+304
-14
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\abc;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
}
12+
13+
14+
}
15+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace app\abc;
4+
5+
class TaskController extends \app\abc\base\TaskController
6+
{
7+
8+
public function actions()
9+
{
10+
$actions = parent::actions();
11+
return $actions;
12+
}
13+
14+
public function checkAccess($action, $model = null, $params = [])
15+
{
16+
//TODO implement checkAccess
17+
}
18+
19+
20+
}
21+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
namespace app\abc\base;
3+
4+
use insolita\fractal\JsonApiController;
5+
use Yii;
6+
7+
abstract class TaskController extends JsonApiController
8+
{
9+
public function actions()
10+
{
11+
return [
12+
'view' => [
13+
'class' => \insolita\fractal\actions\ViewAction::class,
14+
'checkAccess' => [$this, 'checkAccess'],
15+
'transformer' => \app\transformers\TaskTransformer::class,
16+
'modelClass' => \app\models\Task::class,
17+
'resourceKey' => 'tasks',
18+
'findModel' => null
19+
],
20+
'options' => [
21+
'class' => \yii\rest\OptionsAction::class,
22+
],
23+
];
24+
}
25+
26+
/**
27+
* Checks the privilege of the current user.
28+
*
29+
* This method checks whether the current user has the privilege
30+
* to run the specified action against the specified data model.
31+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
32+
*
33+
* @param string $action the ID of the action to be executed
34+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
35+
* @param array $params additional parameters
36+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
37+
*/
38+
abstract public function checkAccess($action, $model = null, $params = []);
39+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET hi' => 'greet/default',
9+
'GET bye' => 'bye/list',
10+
'POST bye' => 'bye/create',
11+
'GET abc/task/<id:\d+>' => 'abc/task/view',
12+
'hi' => 'greet/options',
13+
'bye' => 'bye/options',
14+
'abc/task/<id:\d+>' => 'abc/task/options',
15+
];
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
class ByeController extends \app\controllers\base\ByeController
6+
{
7+
8+
public function actions()
9+
{
10+
$actions = parent::actions();
11+
return $actions;
12+
}
13+
14+
public function checkAccess($action, $model = null, $params = [])
15+
{
16+
//TODO implement checkAccess
17+
}
18+
19+
public function actionList()
20+
{
21+
//TODO implement actionList
22+
}
23+
24+
public function actionCreate()
25+
{
26+
//TODO implement actionCreate
27+
}
28+
29+
30+
}
31+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace app\controllers\base;
3+
4+
use insolita\fractal\JsonApiController;
5+
use Yii;
6+
7+
abstract class ByeController extends JsonApiController
8+
{
9+
public function actions()
10+
{
11+
return [
12+
'options' => [
13+
'class' => \yii\rest\OptionsAction::class,
14+
],
15+
];
16+
}
17+
18+
/**
19+
* Checks the privilege of the current user.
20+
*
21+
* This method checks whether the current user has the privilege
22+
* to run the specified action against the specified data model.
23+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
24+
*
25+
* @param string $action the ID of the action to be executed
26+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
27+
* @param array $params additional parameters
28+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
29+
*/
30+
abstract public function checkAccess($action, $model = null, $params = []);
31+
32+
abstract public function actionList();
33+
34+
abstract public function actionCreate();
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace app\greet;
4+
5+
class DefaultController extends \app\greet\base\DefaultController
6+
{
7+
8+
public function actions()
9+
{
10+
$actions = parent::actions();
11+
return $actions;
12+
}
13+
14+
public function checkAccess($action, $model = null, $params = [])
15+
{
16+
//TODO implement checkAccess
17+
}
18+
19+
public function action()
20+
{
21+
//TODO implement action
22+
}
23+
24+
25+
}
26+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\greet;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
}
12+
13+
14+
}
15+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace app\greet\base;
3+
4+
use insolita\fractal\JsonApiController;
5+
use Yii;
6+
7+
abstract class DefaultController extends JsonApiController
8+
{
9+
public function actions()
10+
{
11+
return [
12+
'options' => [
13+
'class' => \yii\rest\OptionsAction::class,
14+
],
15+
];
16+
}
17+
18+
/**
19+
* Checks the privilege of the current user.
20+
*
21+
* This method checks whether the current user has the privilege
22+
* to run the specified action against the specified data model.
23+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
24+
*
25+
* @param string $action the ID of the action to be executed
26+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
27+
* @param array $params additional parameters
28+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
29+
*/
30+
abstract public function checkAccess($action, $model = null, $params = []);
31+
32+
abstract public function action();
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Task extends \app\models\base\Task
6+
{
7+
8+
9+
}
10+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
7+
namespace app\models\base;
8+
9+
/**
10+
* This is the model class for table "tasks".
11+
*
12+
* @property int $id
13+
* @property string $title
14+
*
15+
*/
16+
abstract class Task extends \yii\db\ActiveRecord
17+
{
18+
public static function tableName()
19+
{
20+
return '{{%tasks}}';
21+
}
22+
23+
public function rules()
24+
{
25+
return [
26+
'trim' => [['title'], 'trim'],
27+
'title_string' => [['title'], 'string'],
28+
];
29+
}
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\transformers;
4+
5+
class TaskTransformer extends \app\transformers\base\TaskTransformer
6+
{
7+
8+
9+
}
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace app\transformers\base;
3+
4+
use League\Fractal\TransformerAbstract;
5+
use app\models\Task;
6+
7+
class TaskTransformer extends TransformerAbstract
8+
{
9+
protected array $availableIncludes = [];
10+
protected array $defaultIncludes = [];
11+
12+
public function transform(Task $model)
13+
{
14+
return $model->getAttributes();
15+
}
16+
}

tests/specs/issue_fix/14_module_config_in_url_prefixes/index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
'openApiPath' => '@specs/issue_fix/14_module_config_in_url_prefixes/index.yml',
55
'generateUrls' => true,
66
'generateModels' => true,
7-
// 'useJsonApi' => true, // TODO for FractalAction
87
'excludeModels' => [
98
'Error',
109
],
1110
'generateControllers' => true,
1211
'generateMigrations' => false,
1312
'generateModelFaker' => false,
1413
'urlPrefixes' => [
15-
'hi' => ['module' => 'greet', 'namespace' => 'app\greet'], // TODO `hi/` trailing slash in generated URL rules config
14+
'hi' => ['module' => 'greet', 'namespace' => 'app\greet'],
1615
'abc' => ['module' => 'abc', 'namespace' => 'app\abc'],
1716
]
1817
];

tests/specs/issue_fix/14_nested_module_in_x_route/index.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
'openApiPath' => '@specs/issue_fix/14_nested_module_in_x_route/index.yml',
55
'generateUrls' => true,
66
'generateModels' => true,
7-
// 'useJsonApi' => true, // TODO for FractalAction
87
'excludeModels' => [
98
'Error',
109
],
1110
'generateControllers' => true,
1211
'generateMigrations' => false,
1312
'generateModelFaker' => false,
14-
// 'urlPrefixes' => [
15-
// 'hi' => ['module' => 'greet', 'namespace' => 'app\greet'],
16-
// 'abc' => ['module' => 'abc', 'namespace' => 'app\abc'],
17-
// ]
1813
];

tests/unit/issues/Issue14Test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public function testModuleConfigInUrlPrefixesFractalAction()
6666

6767
$testFile = Yii::getAlias($tmpConfigFile);
6868
$this->runGenerator($testFile);
69-
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [ TODO
70-
// 'recursive' => true,
71-
// ]);
72-
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/14_module_config_in_url_prefixes/mysql"), [
73-
// 'recursive' => true,
74-
// ]);
75-
// $this->checkFiles($actualFiles, $expectedFiles);
69+
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
70+
'recursive' => true,
71+
]);
72+
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/14_module_config_in_url_prefixes/fractal"), [
73+
'recursive' => true,
74+
]);
75+
$this->checkFiles($actualFiles, $expectedFiles);
7676

7777
FileHelper::unlink($tmpConfigFile);
7878
}

0 commit comments

Comments
 (0)