public function testFixupImportedContactName()
 {
     $admin = Yii::app()->settings;
     $fixupImportedContactName = TestingAuxLib::setPublic('ImportExportBehavior', 'fixupImportedContactName', true);
     // Using Explicit 'First Last' format
     $admin->contactNameFormat = 'firstName lastName';
     $this->assertUpdates($admin, array('contactNameFormat'));
     $contact = new Contacts();
     $contact->name = 'FirstName LastName';
     $fixupImportedContactName($contact);
     $this->assertEquals('FirstName', $contact->firstName);
     $this->assertEquals('LastName', $contact->lastName);
     $contact = new Contacts();
     $contact->firstName = 'FirstName';
     $contact->lastName = 'LastName';
     $fixupImportedContactName($contact);
     $this->assertEquals('FirstName LastName', $contact->name);
     // Using 'Last, First' format
     $admin->contactNameFormat = 'lastName, firstName';
     $this->assertUpdates($admin, array('contactNameFormat'));
     $contact = new Contacts();
     $contact->name = 'LastName, FirstName';
     $fixupImportedContactName($contact);
     $this->assertEquals('FirstName', $contact->firstName);
     $this->assertEquals('LastName', $contact->lastName);
     $contact = new Contacts();
     $contact->firstName = 'FirstName';
     $contact->lastName = 'LastName';
     $fixupImportedContactName($contact);
     $this->assertEquals('LastName, FirstName', $contact->name);
     // Reset format to default empty value
     $admin->contactNameFormat = null;
     $this->assertUpdates($admin, array('contactNameFormat'));
 }
Example #2
0
 /**
  * Attempt to login with curlLogin and ensure that a page which requires login can be viewed 
  */
 public function testCurlLogin()
 {
     // ensure that page which should require login can't be viewed before logging in
     $sessionId = uniqid();
     $cookies = "PHPSESSID={$sessionId}; path=/;";
     $curlHandle = curl_init(TEST_BASE_URL . 'profile/settings');
     curl_setopt($curlHandle, CURLOPT_HTTPGET, 1);
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlHandle, CURLOPT_COOKIE, $cookies);
     ob_start();
     $result = curl_exec($curlHandle);
     ob_clean();
     $this->assertFalse((bool) preg_match('/Change Personal Settings/', $result));
     // log in and then request the same page
     $sessionId = TestingAuxLib::curlLogin('testuser', 'password');
     $cookies = "PHPSESSID={$sessionId};";
     $curlHandle = curl_init(TEST_BASE_URL . 'profile/settings');
     curl_setopt($curlHandle, CURLOPT_HTTPGET, 1);
     curl_setopt($curlHandle, CURLOPT_HEADER, 1);
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlHandle, CURLOPT_COOKIE, $cookies);
     ob_start();
     $result = curl_exec($curlHandle);
     ob_clean();
     //print_r ("document.cookie = 'PHPSESSID=$sessionId; path=/;';\n");
     //print_r ($result);
     $this->assertTrue((bool) preg_match('/Change Personal Settings/', $result));
 }
Example #3
0
 public function testCaching()
 {
     $timer = new TimerUtil();
     TestingAuxLib::suLogin('testuser');
     Yii::app()->authCache->clear();
     $this->assertEquals(0, count(Yii::app()->authCache->loadAuthCache(2)));
     $contact = $this->contacts('testUser');
     $expectedCacheValue = array('ContactsUpdateAccess' => array());
     // add cache entry
     Yii::app()->authManager->checkAccess('ContactsUpdateAccess', 2, array('X2Model' => $contact));
     $expectedCacheValue['ContactsUpdateAccess'][json_encode(array('modelType' => get_class($contact), 'assignedTo' => $contact->assignedTo))] = '1';
     $this->assertEquals($expectedCacheValue, Yii::app()->authCache->loadAuthCache(2));
     // ensure cache hit
     Yii::app()->authManager->checkAccess('ContactsUpdateAccess', 2, array('X2Model' => $contact));
     $this->assertEquals($expectedCacheValue, Yii::app()->authCache->loadAuthCache(2));
     // no cache entries for non-scalar params
     Yii::app()->authManager->checkAccess('ContactsUpdateAccess', 2, array('model' => $contact));
     $this->assertEquals($expectedCacheValue, Yii::app()->authCache->loadAuthCache(2));
     // add cache entries for scalar params
     $timer->start();
     Yii::app()->authManager->checkAccess('ContactsUpdateAccess', 2, array('scalar' => ''));
     $expectedCacheValue['ContactsUpdateAccess'][json_encode(array('scalar' => ''))] = '1';
     $this->assertEquals($expectedCacheValue, Yii::app()->authCache->loadAuthCache(2));
     $timeA = $timer->stop()->getTime();
     // ensure cache hit
     $timer->start();
     Yii::app()->authManager->checkAccess('ContactsUpdateAccess', 2, array('scalar' => ''));
     $this->assertEquals($expectedCacheValue, Yii::app()->authCache->loadAuthCache(2));
     $timeB = $timer->stop()->getTime();
     $this->assertLessThan($timeA, $timeB);
 }
