public function testRecursiveFindAll() { $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'ArticleFeaturedsTags', 'Featured', 'Category'); $TestModel = new Article(); $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); $expected = array(array('Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Comment' => array(array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31')), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'))), array('Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Comment' => array(), 'Tag' => array())); $this->assertEquals($expected, $result); $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 3), 'limit' => 1, 'recursive' => 2)); $expected = array(array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), 'Comment' => array(array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Attachment' => array('id' => '1', 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31')), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), 'Attachment' => array())), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')))); $this->assertEquals($expected, $result); $Featured = new Featured(); $Featured->recursive = 2; $Featured->bindModel(array('belongsTo' => array('ArticleFeatured' => array('conditions' => "ArticleFeatured.published = 'Y'", 'fields' => 'id, title, user_id, published')))); $Featured->ArticleFeatured->unbindModel(array('hasMany' => array('Attachment', 'Comment'), 'hasAndBelongsToMany' => array('Tag'))); $orderBy = 'ArticleFeatured.id ASC'; $result = $Featured->find('all', array('order' => $orderBy, 'limit' => 3)); $expected = array(array('Featured' => array('id' => '1', 'article_featured_id' => '1', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'ArticleFeatured' => array('id' => '1', 'title' => 'First Article', 'user_id' => '1', 'published' => 'Y', 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Category' => array(), 'Featured' => array('id' => '1', 'article_featured_id' => '1', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), 'Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')), array('Featured' => array('id' => '2', 'article_featured_id' => '2', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'ArticleFeatured' => array('id' => '2', 'title' => 'Second Article', 'user_id' => '3', 'published' => 'Y', 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), 'Category' => array(), 'Featured' => array('id' => '2', 'article_featured_id' => '2', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), 'Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'))); $this->assertEquals($expected, $result); }
/** * testCreation method * * @return void */ public function testCreation() { $this->loadFixtures('Article', 'ArticleFeaturedsTags', 'User', 'Featured'); $TestModel = new Test(); $result = $TestModel->create(); $expected = array('Test' => array('notes' => 'write some notes here')); $this->assertEquals($expected, $result); $TestModel = new User(); $result = $TestModel->schema(); if (isset($this->db->columns['primary_key']['length'])) { $intLength = $this->db->columns['primary_key']['length']; } elseif (isset($this->db->columns['integer']['length'])) { $intLength = $this->db->columns['integer']['length']; } else { $intLength = 11; } foreach (array('collate', 'charset', 'comment', 'unsigned') as $type) { foreach ($result as $i => $r) { unset($result[$i][$type]); } } $expected = array('id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => $intLength, 'key' => 'primary'), 'user' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => 255), 'password' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => 255), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null)); $this->assertEquals($expected, $result); $TestModel = new Article(); $result = $TestModel->create(); $expected = array('Article' => array('published' => 'N')); $this->assertEquals($expected, $result); $FeaturedModel = new Featured(); $data = array('article_featured_id' => 1, 'category_id' => 1, 'published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20)); $expected = array('Featured' => array('article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2008-06-11 00:00:00', 'end_date' => '2008-06-20 00:00:00')); $this->assertEquals($expected, $FeaturedModel->create($data)); $data = array('published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20), 'article_featured_id' => 1, 'category_id' => 1); $expected = array('Featured' => array('published_date' => '2008-06-11 00:00:00', 'end_date' => '2008-06-20 00:00:00', 'article_featured_id' => 1, 'category_id' => 1)); $this->assertEquals($expected, $FeaturedModel->create($data)); }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/general.include.php'; inc('/site/portfolio.class.php'); inc('/site/featured.class.php'); $Featured = new Featured(); $Template->AddStyleSheet('largebox'); $Template->AddStyleSheet('featured'); $Template->makeHeader(); $Featured->makeHeader(); $Featured->MakeView(); $Featured->makeFooter(); //$Portfolio->traceWindow(); $Template->makeFooter();
/** * Save promoted user record to the database * * @return Response */ public function promote_user_post() { $f = new Featured(); $f->title = Input::get('title'); $f->artist = Input::get('user'); $f->text = Input::get('text'); $f->track = Input::get('track'); if (Input::has('art')) { $image = Input::get('art'); $exp = explode(",", $image); $name = str_random(15); $data = base64_decode($exp[1]); $tempfile = storage_path() . "/temp/" . $name . ""; file_put_contents($tempfile, $data); Image::make($tempfile)->resize(350, 400)->save(storage_path() . "/featured-art/" . $name . ".png"); unlink($tempfile); $f->art = $name . ".png"; } $f->save(); return Redirect::to('admin/users'); }
function makeFeatured() { inc('site/featured.class.php'); $Featured = new Featured(); $Featured->makeFrontPage(); }