forked from luyadev/luya-module-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add relation property for SelectRelationActiveQuery closes luyadev#331
- Loading branch information
1 parent
e8e25d4
commit 5f2ca66
Showing
5 changed files
with
177 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/admin/ngrest/plugins/SelectRelationActiveQuerySqlLiteTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace admintests\admin\ngrest\plugins; | ||
|
||
use admintests\AdminModelTestCase; | ||
use luya\testsuite\fixtures\NgRestModelFixture; | ||
use luya\admin\models\User; | ||
use luya\admin\ngrest\plugins\SelectRelationActiveQuery; | ||
use luya\admin\ngrest\base\NgRestModel; | ||
use yii\base\Event; | ||
|
||
class SelectRelationActiveQueryTestSqlLite extends AdminModelTestCase | ||
{ | ||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testRelationLoad() | ||
{ | ||
$user = new NgRestModelFixture([ | ||
'modelClass' => User::class, | ||
'fixtureData' => [ | ||
"user1" => [ | ||
'id' => 1, | ||
'title' => 1, | ||
'firstname' => 'John', | ||
'lastname' => 'Doe', | ||
'email' => 'john@luya.io', | ||
'password' => 'nohash', | ||
'is_deleted' => 0, | ||
'is_api_user' => 0, | ||
] | ||
] | ||
]); | ||
|
||
$userModel = $user->getModel('user1'); | ||
|
||
$pluginModel = new NgRestModelFixture([ | ||
'modelClass' => TestModel::class, | ||
'fixtureData' => [ | ||
1 => [ | ||
'id' => 1, | ||
'user_id' => 1, | ||
] | ||
] | ||
]); | ||
|
||
$pluginModel1 = $pluginModel->getModel(1); | ||
|
||
$plugin = new SelectRelationActiveQuery([ | ||
'name' => 'user_id', | ||
'alias' => 'user_id', | ||
'i18n' => false, | ||
'relation' => 'user', | ||
'labelField' => ['lastname', 'firstname'], | ||
]); | ||
|
||
$event = new Event(); | ||
$event->sender = $pluginModel1; | ||
|
||
$plugin->onListFind($event); | ||
|
||
$this->assertSame('Doe John', $pluginModel1->user_id); | ||
} | ||
} | ||
|
||
class TestModel extends NgRestModel { | ||
|
||
public static function ngRestApiEndpoint() | ||
{ | ||
return 'api-end-point'; | ||
} | ||
|
||
public static function tableName() | ||
{ | ||
return 'footable'; | ||
} | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'user_id'], 'string'], | ||
]; | ||
} | ||
|
||
public function getUser() | ||
{ | ||
return $this->hasOne(User::class, ['id' => 'user_id']); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters