public static function createNotificationByContentAndTypeForOwner($content, $owner, $type = 'Simple') { //And Billy can create a notification for super $notification = new Notification(); $notification->type = $type; $notification->owner = $owner; $saved = $notification->save(); assert('$saved'); //Same with a message. $message = new NotificationMessage(); $message->textContent = 'text' . $content; $message->htmlContent = 'html' . $content; $saved = $message->save(); assert('$saved'); }
/** * @depends testCreateActionForRowsAndColumns */ public function testExportAction() { $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); $savedReports = SavedReport::getAll(); $this->assertEquals(2, count($savedReports)); $this->setGetArray(array('id' => $savedReports[0]->id)); //Test where there is no data to export $this->runControllerWithRedirectExceptionAndGetContent('reports/default/export'); $this->assertContains('There is no data to export.', Yii::app()->user->getFlash('notification')); $reportModelTestItem = new ReportModelTestItem(); $reportModelTestItem->string = 'string1'; $reportModelTestItem->lastName = 'xLast1'; $this->assertTrue($reportModelTestItem->save()); $reportModelTestItem = new ReportModelTestItem(); $reportModelTestItem->string = 'string2'; $reportModelTestItem->lastName = 'xLast2'; $this->assertTrue($reportModelTestItem->save()); $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/export'); $this->assertEquals('Testing download.', $content); ExportModule::$asynchronousThreshold = 1; $this->runControllerWithRedirectExceptionAndGetUrl('reports/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('reports', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); }
/** * Walkthrough test for synchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); $products = Product::getAll(); if (count($products)) { foreach ($products as $product) { $product->delete(); } } $products = array(); for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) { $products[] = ProductTestHelper::createProductByNameForOwner('superProduct' . $i, $super); } $this->setGetArray(array('Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('products', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = Notification::getCount(); $notificationMessagesBeforeCount = NotificationMessage::getCount(); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($products as $product) { $selectedIds .= $product->id . ","; // Not Coding Standard } $this->setGetArray(array('ProductsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'quantity' => ''), 'multiselect_ProductsSearchForm_anyMixedAttributesScope' => 'All', 'Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}")); $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('products', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount()); $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount()); }
/** * @depends testNonAdminCanCreateNotificationsAndMessages */ public function testRelationsBetweenNotificationAndNotificationMessage() { $super = User::getByUsername('super'); $billy = User::getByUsername('billy'); Yii::app()->user->userModel = $super; //Make sure the relations between Notification and NotificationMessage is working. $message = new NotificationMessage(); $message->textContent = 'text content2'; $message->htmlContent = 'html content2'; $this->assertTrue($message->save()); $notification = new Notification(); $notification->type = 'SimpleYTest'; $notification->owner = $billy; $notification->notificationMessage = $message; $this->assertTrue($notification->save()); //And Billy can create a notification for super $notification = new Notification(); $notification->type = 'SimpleZTest'; $notification->owner = $super; $notification->notificationMessage = $message; $this->assertTrue($notification->save()); //At this point the message should have 2 notifications associated with it $messageId = $message->id; $message->forget(); $mesage = NotificationMessage::getById($messageId); $this->assertEquals(2, $message->notifications->count()); $this->assertTrue($message->notifications[0]->type == 'SimpleYTest' || $message->notifications[0]->type == 'SimpleZTest'); $this->assertTrue($message->notifications[1]->type == 'SimpleYTest' || $message->notifications[1]->type == 'SimpleZTest'); /** - Add back in if it is possible to get the NotificationMessages to Notifications as RedBeanModel::OWNED * //Currently it is not working and cause $this->assertEquals(2, $message->notifications->count()); * to return 0. //When removing a notificationMessage with notifications, the notifications should be //removed too. $this->assertEquals(8, count(Notification::getAll())); $message->delete(); $this->assertEquals(3, count(Notification::getAll())); **/ }
/** * @depends testRelationsBetweenNotificationAndNotificationMessage */ public function testDeleteByTypeAndUser() { Yii::app()->user->userModel = User::getByUsername('super'); $joe = UserTestHelper::createBasicUser('joe'); $sally = UserTestHelper::createBasicUser('sally'); //Make sure the relations between Notification and NotificationMessage is working. $message = new NotificationMessage(); $message->textContent = 'text content3'; $message->htmlContent = 'html content3'; $this->assertTrue($message->save()); $notification1 = new Notification(); $notification1->type = 'SimpleDTest'; $notification1->owner = $joe; $notification1->notificationMessage = $message; $this->assertTrue($notification1->save()); //And Billy can create a notification for super $notification2 = new Notification(); $notification2->type = 'SimpleDTest'; $notification2->owner = $sally; $notification2->notificationMessage = $message; $this->assertTrue($notification2->save()); $this->assertEquals(2, $message->notifications->count()); $messageId = $message->id; $notification1Id = $notification1->id; $notification2Id = $notification2->id; $message->forget(); $notification1->forget(); $notification2->forget(); Notification::deleteByTypeAndUser('SimpleDTest', $joe); // Notification message should exist, because there is still notification point to it $message = NotificationMessage::getById($messageId); $this->assertTrue($message instanceof NotificationMessage); $notification2 = Notification::getById($notification2Id); $this->assertTrue($notification2 instanceof Notification); $notifications = Notification::getByNotificationMessageId($messageId); $this->assertEquals(1, count($notifications)); $this->assertEquals($notification2Id, $notifications[0]->id); try { Notification::getById($notification1Id); $this->fail(); } catch (NotFoundException $e) { } $message->forget(); $notification2->forget(); // Now delete second notification, this time notification message should be deleted too Notification::deleteByTypeAndUser('SimpleDTest', $sally); try { NotificationMessage::getById($messageId); $this->fail(); } catch (NotFoundException $e) { } try { Notification::getById($notification2Id); $this->fail(); } catch (NotFoundException $e) { } }
public function actionRenderMessageHtmlContent($id) { $notificationMessage = NotificationMessage::getById(intval($id)); echo Yii::app()->format->raw($notificationMessage->htmlContent); }
/** * Construct a new notification message * * @param string $title * @param string $content * @param string $class (Optional) Defaults to NotificationMessage::MESSAGE * * @return void **/ public function __construct($title, $content, $class = self::INFO) { $this->title = NotificationMessage::styleAlertLinks($title); $this->content = NotificationMessage::styleAlertLinks($content); $this->class = $class; }