Example #4
0
 /**
  * Test new list + add to list super mass actions
  */
 public function testSuperExecute()
 {
     X2List::model()->deleteAllByAttributes(array('name' => 'test'));
     $_SESSION = array();
     $newList = new NewListFromSelection();
     $addToList = new MassAddToList();
     TestingAuxLib::suLogin('admin');
     Yii::app()->user;
     // initializes $_SESSION superglobal
     Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null));
     $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n                SELECT id\n                FROM x2_contacts\n                ORDER BY lastUpdated DESC, id DESC\n            ")->queryColumn());
     // perform super mass actions in batches, ensuring that after each batch, the id queue
     // in the session matches the remaining records to be updated. Call the new list from
     // selection mass action on the first batch and the mass add to list on all subsequent
     // batches to simulate behavior of grid view
     $_POST['modelType'] = 'Contacts';
     $_POST['listName'] = 'test';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['SERVER_NAME'] = 'localhost';
     $updated = 0;
     $uid = null;
     $listId = null;
     while (true) {
         ob_start();
         if (!isset($listId)) {
             $newList->superExecute($uid, 24, $idChecksum);
         } else {
             $_POST['listId'] = $listId;
             $addToList->superExecute($uid, 24, $idChecksum);
         }
         $retVal = CJSON::decode(ob_get_contents());
         ob_clean();
         $this->assertTrue(!isset($retVal['errorCode']));
         $uid = $retVal['uid'];
         if (isset($retVal['listId'])) {
             $listId = $retVal['listId'];
         }
         // get ids of contacts not in new list
         $remainingIds = Yii::app()->db->createCommand('
             SELECT t.id
             FROM x2_contacts AS t
             WHERE t.id NOT IN (
                 SELECT contactId 
                 FROM x2_list_items AS t2
                 JOIN x2_lists AS t3 ON t3.id = t2.listId
                 WHERE t.id = t2.contactId AND t3.name="test"
             )
         ')->queryColumn();
         if (isset($retVal['complete'])) {
             $this->assertEquals(0, count($remainingIds));
             $this->assertTrue(!isset($_SESSION[MassAction::SESSION_KEY_PREFIX . $uid]));
             break;
         } else {
             $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid];
             sort($storedIds);
             $this->assertEquals($remainingIds, $storedIds);
         }
     }
 }
Example #5
0
 public function testFindMissingPermissions()
 {
     // satisfy CAssetManager so it doesn't complain when we call findMissingPermissions
     $path = TestingAuxLib::printExec('cd ../../ && pwd');
     Yii::app()->assetManager->setBasePath($path[0] . '/');
     $findMissingPermissions = TestingAuxLib::setPublic('AdminController', 'findMissingPermissions', true);
     $this->assertEquals(array(), $findMissingPermissions());
 }
 /**
  * Ensure that list of viewable calendars correctly reflects calendar permissions records
  */
 public function testGetViewableUserCalendarNames()
 {
     TestingAuxLib::loadX2NonWebUser();
     TestingAuxLib::suLogin('admin');
     $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames());
     $this->assertEquals(array_merge(array('Anyone'), Yii::app()->db->createCommand("\n                SELECT username\n                FROM x2_users\n            ")->queryColumn()), ArrayUtil::sort($viewable));
     $user = $this->users('testUser');
     TestingAuxLib::suLogin('testuser');
     $viewable = array_keys(X2CalendarPermissions::getViewableUserCalendarNames());
     $grantedUsers = array_unique(array_merge(array('Anyone', 'testuser'), Yii::app()->db->createCommand("\n                /**\n                 * get names of users who have granted view permission to testuser and names of\n                 * users who have not set up calendar permissions\n                 */\n                SELECT distinct(username)\n                FROM x2_users as t, x2_calendar_permissions\n                WHERE other_user_id=:userId OR t.id NOT in (\n                    SELECT distinct(user_id)\n                    FROM x2_calendar_permissions\n                )\n            ")->queryColumn(array(':userId' => $user->id))));
     $this->assertEquals(ArrayUtil::sort($grantedUsers), ArrayUtil::sort($viewable));
     TestingAuxLib::restoreX2WebUser();
 }
 /**
  * Super mass update firstName and lastName for fixture records 
  */
 public function testSuperExecute()
 {
     X2List::model()->deleteAllByAttributes(array('name' => 'test'));
     $_SESSION = array();
     $newList = new NewListFromSelection();
     TestingAuxLib::suLogin('admin');
     Yii::app()->user;
     // initializes $_SESSION superglobal
     Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null));
     // perform super mass actions in batches, ensuring that after each batch, the id queue
     // in the session matches the remaining records to be updated
     $_POST['modelType'] = 'Contacts';
     $_POST['listName'] = 'test';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['SERVER_NAME'] = 'localhost';
     $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n                SELECT id\n                FROM x2_contacts\n                ORDER BY lastUpdated DESC, id DESC\n            ")->queryColumn());
     $updated = 0;
     $uid = null;
     while (true) {
         $this->obStart();
         $newList->superExecute($uid, 24, $idChecksum);
         $retVal = CJSON::decode(ob_get_contents());
         $this->obEndClean();
         $this->assertTrue(!isset($retVal['errorCode']));
         $uid = $retVal['uid'];
         // get ids of contacts not in new list
         $remainingIds = Yii::app()->db->createCommand('
             SELECT t.id
             FROM x2_contacts AS t
             WHERE t.id NOT IN (
                 SELECT contactId 
                 FROM x2_list_items AS t2
                 JOIN x2_lists AS t3 ON t3.id = t2.listId
                 WHERE t.id = t2.contactId AND t3.name="test"
             )
         ')->queryColumn();
         $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid];
         sort($storedIds);
         $this->assertEquals($remainingIds, $storedIds);
         // new list from selection mass action should only ever get run on the first batch.
         // subsequent batches get added to the list (mass action swapping is handled
         // client-side)
         break;
     }
 }
 public function testGetVisibleRelatedX2Models()
 {
     TestingAuxLib::loadControllerMock();
     TestingAuxLib::suLogin('testUser2');
     $contact = $this->contact('testAnyone');
     $otherContact = $this->contact('testUser');
     $this->assertFalse($contact->relationships->hasRelationship($otherContact));
     $contact->relationships->createRelationship($otherContact);
     $this->assertTrue($contact->relationships->hasRelationship($otherContact));
     $visibleRelatedModels = $contact->relationships->getVisibleRelatedX2Models(true);
     $this->assertEquals(1, count($visibleRelatedModels));
     $this->assertInstanceOf(get_class($otherContact), $visibleRelatedModels[0]);
     $this->assertEquals($otherContact->id, $visibleRelatedModels[0]->id);
     $otherContact->visibility = 0;
     $otherContact->assignedTo = 'test';
     $this->assertSaves($otherContact);
     Yii::app()->params->isAdmin = false;
     $visibleRelatedModels = $contact->relationships->getVisibleRelatedX2Models();
     $this->assertEquals(1, count($visibleRelatedModels));
     $this->assertInstanceOf(get_class($otherContact), $visibleRelatedModels[0]);
     $this->assertEquals($otherContact->id, $visibleRelatedModels[0]->id);
     $this->assertEmpty($contact->relationships->getVisibleRelatedX2Models(true));
 }
 public function testCustomRoundRobin()
 {
     Yii::app()->settings->leadDistribution = 'customRoundRobin';
     //$this->assertSaves (Yii::app()->settings);
     TestingAuxLib::setUpSessions($this->sessions);
     $_POST['Contacts'] = array('firstName' => 'contact1', 'lastName' => 'contact1');
     $leadRouting = new LeadRoutingBehavior();
     $username = $leadRouting->customRoundRobin();
     if (VERBOSE_MODE) {
         print "Getting assignee: username = {$username}\n";
     }
     $this->assertTrue($username === 'testUser1');
     $_POST['Contacts'] = array('firstName' => 'contact2', 'lastName' => 'contact2');
     $username = $leadRouting->customRoundRobin();
     if (VERBOSE_MODE) {
         print "Getting assignee: username = {$username}\n";
     }
     $this->assertTrue($username === 'testUser2');
     $_POST['Contacts'] = array('firstName' => 'contact3', 'lastName' => 'contact3');
     $username = $leadRouting->customRoundRobin();
     if (VERBOSE_MODE) {
         print "Getting assignee: username = {$username}\n";
     }
     $this->assertTrue($username === 'Anyone');
     $_POST['Contacts'] = array('firstName' => 'contact4', 'lastName' => 'contact4');
     $this->assertEquals('testUser1', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser2', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser3', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser4', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser1', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser2', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser3', $leadRouting->customRoundRobin());
     $this->assertEquals('testUser4', $leadRouting->customRoundRobin());
 }
