public function testActionCreate() { $options = []; $arguments = ['userName' => 'newAdmin']; $params = $options; foreach ($arguments as $key => $value) { $params[] = $value; } $this->specify('Promote non-existent user', function () use($params) { ob_start(); \Yii::$app->runAction('admin/create', $params); $output = ob_get_flush(); expect('Output should indicate that the user does not exist.', $output)->contains('not found'); }); $this->specify('Promote user already being an admin', function () use($params) { $admin = new UserEntity(); $admin->setName('newAdmin'); $this->em->persist($admin); $this->em->flush(); $authMan = \Yii::$app->getAuthManager(); /* @var $authMan \yii\rbac\ManagerInterface */ $adminRole = $authMan->getRole(\common\objects\RbacRole::ADMIN); $authMan->assign($adminRole, $admin->getId()); ob_start(); \Yii::$app->runAction('admin/create', $params); $output = ob_get_flush(); expect('Output should indicate that the user already is an admin.', $output)->contains('already is an admin'); }); $this->specify('Promote user', function () use($params) { $authMan = \Yii::$app->getAuthManager(); /* @var $authMan \yii\rbac\ManagerInterface */ $authMan->removeAllAssignments(); ob_start(); \Yii::$app->runAction('admin/create', $params); $output = ob_get_flush(); expect('Output should be empty.', $output)->isEmpty(); }); }
public function testFindForNewPlayer() { $this->specify('CelestialBodyRepository should be able to find a Celestial Body for a new player', function () { $celestialBody = $this->repo->findForNewPlayer(); expect('celestial body should be found', $celestialBody instanceof CelestialBodyEntity)->equals(true); expect('the celestial body should not have an owner', $celestialBody->hasOutpost())->equals(false); expect('the celestial body should not be in a chaos galaxy', $celestialBody->getSystem()->getGalaxy()->getNumber() % 4)->notEquals(0); expect('the celestial body should not be in a system causing effects', $celestialBody->getSystem()->hasModifier())->false(); }); // Specify clones our properties, this makes "$this->freeCelestialBody" a // new object. Since doctrine uses OIDs to identify objects, the cloning // causes the cloned object to be identified as "not managed". // --> Deactivate cloning! /* @var $configBuilder \Codeception\Specify\ConfigBuilder */ $configBuilder = $this->specifyConfig(); $configBuilder->ignore('celestialBodyForNewPlayer'); $this->specify('CelestialBodyRepository should not be able to find a Celestial Body for a new player if there are no more', function () { $user = new UserEntity(); $user->setName('Someone else'); $this->em->persist($user); // after this, there are no more free celestial bodies left. $outpostEntity = new OutpostEntity(); $outpostEntity->setCelestialBody($this->celestialBodyForNewPlayer); $outpostEntity->setName("Another outpost"); $outpostEntity->setOwner($user); $this->em->persist($outpostEntity); $this->em->flush(); // Since there's no more free celestial body, we expect this method to throw an exception. $this->repo->findForNewPlayer(); }, ['throws' => 'Doctrine\\ORM\\NoResultException']); }
/** * @inheritdoc */ public function getId() { return $this->entity->getId(); }