public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); Yii::app()->user->userModel = User::getByUsername('super'); SecurityTestHelper::createUsers(); SecurityTestHelper::createGroups(); SecurityTestHelper::createAccounts(); SecurityTestHelper::createRoles(); $everyone = Group::getByName('Everyone'); $saved = $everyone->save(); assert('$saved'); // Not Coding Standard //Add contacts to help test that the rebuild is working correctly $contact = ContactTestHelper::createContactByNameForOwner('jason', Yii::app()->user->userModel); $contact->addPermissions(User::getByUsername('betty'), Permission::READ); $contact->addPermissions(Group::getByName('Support Staff'), Permission::READ); $saved = $contact->save(); assert('$saved'); // Not Coding Standard ReadPermissionsOptimizationUtil::rebuild(); assert('self::getAccountMungeRowCount() == 0'); // Not Coding Standard }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); // we are using some hardcoded Ids, we need fresh tables so these Ids are what we expect, rebuild: ForgetAllCacheUtil::forgetAllCaches(); ZurmoRedBean::$writer->wipeAll(); InstallUtil::autoBuildDatabase(new MessageLogger(), true); // This is setting up users and groups to match Jason's // powerpoint workings out of how the munge should look // after each operation. Things are set up in the order // that will give them the right ids to have munge ids // that match the document. The names are adjusted // to conform to the minimum lengths and casing in // the models. This the basic set up that is almost // right for many of the tests, and each test does // whatever it needs to to make the exactly what it // needs AND puts it back how it found it. $u1 = new User(); $u1->username = '******'; $u1->lastName = 'U1'; $saved = $u1->save(); assert('$saved'); // Not Coding Standard assert('$u1->id == 1'); // Not Coding Standard $u2 = new User(); $u2->username = '******'; $u2->lastName = 'U2'; $saved = $u2->save(); assert('$saved'); // Not Coding Standard assert('$u2->id == 2'); // Not Coding Standard $u3 = new User(); $u3->username = '******'; $u3->lastName = 'U3'; $saved = $u3->save(); assert('$saved'); // Not Coding Standard assert('$u3->id == 3'); // Not Coding Standard $u4 = new User(); $u4->username = '******'; $u4->lastName = 'U4'; $saved = $u4->save(); assert('$saved'); // Not Coding Standard assert('$u4->id == 4'); // Not Coding Standard $u5 = new User(); $u5->username = '******'; $u5->lastName = 'U5'; $saved = $u5->save(); assert('$saved'); // Not Coding Standard assert('$u5->id == 5'); // Not Coding Standard $u6 = new User(); $u6->username = '******'; $u6->lastName = 'U6'; $saved = $u6->save(); assert('$saved'); // Not Coding Standard assert('$u6->id == 6'); // Not Coding Standard $u99 = new User(); // A user with no roles $u99->username = '******'; // that can create accounts $u99->lastName = 'U99'; // without having any $saved = $u99->save(); // effect on the munge. assert('$saved'); // Not Coding Standard $g1 = new Group(); $g1->name = 'G1.'; $saved = $g1->save(); assert('$saved'); // Not Coding Standard assert('$g1->id == 1'); // Not Coding Standard $g2 = new Group(); $g2->name = 'G2.'; $saved = $g2->save(); assert('$saved'); // Not Coding Standard assert('$g2->id == 2'); // Not Coding Standard $g3 = new Group(); $g3->name = 'G3.'; $saved = $g3->save(); assert('$saved'); // Not Coding Standard assert('$g3->id == 3'); // Not Coding Standard $r1 = new Role(); $r1->name = 'R1.'; $saved = $r1->save(); assert('$saved'); // Not Coding Standard assert('$r1->id == 1'); // Not Coding Standard $r2 = new Role(); $r2->name = 'R2.'; $saved = $r2->save(); assert('$saved'); // Not Coding Standard assert('$r2->id == 2'); // Not Coding Standard $r3 = new Role(); $r3->name = 'R3.'; $saved = $r3->save(); assert('$saved'); // Not Coding Standard assert('$r3->id == 3'); // Not Coding Standard $r4 = new Role(); $r4->name = 'R4.'; $saved = $r4->save(); assert('$saved'); // Not Coding Standard assert('$r4->id == 4'); // Not Coding Standard $r5 = new Role(); $r5->name = 'R5.'; $saved = $r5->save(); assert('$saved'); // Not Coding Standard assert('$r5->id == 5'); // Not Coding Standard $r6 = new Role(); $r6->name = 'R6.'; $saved = $r6->save(); assert('$saved'); // Not Coding Standard assert('$r6->id == 6'); // Not Coding Standard $r3->roles->add($r2); $r2->roles->add($r1); $r6->roles->add($r5); $r5->roles->add($r4); $u1->role = $r1; $u2->role = $r4; $u3->role = $r4; $u4->role = $r4; $saved = $r3->save(); assert('$saved'); // Not Coding Standard $saved = $r2->save(); assert('$saved'); // Not Coding Standard $saved = $r6->save(); assert('$saved'); // Not Coding Standard $saved = $r5->save(); assert('$saved'); // Not Coding Standard $saved = $u1->save(); assert('$saved'); // Not Coding Standard $saved = $u2->save(); assert('$saved'); // Not Coding Standard $saved = $u3->save(); assert('$saved'); // Not Coding Standard $saved = $u4->save(); assert('$saved'); // Not Coding Standard //Add contacts to help test that the rebuild is working correctly $contact = ContactTestHelper::createContactByNameForOwner('jason', Yii::app()->user->userModel); $contact->addPermissions($u2, Permission::READ); $contact->addPermissions($g2, Permission::READ); $saved = $contact->save(); assert('$saved'); // Not Coding Standard ReadPermissionsOptimizationUtil::rebuild(); assert('self::getAccountMungeRowCount() == 0'); // Not Coding Standard RedBeanModel::forgetAll(); self::assertEverythingHasBeenSetBackToHowItStarted(); }