Example #10
0
 /**
  * Load controller mock, as well as related mocks and $_SERVER values which might be needed 
  * in cases where a controller is needed.
  */
 public static function loadControllerMock($serverName = 'localhost', $scriptName = '/index-test.php')
 {
     self::$_oldController = Yii::app()->controller;
     self::$_oldServerVals = $_SERVER;
     $_SERVER['SCRIPT_FILENAME'] = realpath('../../index-test.php');
     $_SERVER['DOCUMENT_ROOT'] = realpath('../..');
     $_SERVER['SERVER_NAME'] = $serverName;
     $_SERVER['SCRIPT_NAME'] = $scriptName;
     $_SERVER['REQUEST_URI'] = '/index.php/controllerMock/actionMock';
     Yii::app()->controller = new ControllerMock('moduleMock', new ModuleMock('moduleMock', null));
     Yii::app()->controller->action = new ActionMock(Yii::app()->controller, 'actionMock');
     // clear the url property caches so they will get regenerated using the
     // properties of $_SERVER
     self::setPrivateProperty('CHttpRequest', '_scriptUrl', null, Yii::app()->request);
     self::setPrivateProperty('CUrlManager', '_baseUrl', null, Yii::app()->getUrlManager());
 }
Example #11
0
 public function testAddRemoveLayoutElements()
 {
     $profile = $this->profile('testProfile');
     $fn = TestingAuxLib::setPublic($profile, 'addRemoveLayoutElements');
     $defaultLayout = $profile->initLayout();
     // attempt to construct default layout from empty layout
     $profile->layout = json_encode(array());
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $this->assertEquals($defaultLayout, json_decode($profile->layout, true));
     // ensure that invalid hidden right widgets get removed
     $profile->layout = json_encode(array('hiddenRight' => array('InvalidRightWidget' => array('title' => 'Invalid Right Widget', 'minimize' => false))));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $this->assertEquals($defaultLayout, json_decode($profile->layout, true));
     // ensure that invalid left widgets get removed
     $profile->layout = json_encode(array('left' => array('Invalid' => array('title' => 'Invalid', 'minimize' => false))));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $this->assertEquals($defaultLayout, json_decode($profile->layout, true));
     // ensure that invalid right widgets get removed
     $profile->layout = json_encode(array('right' => array('Invalid' => array('title' => 'Invalid', 'minimize' => false))));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $this->assertEquals($defaultLayout, json_decode($profile->layout, true));
     // ensure that right widgets get retitled while preserving other settings
     $helpfulTipsConfig = $defaultLayout['right']['TimeZone'];
     $this->assertFalse($helpfulTipsConfig['minimize']);
     // make sure we're changing state
     $newHelpfulTipsConfig = array('title' => 'Not Clock', 'minimize' => true);
     $profile->layout = json_encode(array('right' => array('TimeZone' => $newHelpfulTipsConfig)));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $expected = $defaultLayout;
     $newHelpfulTipsConfig['title'] = $helpfulTipsConfig['title'];
     $expected['right']['TimeZone'] = $newHelpfulTipsConfig;
     $this->assertEquals($expected, json_decode($profile->layout, true));
     // ensure that hidden right widgets remain hidden
     $helpfulTipsConfig = $defaultLayout['right']['TimeZone'];
     $profile->layout = json_encode(array('hiddenRight' => array('TimeZone' => $helpfulTipsConfig)));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $expected = $defaultLayout;
     unset($expected['right']['TimeZone']);
     $expected['hiddenRight']['TimeZone'] = $helpfulTipsConfig;
     $this->assertEquals($expected, json_decode($profile->layout, true));
     // ensure that hidden right widgets get retitled while preserving other settings
     $helpfulTipsConfig = $defaultLayout['right']['TimeZone'];
     $this->assertFalse($helpfulTipsConfig['minimize']);
     // make sure we're changing state
     $newHelpfulTipsConfig = array('title' => 'Not Clock', 'minimize' => true);
     $profile->layout = json_encode(array('hiddenRight' => array('TimeZone' => $newHelpfulTipsConfig)));
     $profile->update('layout');
     $layout = json_decode($profile->layout, true);
     $this->assertNotEquals(json_decode($profile->layout), $defaultLayout);
     $fn('left', $layout, $defaultLayout);
     $profile->refresh();
     $layout = json_decode($profile->layout, true);
     $fn('right', $layout, $defaultLayout);
     $profile->refresh();
     $expected = $defaultLayout;
     $newHelpfulTipsConfig['title'] = $helpfulTipsConfig['title'];
     unset($expected['right']['TimeZone']);
     $expected['hiddenRight']['TimeZone'] = $newHelpfulTipsConfig;
     $this->assertEquals($expected, json_decode($profile->layout, true));
 }
