|
2 | 2 |
|
3 | 3 | namespace yii\permission\tests;
|
4 | 4 |
|
5 |
| -use PHPUnit\Framework\TestCase; |
6 |
| -use yii\web\Application; |
7 | 5 | use Yii;
|
8 |
| -use yii\permission\models\CasbinRule; |
9 | 6 | use Casbin\Persist\Adapters\Filter;
|
10 | 7 | use Casbin\Exceptions\InvalidFilterTypeException;
|
11 | 8 | use yii\db\ActiveQueryInterface;
|
12 | 9 |
|
13 | 10 | class AdapterTest extends TestCase
|
14 | 11 | {
|
15 |
| - protected $app; |
16 |
| - |
17 | 12 | public function testEnforce()
|
18 | 13 | {
|
19 | 14 | $this->assertTrue(Yii::$app->permission->enforce('alice', 'data1', 'read'));
|
@@ -331,80 +326,4 @@ public function testLoadFilteredPolicy()
|
331 | 326 | ['alice', 'data1', 'read'],
|
332 | 327 | ], Yii::$app->permission->getPolicy());
|
333 | 328 | }
|
334 |
| - |
335 |
| - public function createApplication() |
336 |
| - { |
337 |
| - $config = require __DIR__ . '/../vendor/yiisoft/yii2-app-basic/config/web.php'; |
338 |
| - $config['components']['permission'] = require __DIR__ . '/../config/permission.php'; |
339 |
| - |
340 |
| - $config['components']['db']['dsn'] = 'mysql:host=' . $this->env('DB_HOST', '127.0.0.1') . ';port=' . $this->env('DB_PORT', '3306') . ';dbname=' . $this->env('DB_DATABASE', 'casbin'); |
341 |
| - $config['components']['db']['username'] = $this->env('DB_USERNAME', 'root'); |
342 |
| - $config['components']['db']['password'] = $this->env('DB_PASSWORD', ''); |
343 |
| - |
344 |
| - return new Application($config); |
345 |
| - } |
346 |
| - |
347 |
| - /** |
348 |
| - * init table. |
349 |
| - */ |
350 |
| - protected function initTable() |
351 |
| - { |
352 |
| - $db = CasbinRule::getDb(); |
353 |
| - $tableName = CasbinRule::tableName(); |
354 |
| - $table = $db->getTableSchema($tableName); |
355 |
| - if ($table) { |
356 |
| - $db->createCommand()->dropTable($tableName)->execute(); |
357 |
| - } |
358 |
| - |
359 |
| - Yii::$app->permission->init(); |
360 |
| - |
361 |
| - Yii::$app->db->createCommand()->batchInsert( |
362 |
| - $tableName, |
363 |
| - ['ptype', 'v0', 'v1', 'v2'], |
364 |
| - [ |
365 |
| - ['p', 'alice', 'data1', 'read'], |
366 |
| - ['p', 'bob', 'data2', 'write'], |
367 |
| - ['p', 'data2_admin', 'data2', 'read'], |
368 |
| - ['p', 'data2_admin', 'data2', 'write'], |
369 |
| - ['g', 'alice', 'data2_admin', null], |
370 |
| - ] |
371 |
| - )->execute(); |
372 |
| - } |
373 |
| - |
374 |
| - /** |
375 |
| - * Refresh the application instance. |
376 |
| - */ |
377 |
| - protected function refreshApplication() |
378 |
| - { |
379 |
| - $this->app = $this->createApplication(); |
380 |
| - } |
381 |
| - |
382 |
| - /** |
383 |
| - * This method is called before each test. |
384 |
| - */ |
385 |
| - protected function setUp(): void/* The :void return type declaration that should be here would cause a BC issue */ |
386 |
| - { |
387 |
| - if (!$this->app) { |
388 |
| - $this->refreshApplication(); |
389 |
| - } |
390 |
| - |
391 |
| - $this->initTable(); |
392 |
| - } |
393 |
| - |
394 |
| - /** |
395 |
| - * This method is called after each test. |
396 |
| - */ |
397 |
| - protected function tearDown(): void/* The :void return type declaration that should be here would cause a BC issue */ |
398 |
| - { |
399 |
| - } |
400 |
| - |
401 |
| - protected function env($key, $default = null) |
402 |
| - { |
403 |
| - $value = getenv($key); |
404 |
| - if (is_null($default)) { |
405 |
| - return $value; |
406 |
| - } |
407 |
| - |
408 |
| - return false === $value ? $default : $value; |
409 |
| - } |
410 | 329 | }
|
0 commit comments