Пример #1
0
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notes = Note::getAll();
     $this->assertEquals(0, count($notes));
     $import = new Import();
     $serializedData['importRulesType'] = 'Notes';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('simpleImportTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.notes.tests.unit.files'));
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('occurredOnDateTime'), 'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Notes');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $notes = Note::getAll();
     $this->assertEquals(3, count($notes));
     $notes = Note::getByName('note1');
     $this->assertEquals(1, count($notes[0]));
     $this->assertEquals(1, count($notes[0]->activityItems));
     $this->assertEquals('testAccount', $notes[0]->activityItems[0]->name);
     $this->assertEquals('Account', get_class($notes[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 05:03', substr($notes[0]->latestDateTime, 0, -3));
     $notes = Note::getByName('note2');
     $this->assertEquals(1, count($notes[0]));
     $this->assertEquals(1, count($notes[0]->activityItems));
     $this->assertEquals('testContact', $notes[0]->activityItems[0]->firstName);
     $this->assertEquals('Contact', get_class($notes[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 05:03', substr($notes[0]->latestDateTime, 0, -3));
     $notes = Note::getByName('note3');
     $this->assertEquals(1, count($notes[0]));
     $this->assertEquals(1, count($notes[0]->activityItems));
     $this->assertEquals('testOpportunity', $notes[0]->activityItems[0]->name);
     $this->assertEquals('Opportunity', get_class($notes[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 06:03', substr($notes[0]->latestDateTime, 0, -3));
     //Confirm 10 rows were processed as 'created'.
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED));
     //Confirm that 0 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 2 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2');
     $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $account = Account::getById($superAccountId);
     $account2 = Account::getById($superAccountId2);
     $contact = Contact::getById($superContactId);
     //confirm no existing activities exist
     $activities = Activity::getAll();
     $this->assertEquals(0, count($activities));
     //Test just going to the create from relation view.
     $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $this->runControllerWithNoExceptionsAndGetContent('notes/default/createFromRelation');
     //add related note for account using createFromRelation action
     $activityItemPostData = array('account' => array('id' => $superAccountId));
     $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNote')));
     $this->runControllerWithRedirectExceptionAndGetContent('notes/default/createFromRelation');
     //now test that the new note exists, and is related to the account.
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
     $this->assertEquals('myNote', $notes[0]->description);
     $this->assertEquals(1, $notes[0]->activityItems->count());
     $activityItem1 = $notes[0]->activityItems->offsetGet(0);
     $this->assertEquals($account, $activityItem1);
     //test viewing the existing note in a details view
     $this->setGetArray(array('id' => $notes[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('notes/default/details');
     //test editing an existing note and saving.
     //First just go to the edit view and confirm it loads ok.
     $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('notes/default/edit');
     //Save changes via edit action.
     $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId));
     $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX')));
     $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit');
     //Confirm changes applied correctly.
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
     $this->assertEquals('myNoteX', $notes[0]->description);
     $this->assertEquals(2, $notes[0]->activityItems->count());
     $activityItem1 = $notes[0]->activityItems->offsetGet(0);
     $activityItem2 = $notes[0]->activityItems->offsetGet(1);
     $this->assertEquals($account, $activityItem1);
     $this->assertEquals($contact, $activityItem2);
     //Remove contact relation.  Switch account relation to a different account.
     $activityItemPostData = array('Account' => array('id' => $superAccountId2));
     $this->setGetArray(array('id' => $notes[0]->id));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'myNoteX')));
     $this->runControllerWithRedirectExceptionAndGetContent('notes/default/edit');
     //Confirm changes applied correctly.
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
     $this->assertEquals('myNoteX', $notes[0]->description);
     $this->assertEquals(1, $notes[0]->activityItems->count());
     $activityItem1 = $notes[0]->activityItems->offsetGet(0);
     $this->assertEquals($account2, $activityItem1);
     //Test validating an existing note via the inline edit validation (failed Validation)
     $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId));
     $this->setGetArray(array('id' => $notes[0]->id, 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'ajax' => 'inline-edit-form', 'Note' => array('description' => '')));
     $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave');
     $this->assertTrue(strlen($content) > 20);
     //approximate, but should definetely be larger than 20.
     //Test validating an existing note via the inline edit validation (Success)
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'ajax' => 'inline-edit-form', 'Note' => array('description' => 'a Valid Name of a Note')));
     $content = $this->runControllerWithExitExceptionAndGetContent('notes/default/inlineCreateSave');
     $this->assertEquals('[]', $content);
     //Test saving an existing note via the inline edit validation
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Note' => array('description' => 'a Valid Name of a Note')));
     $content = $this->runControllerWithRedirectExceptionAndGetContent('notes/default/inlineCreateSave');
     //Confirm changes applied correctly.
     $notes = Note::getAll();
     $this->assertEquals(2, count($notes));
     $this->assertEquals('a Valid Name of a Note', $notes[1]->description);
     //test removing a note.
     $this->setGetArray(array('id' => $notes[1]->id));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('notes/default/delete');
     //Confirm no more notes exist.
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
 }