Example #12
0
 public function testCompareAttribute()
 {
     $contact1 = $this->contact('testAnyone');
     $contact2 = $this->contact('testUser');
     $contact1->leadSource = 'Google';
     $this->assertSaves($contact1);
     $contact2->leadSource = 'Facebook';
     $this->assertSaves($contact2);
     $criteria = new CDbCriteria();
     $searchModel = new Contacts();
     $searchModel->leadSource = 'Google';
     $compareAttribute = TestingAuxLib::setPublic($searchModel, 'compareAttribute');
     $compareAttribute($criteria, $searchModel->getField('leadSource'));
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertModelArrayEquality(array($contact1), $contacts);
     $criteria = new CDbCriteria();
     $searchModel = new Contacts();
     $searchModel->leadSource = 'Facebook';
     $compareAttribute = TestingAuxLib::setPublic($searchModel, 'compareAttribute');
     $compareAttribute($criteria, $searchModel->getField('leadSource'));
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertModelArrayEquality(array($contact2), $contacts);
     $contact1->leadSource = CJSON::encode(array('Google', 'Facebook'));
     $this->assertSaves($contact1);
     $criteria = new CDbCriteria();
     $searchModel = new Contacts();
     $searchModel->leadSource = array('Google');
     $compareAttribute = TestingAuxLib::setPublic($searchModel, 'compareAttribute');
     $compareAttribute($criteria, $searchModel->getField('leadSource'));
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertModelArrayEquality(array($contact1), $contacts);
     $criteria = new CDbCriteria();
     $searchModel = new Contacts();
     $searchModel->leadSource = array('Facebook');
     $compareAttribute = TestingAuxLib::setPublic($searchModel, 'compareAttribute');
     $compareAttribute($criteria, $searchModel->getField('leadSource'));
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertModelArrayEquality(array($contact1, $contact2), $contacts);
 }
Example #13
0
 /**
  * Executes a specified flow, ensuring that flows won't get triggered recursively
  * @param object $flow An X2Flow model
  */
 public function executeFlow($flow, $params)
 {
     $X2Flow = new ReflectionClass('X2Flow');
     $_triggerDepth = $X2Flow->getProperty('_triggerDepth');
     $_triggerDepth->setAccessible(TRUE);
     $_triggerDepth->setValue(1);
     $fn = TestingAuxLib::setPublic('X2Flow', 'executeFlow');
     $returnVal = $fn($flow, $params);
     $_triggerDepth->setValue(0);
     return $returnVal;
 }
Example #14
0
 public function tearDown()
 {
     // try to replace mocks with original components in case mocks were set during test case
     TestingAuxLib::restoreX2WebUser();
     TestingAuxLib::restoreX2AuthManager();
     return parent::tearDown();
 }
Example #15
0
 /**
  * TODO: Remove hardcoded references to events in the fixture.
  */
 public function testCheckPermissions()
 {
     TestingAuxLib::loadX2NonWebUser();
     $event1 = $this->event(0);
     // Admin can do anything
     TestingAuxLib::suLogin('admin');
     $this->assertTrue($event1->checkPermissions('view', true));
     $this->assertTrue($event1->checkPermissions('edit', true));
     $this->assertTrue($event1->checkPermissions('delete', true));
     // Private and no shared group means testuser can't do anything
     TestingAuxLib::suLogin('testuser');
     $this->assertFalse($event1->checkPermissions('view', true));
     $this->assertFalse($event1->checkPermissions('edit', true));
     $this->assertFalse($event1->checkPermissions('delete', true));
     // Associated with testuser2, so they can view and delete but not edit
     TestingAuxLib::suLogin('testuser2');
     $this->assertTrue($event1->checkPermissions('view', true));
     $this->assertFalse($event1->checkPermissions('edit', true));
     $this->assertTrue($event1->checkPermissions('delete', true));
     // Created by testuser3, so they can do anything
     TestingAuxLib::suLogin('testuser3');
     $this->assertTrue($event1->checkPermissions('view', true));
     $this->assertTrue($event1->checkPermissions('edit', true));
     $this->assertTrue($event1->checkPermissions('delete', true));
     $event2 = $this->event(6);
     // Admin can do anything
     TestingAuxLib::suLogin('admin');
     $this->assertTrue($event2->checkPermissions('view', true));
     $this->assertTrue($event2->checkPermissions('edit', true));
     $this->assertTrue($event2->checkPermissions('delete', true));
     // Public posts are visible but not editable or deletable by regular users
     TestingAuxLib::suLogin('testuser');
     $this->assertTrue($event2->checkPermissions('view', true));
     $this->assertFalse($event2->checkPermissions('edit', true));
     $this->assertFalse($event2->checkPermissions('delete', true));
     // Public posts are visible but not editable or deletable by regular users
     TestingAuxLib::suLogin('testuser2');
     $this->assertTrue($event2->checkPermissions('view', true));
     $this->assertFalse($event2->checkPermissions('edit', true));
     $this->assertFalse($event2->checkPermissions('delete', true));
     $event3 = $this->event(7);
     // Admin can do anything
     TestingAuxLib::suLogin('admin');
     $this->assertTrue($event3->checkPermissions('view', true));
     $this->assertTrue($event3->checkPermissions('edit', true));
     $this->assertTrue($event3->checkPermissions('delete', true));
     // Non-social post is visible to user it's assigned to but they can't edit or delete
     TestingAuxLib::suLogin('testuser');
     $this->assertTrue($event3->checkPermissions('view', true));
     $this->assertFalse($event3->checkPermissions('edit', true));
     $this->assertFalse($event3->checkPermissions('delete', true));
     // Private, so testuser3 can't do anything
     TestingAuxLib::suLogin('testuser3');
     $this->assertFalse($event3->checkPermissions('view', true));
     $this->assertFalse($event3->checkPermissions('edit', true));
     $this->assertFalse($event3->checkPermissions('delete', true));
 }
