public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; AllPermissionsOptimizationUtil::rebuild(); //create everyone group $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $everyoneGroup->save(); //Create test users $steven = UserTestHelper::createBasicUser('steven'); $steven->primaryEmail->emailAddress = '*****@*****.**'; //Steven has turned off notifications UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications'); $sally = UserTestHelper::createBasicUser('sally'); $sally->primaryEmail->emailAddress = '*****@*****.**'; $mary = UserTestHelper::createBasicUser('mary'); $mary->primaryEmail->emailAddress = '*****@*****.**'; //give 3 users access, create, delete for mission rights. $steven->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $steven->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $steven->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $steven->save(); if (!$saved) { throw new NotSupportedException(); } $sally->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $sally->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $sally->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $sally->save(); if (!$saved) { throw new NotSupportedException(); } $mary->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS); $mary->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS); $mary->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS); $saved = $mary->save(); if (!$saved) { throw new NotSupportedException(); } }
public function testsSendNotificationOnNewComment() { $super = User::getByUsername('super'); $steven = User::getByUsername('steven'); $jack = User::getByUsername('jack'); $conversation = new Conversation(); $conversation->owner = Yii::app()->user->userModel; $conversation->subject = 'My test subject2'; $conversation->description = 'My test description2'; $this->assertTrue($conversation->save()); $comment = new Comment(); $comment->description = 'This is the 1st test comment'; //Confirm no email notifications are sitting in the queue $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //No message was sent because Steven and Jack don't have primary email address CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack)); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $super->primaryEmail->emailAddress = '*****@*****.**'; $steven->primaryEmail->emailAddress = '*****@*****.**'; $jack->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($super->save()); $this->assertTrue($steven->save()); $this->assertTrue($jack->save()); //One email message was sent because to Steven and Jack CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack)); $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[0]; $this->assertEquals(2, count($emailMessage->recipients)); //One email message was sent to Super but not to Steven UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications'); CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $jack, array($steven, $super)); $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[1]; $this->assertEquals(1, count($emailMessage->recipients)); }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("Group")'); assert('$demoDataHelper->isSetRange("Role")'); $super = User::getByUsername('super'); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Super.test'); $super->primaryEmail = $email; $saved = $super->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($super, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($super); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $user = new User(); $this->populateModel($user); $user->username = '******'; $user->title->value = 'Sir'; $user->firstName = 'Jason'; $user->lastName = 'Blue'; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress('Jason.Blue'); $user->primaryEmail = $email; $user->setPassword($user->username); $saved = $user->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($user, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $userStartId = $user->id; $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId']); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); foreach (array('jim' => 'Mr.', 'john' => 'Mr.', 'sally' => 'Dr.', 'mary' => 'Mrs.', 'katie' => 'Ms.', 'jill' => 'Ms.', 'sam' => 'Mr.') as $username => $title) { $user = new User(); $this->populateModel($user); $user->username = $username; $user->setPassword($user->username); $user->title->value = $title; $user->firstName = ucfirst($username); $user->lastName = 'Smith'; $email = new Email(); $email->emailAddress = static::resolveDemoEmailAddress($user->firstName); $user->primaryEmail = $email; $user->lastLoginDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $saved = $user->save(); assert('$saved'); UserConfigurationFormAdapter::setValue($user, true, 'turnOffEmailNotifications'); $userAvatarForm = new UserAvatarForm($user); $userAvatarForm->avatarType = User::AVATAR_TYPE_PRIMARY_EMAIL; $saved = $userAvatarForm->save(); assert('$saved'); $roleIdRange = $demoDataHelper->getRangeByModelName('Role'); $role = Role::getById($roleIdRange['startId'] + 1); assert('$role instanceof Role'); $role->users->add($user); $saved = $role->save(); assert('$saved'); } $demoDataHelper->setRangeByModelName('User', $userStartId, $user->id); }
public function testAfterSaveForImportModel() { $testUser = UserTestHelper::createBasicUserWithEmailAddress('jimmy'); UserConfigurationFormAdapter::setValue($testUser, false, 'turnOffEmailNotifications'); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertCount(0, EmailMessage::getAll()); $task = new Task(); $task->name = 'MyTaskWithoutImport'; $task->owner = $testUser; $task->requestedByUser = Yii::app()->user->userModel; $this->assertTrue($task->save()); $this->assertEquals(2, count($task->notificationSubscribers)); $this->assertCount(1, EmailMessage::getAll()); //With import $task = new Task(); $task->setScenario('importModel'); $task->name = 'MyTaskWithImport'; $task->owner = $testUser; $task->requestedByUser = Yii::app()->user->userModel; $this->assertTrue($task->save()); $this->assertEquals(2, count($task->notificationSubscribers)); $this->assertCount(1, EmailMessage::getAll()); }
public function testGlobalDefaultsLoadedOnCreateInAbsenceOfUserDefaultPermissions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); UserConfigurationFormAdapter::setValue($super, null, 'defaultPermissionSetting', false); UserConfigurationFormAdapter::setDefaultPermissionGroupSetting($super, null, null); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); // test that 'everyone' radio button is checked $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_2" value="1" ' . 'checked="checked" type="radio" name="Account\\[explicitReadWriteModelPermissions\\]\\[type\\]" />%', $content), 1); // test that no downdown item is selected $this->assertEquals(preg_match('%<option value="(\\d+)" selected="selected">(.*)</option>%', $content), 0); // Not Coding Standard }
/** * @depends testClosingConversations */ public function testSendEmailInNewComment() { if (!SECURITY_OPTIMIZED) { return; } $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $conversations = Conversation::getAll(); $this->assertEquals(2, count($conversations)); $this->assertEquals(0, $conversations[0]->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $initalQueued = 0; $conversation = $conversations[0]; $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $steven; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $sally; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $mary; $conversation->conversationParticipants->add($conversationParticipant); UserConfigurationFormAdapter::setValue($mary, true, 'turnOffEmailNotifications'); //Save a new comment $this->setGetArray(array('relatedModelId' => $conversation->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $conversation->comments->count()); $this->assertEquals($initalQueued + 1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$initalQueued]; $this->assertEquals(2, count($emailMessage->recipients)); $this->assertContains('conversation', $emailMessage->subject); $this->assertContains(strval($conversation), $emailMessage->subject); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent); }