99use EasySwoole \Permission \Config ;
1010use EasySwoole \ORM \Db \Connection ;
1111use EasySwoole \EasySwoole \Config as ESConfig ;
12- use EasySwoole \DDL \Blueprint \Create \Table as CreateTable ;
13- use EasySwoole \DDL \DDLBuilder ;
14- use EasySwoole \DDL \Enum \Character ;
15- use EasySwoole \DDL \Enum \Engine ;
1612
1713class DatabaseAdapterTest extends TestCase
1814{
@@ -31,7 +27,6 @@ protected function getEnforcer()
3127 $ this ->initConfig ();
3228 $ config = new Config ();
3329 $ casbin = new Casbin ($ config );
34- $ this ->initTable ();
3530 $ this ->initDb ();
3631 return $ casbin ->enforcer ();
3732 }
@@ -45,7 +40,7 @@ protected function initConfig()
4540 'port ' => 3306 ,
4641 'user ' => 'root ' ,
4742 'password ' => '' ,
48- 'database ' => 'easyswoole ' ,
43+ 'database ' => 'easyswoole_permission ' ,
4944 'timeout ' => 5 ,
5045 'charset ' => 'utf8mb4 ' ,
5146 ];
@@ -54,23 +49,6 @@ protected function initConfig()
5449 DbManager::getInstance ()->addConnection (new Connection ($ config ));
5550 }
5651
57- public function initTable ()
58- {
59- DDLBuilder::create ('casbin_rules ' , function (CreateTable $ table ) {
60- $ table ->setIfNotExists ()->setTableComment ('rule table of casbin ' );
61- $ table ->setTableCharset (Character::UTF8MB4_GENERAL_CI );
62- $ table ->setTableEngine (Engine::MYISAM );
63- $ table ->int ('id ' )->setIsUnsigned ()->setIsAutoIncrement ()->setIsPrimaryKey ();
64- $ table ->varchar ('ptype ' , 255 );
65- $ table ->varchar ('v0 ' , 255 );
66- $ table ->varchar ('v1 ' , 255 );
67- $ table ->varchar ('v2 ' , 255 );
68- $ table ->varchar ('v3 ' , 255 );
69- $ table ->varchar ('v4 ' , 255 );
70- $ table ->varchar ('v5 ' , 255 );
71- });
72- }
73-
7452 public function testRemovePolicy ()
7553 {
7654 $ e = $ this ->getEnforcer ();
@@ -130,4 +108,25 @@ public function testSavePolicy()
130108 $ adapter ->savePolicy ($ model );
131109 $ this ->assertTrue ($ e ->enforce ('alice ' , 'data4 ' , 'read ' ));
132110 }
111+
112+ public function testRemovePolicies ()
113+ {
114+ $ e = $ this ->getEnforcer ();
115+ $ this ->assertEquals ([
116+ ['alice ' , 'data1 ' , 'read ' ],
117+ ['bob ' , 'data2 ' , 'write ' ],
118+ ['data2_admin ' , 'data2 ' , 'read ' ],
119+ ['data2_admin ' , 'data2 ' , 'write ' ],
120+ ], $ e ->getPolicy ());
121+
122+ $ e ->removePolicies ([
123+ ['data2_admin ' , 'data2 ' , 'read ' ],
124+ ['data2_admin ' , 'data2 ' , 'write ' ],
125+ ]);
126+
127+ $ this ->assertEquals ([
128+ ['alice ' , 'data1 ' , 'read ' ],
129+ ['bob ' , 'data2 ' , 'write ' ]
130+ ], $ e ->getPolicy ());
131+ }
133132}
0 commit comments