Example #16
0
 public function testToBytes()
 {
     $fn = TestingAuxLib::setPublic('Media', 'toBytes');
     $testSizes = array('3PB' => 3 * pow(1024, 5), '1g' => 1024 * 1024 * 1024, '2m' => 2 * 1024 * 1024, '1MB' => 1024 * 1024, '1k' => 1024, 666 => 666);
     foreach ($testSizes as $readable => $bytes) {
         $this->assertEquals($bytes, $fn($readable));
     }
 }
Example #17
0
 public function testCaseInsensitiveCopyFix()
 {
     $outdir = implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, 'tests', 'data', 'output', 'testCaseInsensitivityCopyFix'));
     $testFile = $outdir . DIRECTORY_SEPARATOR . 'test.php';
     $newTestFile = $outdir . DIRECTORY_SEPARATOR . 'Test.php';
     FileUtil::rrmdir($outdir);
     $caseInsensitiveCopyFix = TestingAuxLib::setPublic('FileUtil', 'caseInsensitiveCopyFix', true);
     // ensure that nothing occurs if target doesn't exist
     $this->assertFalse($caseInsensitiveCopyFix($testFile, $testFile));
     system("mkdir {$outdir}");
     system("touch {$testFile}");
     $this->assertTrue(file_exists($testFile));
     // ensure that nothing occurs if filenames are identical
     $this->assertFalse($caseInsensitiveCopyFix($testFile, $testFile));
     // ensure that nothing occurs if filenames differ
     $this->assertFalse($caseInsensitiveCopyFix($testFile, $newTestFile));
     FileUtil::rrmdir($outdir);
     FileUtil::rrmdir($outdir);
 }
Example #18
0
 /**
  * Send an actual email using local credentials and then assert that the email was received
  * by using imap_search
  */
 public function testLiveEmail()
 {
     TestingAuxLib::setConstant('X2_DEBUG_EMAIL', 'false');
     $contact = $this->contacts('testAnyone');
     $liveDeliveryTestCreds = $this->credentials('liveDeliveryTest');
     $this->openX2('contacts/' . $contact->id);
     sleep(1);
     $this->click("dom=document.querySelector ('.page-title .email')");
     $subject = 'functional test email ' . time();
     $this->select("css=#InlineEmail_credId", 'value=' . $liveDeliveryTestCreds->id);
     $this->type("name=InlineEmail[subject]", $subject);
     $this->type("name=InlineEmail[to]", $liveDeliveryTestCreds->auth->email);
     $this->storeEval("window.\$('#email-message').val ('test')", 'placeholder');
     sleep(2);
     $this->click("dom=document.querySelector('#send-email-button')");
     sleep(2);
     $this->assertEmailSuccess();
     TestingAuxLib::assertEmailReceived($this, $liveDeliveryTestCreds, $subject, 3);
 }
Example #19
0
 /**
  * Attempts to ensure that isVisibleTo and getAccessCriteria check the same permissions
  */
 public function testPermissionsCheckEquivalence()
 {
     TestingAuxLib::loadX2NonWebUser();
     TestingAuxLib::suLogin('testuser2');
     $allEvents = Events::model()->findAll();
     $that = $this;
     $checkEquivalence = function ($events) use($allEvents, $that) {
         $ids = array_map(function ($event) {
             return $event->id;
         }, $events);
         $that->assertTrue(count($events) > 1);
         foreach ($events as $event) {
             $that->assertTrue($event->isVisibleTo(Yii::app()->params->profile->user));
         }
         $found = false;
         foreach ($allEvents as $event) {
             if (!in_array($event->id, $ids)) {
                 $found = true;
                 $that->assertFalse($event->isVisibleTo(Yii::app()->params->profile->user));
             }
         }
         $that->assertTrue($found);
     };
     Yii::app()->settings->historyPrivacy = null;
     $accessCriteria = Events::model()->getAccessCriteria();
     $events = Events::model()->findAll($accessCriteria);
     $checkEquivalence($events);
     Yii::app()->settings->historyPrivacy = 'group';
     $accessCriteria = Events::model()->getAccessCriteria();
     $events = Events::model()->findAll($accessCriteria);
     $checkEquivalence($events);
     Yii::app()->settings->historyPrivacy = 'user';
     $accessCriteria = Events::model()->getAccessCriteria();
     $events = Events::model()->findAll($accessCriteria);
     $checkEquivalence($events);
 }
Example #20
0
 public function tearDown()
 {
     // try to replace mocks with original components in case mocks were set during test case
     TestingAuxLib::restoreX2WebUser();
     TestingAuxLib::restoreX2AuthManager();
     TestingAuxLib::restoreController();
     self::$skipAllTests = false;
     self::$loadFixtures = X2_LOAD_FIXTURES;
     self::$loadFixturesForClassOnly = X2_LOAD_FIXTURES_FOR_CLASS_ONLY;
     if (isset($this->_oldSession)) {
         $_SESSION = $this->_oldSession;
     }
     if (X2_TEST_DEBUG_LEVEL > 0) {
         $timer = TestingAuxLib::getCaseTimer();
         TestingAuxLib::log("time elapsed for test case: {$timer->stop()->getTime()}");
     }
     return parent::tearDown();
 }