Пример #3
0
            $res = self::query("UPDATE `notes` SET `title` = '{$title}', `message` = '{$message}' WHERE `notes`.`id` = {$id}");
        }
        // Return query result
        return json_encode($res);
    }
    public static function delete($id)
    {
        $res = self::query("DELETE FROM notes WHERE `id` = {$id}");
        return $res;
    }
}
// Our script requires JSON data format
// Set Content-Type to JSON
header('Content-Type: application/json');
// if GET request then return the list of all items
// if POST request then add, edit or delete
switch ($_SERVER['REQUEST_METHOD']) {
    case 'GET':
        echo Note::getAll();
        break;
    case 'POST':
        if (isset($_POST['action'])) {
            echo Note::delete($_POST['id']);
        } else {
            print_r(Note::save($_POST));
        }
        break;
    default:
        echo 'Unknown operation';
        break;
}
Пример #4
0
 function getSelect($sort = "content", $order = "ASC")
 {
     $results = Note::getAll(null, $sort, $order);
     $temp = array(array("label" => "Edit item"));
     foreach ($results as $row) {
         $temp[] = array("value" => $row['id'], "label" => str_replace("\n", " /", stripslashes($row['content'])));
     }
     return $temp;
 }
Пример #5
0
	<div>
		<a href='browse.php?cid=".$cid."&tid=".$tid."&h=25'>small</a> | 
		<a href='browse.php?cid=".$cid."&tid=".$tid."&h=50'>med</a> |
		<a href='browse.php?cid=".$cid."&tid=".$tid."&h=75'>large</a>
	</div>";

$where = array();
if(!is_null($cid) && !empty($cid)){
	$category = new Category($cid);
	$where["category_id"] = $cid;
}

if(!is_null($tid) && !empty($tid)){
	$where["type_id"] = $tid;
}

$all_notes = Note::getAll( $where );


foreach($all_notes as $note){
	echo "
		<div style='float:left;'>
			<a href='index.php?id=".$note['id']."'>
				<img border='0' src='../image.php?id=".$note['id']."&h=".$h."' />
			</a>
			<br/><span style='font-size:9px'>".nl2br($note['content'])."</span>
		</div>";
}

}
?>
 /**
  * @depends testPostGameNotificationToProfile
  */
 public function testPostingAnNoteCarriesPermissionsCorrectly()
 {
     if (!SECURITY_OPTIMIZED) {
         return;
     }
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $socialItems = SocialItem::getAll();
     $this->assertEquals(2, count($socialItems));
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $activityItemPostData = array('Account' => array('id' => $superAccountId));
     $this->setGetArray(array('redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'postToProfile' => true, 'Note' => array('description' => 'a note that is promoted')));
     $content = $this->runControllerWithRedirectExceptionAndGetContent('notes/default/inlineCreateSave');
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
     $socialItems = SocialItem::getAll();
     $this->assertEquals(3, count($socialItems));
     $this->assertEquals($notes[0]->id, $socialItems[2]->note->id);
     $this->assertNull($socialItems[2]->description);
 }
Пример #7
0
//	remove old images
clearDirectory( $target_dir );

//	create new
$db = new Database( "db13310_notes" );
$sql  = "SELECT id,image_full,image_full_back FROM notes";
$query = $db->query($sql);
$items = array();

while($row = $db->getRow($query)){
	$items[] = $row;
}

if( isset( $_GET['id'] ) )
{
	$images = Note::getAll( array( "id" => $_GET['id'] ) );
}

foreach($items as $item)
{
	if( isset( $item['image_full'] ) ) createImage( $item, 'image_full' );
	if( isset( $item['image_full_back'] ) ) createImage( $item, 'image_full_back', '_back' );
}

function createImage( $item, $data_field, $suffix = '' )
{
	$defs = array
	(
		array('ext'=>'tiny','height'=>30,'crop'=>false)
	);
Пример #8
0
 /**
  * @depends testUpdateNoteFromForm
  */
 public function testDeleteNote()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notes = Note::getAll();
     $this->assertEquals(2, count($notes));
     $notes[0]->delete();
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
 }