예제 #1
0
 public function testUpdateTopBarLinks()
 {
     //
     // ensure that we can reorder modules
     //
     $moduleIdsOrdered = Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            where visible\n            order by menuPosition asc\n        ")->queryColumn();
     Modules::updateTopBarLinks(array_reverse($moduleIdsOrdered), array());
     $moduleIdsOrderedNew = Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            where visible\n            order by menuPosition asc\n        ")->queryColumn();
     // ensure that module menu position order was reversed
     $this->assertEquals(array_reverse($moduleIdsOrdered), $moduleIdsOrderedNew);
     //
     // ensure that we can change visibility of modules
     //
     $moduleIdsOrdered = $moduleIdsOrderedNew;
     Modules::updateTopBarLinks(array(), $moduleIdsOrdered);
     $hiddenModuleIds = Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            where not visible and menuPosition=-1\n            order by id asc\n        ")->queryColumn();
     // ensure that all formerly visible modules are now hidden with menuPosition = -1
     $this->assertEquals(ArrayUtil::sort($moduleIdsOrdered), $hiddenModuleIds);
     //
     // Change visibility and reorder, for good measure
     //
     $moduleIds = Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            order by id asc\n        ")->queryColumn();
     $hideThese = array_reverse(array_slice($moduleIds, 0, floor(count($moduleIds) / 2)));
     $showThese = array_reverse(array_slice($moduleIds, floor(count($moduleIds) / 2)));
     Modules::updateTopBarLinks($showThese, $hideThese);
     $this->assertEquals($showThese, Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            where visible\n            order by menuPosition asc\n        ")->queryColumn());
     $this->assertEquals($hideThese, Yii::app()->db->createCommand("\n            select id\n            from x2_modules\n            where not visible and menuPosition = -1\n            order by id desc\n        ")->queryColumn());
 }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
    public function testScanForTags()
    {
        $contact = $this->contacts('testAnyone');
        $contact->clearTags();
        $expectedTags = array('#test', '#test2', '#test3', '#test4', '#test-test');
        $badTags = array('#test5', '#test6', '#test7', '#test-');
        $bgInfo = '#test  #test2 #test3
#test-test
#test4
#test-
<style> 
#test5 {
    background: #test6
}
</style> <span style=" #test7 "></span>';
        foreach (array_merge($badTags, $expectedTags) as $tag) {
            $this->assertFalse($contact->hasTag($tag, null, true));
        }
        $contact->backgroundInfo = $bgInfo;
        $contactTags = $contact->scanForTags();
        $this->assertEquals(ArrayUtil::sort($expectedTags), ArrayUtil::sort($contactTags));
    }
예제 #4
0
 public function testScanForTags()
 {
     $contact = $this->contacts('testAnyone');
     $contact->clearTags();
     $tags = array('#test', '#test2', '#test3');
     foreach ($tags as $tag) {
         $this->assertFalse($contact->hasTag($tag, null, true));
     }
     $contact->backgroundInfo = implode(' , ', $tags);
     $contactTags = $contact->scanForTags();
     $this->assertEquals($tags, ArrayUtil::sort($contactTags));
 }