Example #21
0
 /**
  * Call render at least once for each field type  
  */
 public function testRender()
 {
     Yii::app()->cache->flush();
     TestingAuxLib::suLogin('admin');
     $contact = Contacts::model()->findByPk(12345);
     $fieldTypes = Fields::getFieldTypes();
     foreach ($fieldTypes as $type => $info) {
         $fieldsOfType = $contact->getFields(false, function ($field) use($type) {
             return strtolower($field->type) === strtolower($type);
         });
         VERBOSE_MODE && println('type=' . $type);
         $this->assertTrue(count($fieldsOfType) > 0);
         foreach ($fieldsOfType as $field) {
             $contact->formatter->renderAttribute($field->fieldName, true, true, true);
         }
     }
 }
Example #22
0
 public function testUpdateWithNotifications()
 {
     TestingAuxLib::loadX2NonWebUser();
     TestingAuxLib::suLogin('admin');
     // assigned to testuser
     $action = $this->actions('action1');
     $reminders = $action->getReminders(true);
     foreach ($reminders as $reminder) {
         $this->assertTrue($reminder->delete());
     }
     $this->assertEquals(0, count($action->getReminders(true)));
     // ensure that we can create a reminder
     $action->reminder = true;
     $action->notificationUsers = 'assigned';
     $action->notificationTime = 1234;
     $this->assertSaves($action);
     $this->assertEquals(1, count($action->getReminders(true)));
     $reminders = $action->getReminders(true);
     $assignees = array_map(function ($reminder) {
         return $reminder->user;
     }, $reminders);
     $this->assertEquals(array('testuser'), $assignees);
     // now ensure that we can create another reminder and that the old reminder was deleted
     TestingAuxLib::suLogin('testuser');
     $action->reminder = true;
     $action->notificationUsers = 'assigned';
     $action->notificationTime = 1234;
     $this->assertSaves($action);
     $this->assertEquals(1, count($action->getReminders(true)));
     $reminders = $action->getReminders(true);
     $assignees = array_map(function ($reminder) {
         return $reminder->user;
     }, $reminders);
     $this->assertEquals(array('testuser'), $assignees);
 }
Example #23
0
 public function testPropertySetters()
 {
     TestingAuxLib::loadControllerMock();
     $profile = $this->profiles('adminProfile');
     $widgetLayout = $profile->profileWidgetLayout;
     $widgetClass = 'ContactsGridViewProfileWidget';
     $widgetProps = $widgetLayout[$widgetClass];
     $newWidgetProps = $widgetProps;
     $newWidgetProps['label'] = 'newLabel';
     $widgetClass::setJSONProperties($profile, $newWidgetProps, 'profile', '');
     $profile->refresh();
     $widgetLayout = $profile->profileWidgetLayout;
     $widgetProps = $widgetLayout[$widgetClass];
     $this->assertEquals($newWidgetProps, $widgetProps);
     $widgetClass::setJSONProperty($profile, 'label', 'newLabel2', 'profile', '');
     $newWidgetProps['label'] = 'newLabel2';
     $profile->refresh();
     $widgetLayout = $profile->profileWidgetLayout;
     $widgetProps = $widgetLayout[$widgetClass];
     $this->assertEquals($newWidgetProps, $widgetProps);
     $this->obStart();
     $instance = self::createWidget($widgetClass . '_', $profile);
     $this->obEndClean();
     $instance->setWidgetProperty('label', 'newLabel3');
     $newWidgetProps['label'] = 'newLabel3';
     $profile->refresh();
     $widgetLayout = $profile->profileWidgetLayout;
     $widgetProps = $widgetLayout[$widgetClass];
     $this->assertEquals($newWidgetProps, $widgetProps);
     $instance->setWidgetProperties(array('label' => 'newLabel4'));
     $newWidgetProps['label'] = 'newLabel4';
     $profile->refresh();
     $widgetLayout = $profile->profileWidgetLayout;
     $widgetProps = $widgetLayout[$widgetClass];
     $this->assertEquals($newWidgetProps, $widgetProps);
 }
Example #24
0
 public function testDocsPermissions()
 {
     $auth = TestingAuxLib::loadAuthManagerMock();
     TestingAuxLib::loadX2NonWebUser();
     // user has docs update access
     $user = $this->users('testUser');
     $auth->setAccess('AdminIndex', $user->id, array(), false);
     TestingAuxLib::suLogin('testuser');
     $auth->setAccess('DocsAdmin', $user->id, array(), false);
     $auth->setAccess('DocsUpdateAccess', $user->id, array('X2Model' => new Docs()), true);
     // can't be edited since edit permissions list is empty
     $doc = $this->docs('0');
     $this->assertFalse((bool) $doc->checkEditPermissions());
     // "testuser" is in the edit permissions list
     $doc = $this->docs('1');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     $doc = $this->docs('3');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     // testuser created the the doc
     $doc = $this->docs('2');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     // user has docs private update access
     $auth->clearCache();
     $auth->setAccess('AdminIndex', $user->id, array(), false);
     $auth->setAccess('DocsAdmin', $user->id, array(), false);
     $auth->setAccess('DocsUpdateAccess', $user->id, array('X2Model' => new Docs()), false);
     $auth->setAccess('DocsPrivateUpdateAccess', $user->id, array('X2Model' => new Docs()), true);
     // can't be edited since edit permissions list is empty
     $doc = $this->docs('0');
     $this->assertFalse((bool) $doc->checkEditPermissions());
     // "testuser" is in the edit permissions list but since testuser only has private update
     // access, doc cannot be edited
     $doc = $this->docs('1');
     $this->assertFalse((bool) $doc->checkEditPermissions());
     $doc = $this->docs('3');
     $this->assertFalse((bool) $doc->checkEditPermissions());
     // testuser created the the doc, so they can edit it
     $doc = $this->docs('2');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     // user has docs admin access
     $auth->clearCache();
     $auth->setAccess('AdminIndex', $user->id, array(), false);
     $auth->setAccess('DocsAdmin', $user->id, array(), true);
     $auth->setAccess('DocsUpdateAccess', $user->id, array('X2Model' => new Docs()), false);
     $auth->setAccess('DocsPrivateUpdateAccess', $user->id, array('X2Model' => new Docs()), false);
     // user is docs admin
     $doc = $this->docs('0');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     // user is docs admin
     $doc = $this->docs('1');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     // user is docs admin
     $doc = $this->docs('2');
     $this->assertTrue((bool) $doc->checkEditPermissions());
     TestingAuxLib::restoreX2WebUser();
     TestingAuxLib::restoreX2AuthManager();
 }
