Esempio n. 1
0
 /**
  * Create new list from selection then mass add to newly created list
  */
 public function testExecute()
 {
     TestingAuxLib::suLogin('admin');
     X2List::model()->deleteAllByAttributes(array('name' => 'test'));
     $newList = new NewListFromSelection();
     $addToList = new MassAddToList();
     // create new list with 2 records
     $_POST['modelType'] = 'Contacts';
     $_POST['listName'] = 'test';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_SERVER['SERVER_NAME'] = 'localhost';
     Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null));
     $gvSelection = range(1, 2);
     AuxLib::debugLogR($newList->execute($gvSelection));
     $getFlashes = TestingAuxLib::setPublic('NewListFromSelection', 'getFlashes');
     AuxLib::debugLogR($getFlashes());
     $list = X2List::model()->findByAttributes(array('name' => 'test'));
     $itemIds = $list->queryCommand(true)->select('id')->queryColumn();
     $this->assertEquals(array(1, 2), $itemIds);
     //  add the rest of the contacts to the newly created list
     unset($_POST['modelType']);
     unset($_POST['listName']);
     $_POST['listId'] = $list->id;
     $gvSelection = range(3, 24);
     $addToList->execute($gvSelection);
     $itemIds = $list->queryCommand(true)->select('id')->queryColumn();
     $this->assertEquals(range(1, 24), $itemIds);
 }
Esempio n. 2
0
 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'));
 }
Esempio n. 3
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());
 }
Esempio n. 4
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);
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 public function testSetPublic()
 {
     $fn = TestingAuxLib::setPublic('TestingAuxLib', 'privateMethod');
     $this->assertTrue($fn(array(1, 2)) === array(1, 2));
 }
Esempio n. 7
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);
 }
Esempio n. 8
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));
     }
 }
Esempio n. 9
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));
 }
Esempio n. 10
0
 public function testDeleteOldNotifications()
 {
     TestingAuxLib::suLogin('admin');
     // assigned to testuser
     $action = $this->actions('action1');
     $reminders = $action->getReminders(true);
     foreach ($reminders as $reminder) {
         $this->assertTrue($reminder->delete());
     }
     $deleteOldNotifications = TestingAuxLib::setPublic($action, 'deleteOldNotifications');
     $this->assertEquals(0, count($action->getReminders(true)));
     $action->createNotifications('assigned', 1234, 'action_reminder');
     $this->assertGreaterThan(0, count($action->getReminders(true)));
     $deleteOldNotifications('me');
     $this->assertGreaterThan(0, count($action->getReminders(true)));
     $deleteOldNotifications('assigned');
     $this->assertEquals(0, count($action->getReminders(true)));
 }