Example #25
0
 public function tearDown()
 {
     // try to replace mocks with original components in case mocks were set during test case
     TestingAuxLib::restoreX2WebUser();
     TestingAuxLib::restoreX2AuthManager();
     TestingAuxLib::restoreController();
     self::$skipAllTests = false;
     self::$loadFixtures = X2_LOAD_FIXTURES;
     self::$loadFixturesForClassOnly = X2_LOAD_FIXTURES_FOR_CLASS_ONLY;
     if (isset($this->_oldSession)) {
         $_SESSION = $this->_oldSession;
     }
     return parent::tearDown();
 }
Example #26
0
 public function testChangeCompleteState()
 {
     TestingAuxLib::suLogin('admin');
     VERBOSE_MODE && (print Yii::app()->user->name . "\n");
     VERBOSE_MODE && (print (int) Yii::app()->params->isAdmin);
     VERBOSE_MODE && (print "\n");
     $action = $this->actions('action6');
     $completedNum = Actions::changeCompleteState('complete', array($action->id));
     $this->assertEquals(1, $completedNum);
     $action = Actions::model()->findByPk($action->id);
     VERBOSE_MODE && (print $action->complete . "\n");
     $this->assertTrue($action->complete === 'Yes');
     Actions::changeCompleteState('uncomplete', array($action->id));
     $action = Actions::model()->findByPk($action->id);
     $this->assertTrue($action->complete === 'No');
 }
Example #27
0
 public static function loadX2NonWebUser()
 {
     if (!isset(self::$_oldUserComponent) && Yii::app()->getComponent('user') instanceof X2WebUser) {
         self::$_oldUserComponent = Yii::app()->getComponent('user');
     }
     Yii::app()->setComponent('user', array('class' => 'X2NonWebUser'));
 }
 /**
  * Test visibility and access criteria for each access level 
  */
 public function testReadAccessLevels()
 {
     $auth = TestingAuxLib::loadAuthManagerMock();
     $user = $this->users('user2');
     $contactGroupmate = $this->contacts('contactGroupmate');
     $contactGroup = $this->contacts('contactGroup');
     $contactAnyone = $this->contacts('contactAnyone');
     $contactUserPrivate = $this->contacts('contactUserPrivate');
     $contactOtherPrivate = $this->contacts('contactOtherPrivate');
     $contactInvisible = $this->contacts('contactInvisible');
     // private read only access
     $auth->setAccess('ContactsReadOnlyAccess', $user->id, array(), false);
     $auth->setAccess('ContactsPrivateReadOnlyAccess', $user->id, array(), true);
     TestingAuxLib::suLogin('testUser2');
     $accessLevel = Contacts::model()->getAccessLevel();
     $this->assertEquals(X2PermissionsBehavior::QUERY_SELF, $accessLevel);
     $contactGroup->asa('permissions')->clearCache();
     $this->assertTrue($contactGroup->isVisibleTo(Yii::app()->getSuModel()));
     $contactGroupmate->asa('permissions')->clearCache();
     $this->assertFalse($contactGroupmate->isVisibleTo(Yii::app()->getSuModel()));
     $contactAnyone->asa('permissions')->clearCache();
     $this->assertFalse($contactAnyone->isVisibleTo(Yii::app()->getSuModel()));
     $contactUserPrivate->asa('permissions')->clearCache();
     $this->assertTrue($contactUserPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactOtherPrivate->asa('permissions')->clearCache();
     $this->assertFalse($contactOtherPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactInvisible->asa('permissions')->clearCache();
     $this->assertFalse($contactInvisible->isVisibleTo(Yii::app()->getSuModel()));
     $criteria = Contacts::model()->getAccessCriteria();
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertEquals(2, count($contacts));
     $this->assertEquals(2, count(array_intersect(array($contactGroup->id, $contactUserPrivate->id), array_map(function ($contact) {
         return $contact->id;
     }, $contacts))));
     // read only access
     $auth->setAccess('ContactsReadOnlyAccess', $user->id, array(), true);
     $auth->setAccess('ContactsPrivateReadOnlyAccess', $user->id, array(), false);
     $accessLevel = Contacts::model()->getAccessLevel();
     $this->assertEquals(X2PermissionsBehavior::QUERY_PUBLIC, $accessLevel);
     $contactGroup->asa('permissions')->clearCache();
     $this->assertTrue($contactGroup->isVisibleTo(Yii::app()->getSuModel()));
     $contactGroupmate->asa('permissions')->clearCache();
     $this->assertTrue($contactGroupmate->isVisibleTo(Yii::app()->getSuModel()));
     $contactAnyone->asa('permissions')->clearCache();
     $this->assertTrue($contactAnyone->isVisibleTo(Yii::app()->getSuModel()));
     $contactUserPrivate->asa('permissions')->clearCache();
     $this->assertTrue($contactUserPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactOtherPrivate->asa('permissions')->clearCache();
     $this->assertFalse($contactOtherPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactInvisible->asa('permissions')->clearCache();
     $this->assertFalse($contactInvisible->isVisibleTo(Yii::app()->getSuModel()));
     $criteria = Contacts::model()->getAccessCriteria();
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertEquals(4, count($contacts));
     $this->assertEquals(4, count(array_intersect(array($contactGroup->id, $contactGroupmate->id, $contactAnyone->id, $contactUserPrivate->id), array_map(function ($contact) {
         return $contact->id;
     }, $contacts))));
     // no access
     $auth->setAccess('ContactsReadOnlyAccess', $user->id, array(), false);
     $auth->setAccess('ContactsPrivateReadOnlyAccess', $user->id, array(), false);
     $accessLevel = Contacts::model()->getAccessLevel();
     $this->assertEquals(X2PermissionsBehavior::QUERY_NONE, $accessLevel);
     $contactGroup->asa('permissions')->clearCache();
     $this->assertFalse($contactGroup->isVisibleTo(Yii::app()->getSuModel()));
     $contactGroupmate->asa('permissions')->clearCache();
     $this->assertFalse($contactGroupmate->isVisibleTo(Yii::app()->getSuModel()));
     $contactAnyone->asa('permissions')->clearCache();
     $this->assertFalse($contactAnyone->isVisibleTo(Yii::app()->getSuModel()));
     $contactUserPrivate->asa('permissions')->clearCache();
     $this->assertFalse($contactUserPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactOtherPrivate->asa('permissions')->clearCache();
     $this->assertFalse($contactOtherPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactInvisible->asa('permissions')->clearCache();
     $this->assertFalse($contactInvisible->isVisibleTo(Yii::app()->getSuModel()));
     $criteria = Contacts::model()->getAccessCriteria();
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertEquals(0, count($contacts));
     $this->assertEquals(0, count(array_intersect(array(), array_map(function ($contact) {
         return $contact->id;
     }, $contacts))));
     // all access
     $auth->setAccess('ContactsAdmin', $user->id, array(), true);
     $auth->setAccess('AdminIndex', $user->id, array(), true);
     $auth->setAccess('ContactsReadOnlyAccess', $user->id, array(), true);
     $auth->setAccess('ContactsBasicAccess', $user->id, array(), true);
     $auth->setAccess('ContactsFullAccess', $user->id, array(), true);
     $auth->setAccess('ContactsUpdateAccess', $user->id, array(), true);
     $accessLevel = Contacts::model()->getAccessLevel();
     $this->assertEquals(X2PermissionsBehavior::QUERY_ALL, $accessLevel);
     $contactGroup->asa('permissions')->clearCache();
     $this->assertTrue($contactGroup->isVisibleTo(Yii::app()->getSuModel()));
     $contactGroupmate->asa('permissions')->clearCache();
     $this->assertTrue($contactGroupmate->isVisibleTo(Yii::app()->getSuModel()));
     $contactAnyone->asa('permissions')->clearCache();
     $this->assertTrue($contactAnyone->isVisibleTo(Yii::app()->getSuModel()));
     $contactUserPrivate->asa('permissions')->clearCache();
     $this->assertTrue($contactUserPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactOtherPrivate->asa('permissions')->clearCache();
     $this->assertTrue($contactOtherPrivate->isVisibleTo(Yii::app()->getSuModel()));
     $contactInvisible->asa('permissions')->clearCache();
     $this->assertFalse($contactInvisible->isVisibleTo(Yii::app()->getSuModel()));
     $criteria = Contacts::model()->getAccessCriteria();
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertEquals(5, count($contacts));
     $this->assertEquals(5, count(array_intersect(array($contactGroup->id, $contactGroupmate->id, $contactAnyone->id, $contactUserPrivate->id, $contactOtherPrivate->id), array_map(function ($contact) {
         return $contact->id;
     }, $contacts))));
     $criteria = Contacts::model()->getAccessCriteria('t', 'X2PermissionsBehavior', true);
     $contacts = Contacts::model()->findAll($criteria);
     $this->assertEquals(6, count($contacts));
     $this->assertEquals(6, count(array_intersect(array($contactGroup->id, $contactGroupmate->id, $contactAnyone->id, $contactUserPrivate->id, $contactOtherPrivate->id, $contactInvisible->id), array_map(function ($contact) {
         return $contact->id;
     }, $contacts))));
     TestingAuxLib::restoreX2AuthManager();
 }
Example #29
0
 public static function tearDownAfterClass()
 {
     if (X2_TEST_DEBUG_LEVEL > 0) {
         $timer = TestingAuxLib::getClassTimer();
         TestingAuxLib::log("time elapsed for test class: {$timer->stop()->getTime()}");
     }
     parent::tearDownAfterClass();
 }
Example #30
0
 /**
  * Tests a method in WorkflowController which belongs in the Workflow model class
  */
 public function testGetStageMemberDataProvider()
 {
     $workflow = $this->workflows('workflow2');
     $workflowStatus = Workflow::getWorkflowStatus($workflow->id);
     $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 1);
     $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
     // make record invisible
     $action = Actions::model()->findByAttributes(array('workflowId' => $workflow->id, 'complete' => 'No', 'stageNumber' => 8));
     $record = X2Model::getModelOfTypeWithId($action->associationType, $action->associationId);
     $record->visibility = 0;
     $record->assignedTo = 'admin';
     $this->assertSaves($record);
     $counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
     $this->assertEquals(1, $counts[3]);
     TestingAuxLib::suLogin('testuser');
     $counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
     $this->assertEquals(0, $counts[3]);
     $record->assignedTo = 'testuser';
     $this->assertSaves($record);
     $counts = $this->assertDataProviderCountMatchesStageCount($workflow, $workflowStatus, 4);
     $this->assertEquals(1, $counts[3]);
 }