Permalink
Browse files

initial checkin

Signed-off-by: Chris Granger <chris@wrenchlabs.com>
  • Loading branch information...
1 parent 951796d commit a955373b3b0e90df7c0bc28531e42d5e981689d1 Chris Granger committed Aug 7, 2009
Showing with 871 additions and 187 deletions.
  1. +8 −45 bindings/bindings.php
  2. +37 −0 components/gallery.php
  3. +4 −4 components/test.php
  4. +90 −0 components/tests/ormObjectHandling_test.php
  5. +120 −0 components/tests/ormSQLGeneration_test.php
  6. +0 −13 components/tests/super_test.php
  7. +0 −18 components/tests/test_test.php
  8. +0 −13 components/tests/user_test.php
  9. +3 −3 components/user.php
  10. BIN helpers/orm/.orm.php.swo
  11. BIN helpers/orm/.orm.php.swp
  12. +319 −55 helpers/orm/orm.php
  13. +12 −4 helpers/unit/unit.php
  14. BIN out/.DS_Store
  15. +90 −1 out/assets/css/default.css
  16. +3 −0 out/assets/css/slider.css
  17. BIN out/assets/images/apartment/P2080144.jpg
  18. BIN out/assets/images/apartment/P2080145.jpg
  19. BIN out/assets/images/apartment/P2080146.jpg
  20. BIN out/assets/images/apartment/P2080147.jpg
  21. BIN out/assets/images/apartment/P2080148.jpg
  22. BIN out/assets/images/apartment/P2080149.jpg
  23. BIN out/assets/images/apartment/P2080150.jpg
  24. BIN out/assets/images/apartment/P2080151.jpg
  25. BIN out/assets/images/apartment/P2080152.jpg
  26. BIN out/assets/images/apartment/P2080153.jpg
  27. BIN out/assets/images/apartment/P2080154.jpg
  28. BIN out/assets/images/apartment/P2080155.jpg
  29. BIN out/assets/images/apartment/P2080156.jpg
  30. BIN out/assets/images/apartment/P2080157.jpg
  31. BIN out/assets/images/apartment/P2080158.jpg
  32. BIN out/assets/images/apartment/P2080159.jpg
  33. BIN out/assets/images/apartment/P2080160.jpg
  34. BIN out/assets/images/apartment/P2080161.jpg
  35. BIN out/assets/images/apartment/P2080162.jpg
  36. BIN out/assets/images/apartment/P2080163.jpg
  37. BIN out/assets/images/apartment/P2080164.jpg
  38. BIN out/assets/images/apartment/P2080165.jpg
  39. BIN out/assets/images/apartment/P2080166.jpg
  40. BIN out/assets/images/apartment/P2080167.jpg
  41. BIN out/assets/images/apartment/P2080168.jpg
  42. BIN out/assets/images/apartment/P2080169.jpg
  43. BIN out/assets/images/apartment/P2080170.jpg
  44. BIN out/assets/images/featuredpostbg.jpg
  45. BIN out/assets/images/headerbg.gif
  46. BIN out/assets/images/headerbg.jpg
  47. BIN out/assets/images/headerbg.png
  48. BIN out/assets/images/openedtext.gif
  49. BIN out/assets/images/subheaderbg.jpg
  50. BIN out/assets/images/subheadertext1.gif
  51. BIN out/assets/images/subheadertext2.gif
  52. +9 −0 out/assets/js/blog.js
  53. +27 −0 out/layouts/default.php
  54. +12 −0 out/layouts/lang.php
  55. +23 −7 out/layouts/test.php
  56. +34 −9 out/views/index.php
  57. +39 −0 out/views/lang.php
  58. +11 −0 out/views/pics/group.php
  59. +9 −0 out/views/pics/index.php
  60. 0 out/views/pics/single.php
  61. +17 −0 out/views/projects.php
  62. BIN sys/.DS_Store
  63. +1 −1 sys/config/base.php
  64. BIN sys/core/.event.php.swp
  65. +2 −12 sys/core/bm.php
  66. +1 −2 sys/core/event.php
View
@@ -1,6 +1,6 @@
<?php
-config::set('profiler.display', true);
+config::set('profiler.display', false);
config::set('profiler.showErrors', true);
config::set('unit.url', '/test');
@@ -9,48 +9,6 @@
config::set('validator.form.default', 'validate');
-config::set('database.config.group', 'localhost');
-config::set('database.config.localhost', array(
- 'username' => 'root',
- 'password' => 'root',
- 'hostname' => 'localhost',
- 'database' => 'test'
-));
-
-config::set('schema.company.has_one', array('companytype', 'user'));
-config::set('schema.user.has_one', array('usertype', 'email'));
-config::set('schema.email.has_one', array('emailtype'));
-config::set('schema.companytype.belongs_to_many', 'company');
-
-$yes = ORM::factory('company')->with('companytype', array('user', 'usertype', array('email', 'emailtype')))->order('user.name DESC')->fetch('massive');
-
-/*$yes = ORM::factory('company')
- ->with('companytype', 'user')
- ->where('company.name = "?"', 'woot')
- ->fetch('skookum');
- */
-
-
-/*
-class Company_Model extends orm {}
-class Project_Model extends orm {}
-
-
-profiler::start('test');
-$comp = ORM::factory('company');
-
-$comp->select('value')->find(1);
-//$comp->find(2);
-
-//$projects = ORM::factory('project');
-//$projects->select('name')->find_all();
-profiler::end('test');
-//var_dump($projects);
-*/
-
-//url listeners
-$this->event->register('url::/index','test::event');
-$this->event->register('url::/index', 'test::event2');
/*
access::restrict('/admin', array(
@@ -59,12 +17,19 @@ class Project_Model extends orm {}
));
*/
+//url listeners
+$this->event->register('url::/index','test::event');
+$this->event->register('url::/index', 'test::event2');
+
+
+
$this->event->register('url::/cool/test', 'test::event');
//form listeners
$this->event->register('submit::login', 'user::login');
$this->event->register('submit::login', 'test::event');
+
//custom
$this->event->register('kaboom', 'test::bombsquad');
@@ -73,5 +38,3 @@ class Project_Model extends orm {}
$this->event->register('sys::preForm', 'validator::dispatch');
$this->event->register('url::'.config::get('unit.url'), 'unit::runUnits');
-
-?>
View
@@ -0,0 +1,37 @@
+<?php
+
+class gallery extends trigger_component {
+
+ const IMAGEDIR = 'out/assets/images/';
+
+ function gallery() {
+ parent::__construct();
+
+ $this->OUTPUTDIR = FOLDER.'/assets/images/';
+
+ $this->group = $this->event->segment(1);
+ $this->picName = $this->event->segment(2);
+ }
+
+ public function pics() {
+
+ $pics = array();
+
+ if(!$this->picName) {
+ foreach (new DirectoryIterator(self::IMAGEDIR.$this->group) as $pic) {
+ if(substr($pic, 0, 1) != '.') {
+ $pics[] = $this->OUTPUTDIR."$this->group/$pic";
+ }
+ }
+ } else {
+ $pics[] = $this->OUTPUTDIR.$this->group.'/'.$this->picName;
+ }
+
+ return $pics;
+ }
+
+ public function group() {
+ return $this->group;
+ }
+
+}
View
@@ -10,16 +10,16 @@ function test() {
function event() {
//profiler::debug($this->event);
- echo 'responding to an event<br/>';
+ //echo 'responding to an event<br/>';
}
function event2($info) {
- echo 'second response to "event" - with info: '.$info.'<br/>';
+ //echo 'second response to "event" - with info: '.$info.'<br/>';
$this->event->trigger('kaboom');
}
function bombsquad() {
- echo 'bomb diffused<br/>';
+ //echo 'bomb diffused<br/>';
}
function info() {
@@ -53,4 +53,4 @@ function aggregate($node) {
}
-?>
+?>
@@ -0,0 +1,90 @@
+<?php
+
+class ormObjectHandling_test extends unit_test {
+
+ public function setup() {
+
+ config::set('database.config.group', 'localhost');
+ config::set('database.config.localhost', array(
+ 'username' => 'root',
+ 'password' => 'root',
+ 'hostname' => 'localhost',
+ 'database' => 'test'
+ ));
+
+ config::set('schema.company.has_one', array('companytype'));
+ config::set('schema.company.has_many', array('user'));
+ config::set('schema.company.has_and_belongs_to_many', array('category'));
+ config::set('schema.user.has_one', array('usertype', 'email'));
+ config::set('schema.email.has_one', array('emailtype'));
+ config::set('schema.companytype.belongs_to_many', 'company');
+
+ config::set('schema.company.fields', array('ID', 'name', 'companytype_ID', 'created_ts', 'modified_ts'));
+ config::set('schema.companytype.fields', array('ID', 'value', 'created_ts', 'modified_ts'));
+
+ config::set('schema.company.secondaryKey', 'name');
+
+ }
+
+ private function standardAssumptionForCompanyQuery($query) {
+ $this->assertTrue(is_object($query));
+ $this->assertEquals($query->count(), 2);
+
+ $this->assertEquals($query[0]->name, 'skookum');
+ $this->assertEquals($query[1]->name, 'wrenchlabs');
+ }
+
+ public function basic_test() {
+
+ $query = ORM::factory('company');
+ $this->assertTrue(is_object($query));
+
+ }
+
+ public function basicQuery_test() {
+
+ $query = ORM::factory('company')->fetch();
+
+ $this->standardAssumptionForCompanyQuery($query);
+ }
+
+ public function has_one_WithQuery_test() {
+
+ $query = ORM::factory('company')->with('companytype')->fetch();
+
+ $this->standardAssumptionForCompanyQuery($query);
+
+ $this->assertEquals($query[0]->companytype->value, 'small');
+
+
+
+ /*
+ $query->companytype = ORM::object('companytype');
+ $query->companytype->ID = '5';
+ $query->companytype->name = 'woot';
+ /*
+ $query->ID = 3;
+ $query->name = 'chris';
+ $query->category = ORM::factory('category')->fetch('super');
+
+ $query[1] = clone $query[0];
+ $query[1]->ID = 1;
+ $query[1]->name = 'robert';
+
+
+ foreach($query as $key=>$value) {
+ profiler::debug($value);
+ }
+
+ profiler::debug($query);
+ */
+ //$query->save();
+
+ /*$query = ORM::factory('company')
+ ->with('companytype', 'user')
+ ->where('company.name = "?"', 'woot')
+ ->fetch('skookum');
+ */
+ }
+
+}
@@ -0,0 +1,120 @@
+<?php
+
+class ormSQLGeneration_test extends unit_test {
+
+ public function setup() {
+
+ config::set('database.config.group', 'localhost');
+ config::set('database.config.localhost', array(
+ 'username' => 'root',
+ 'password' => 'root',
+ 'hostname' => 'localhost',
+ 'database' => 'test'
+ ));
+
+ config::set('schema.company.has_one', array('companytype'));
+ config::set('schema.company.has_many', array('user'));
+ config::set('schema.company.has_and_belongs_to_many', array('category'));
+ config::set('schema.user.has_one', array('usertype', 'email'));
+ config::set('schema.email.has_one', array('emailtype'));
+ config::set('schema.companytype.belongs_to_many', 'company');
+
+ config::set('schema.company.secondaryKey', 'name');
+
+ }
+
+ public function basic_test() {
+
+ $query = ORM::factory('company');
+ $this->assertTrue(is_object($query));
+
+ }
+
+ public function basicQuery_test() {
+
+ $query = ORM::factory('company')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.* FROM company');
+
+ }
+
+ public function basicOrder_test() {
+ $query = ORM::factory('company')->order('company.name DESC')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.* FROM company ORDER BY company.name DESC');
+ }
+
+ public function multiOrder_test() {
+ $query = ORM::factory('company')->order('company.name ASC')->order('company.ID DESC')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.* FROM company ORDER BY company.name ASC, company.ID DESC');
+ }
+
+ public function basicGroup_test() {
+ $query = ORM::factory('company')->group('company.name')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.* FROM company GROUP BY company.name');
+ }
+
+ public function multiGroup_test() {
+ $query = ORM::factory('company')->group('company.name')->group('company.ID')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.* FROM company GROUP BY company.name, company.ID');
+ }
+
+ public function distinctQuery_test() {
+ $query = ORM::factory('company')->distinct()->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT DISTINCT company.* FROM company');
+ }
+
+ public function calcFoundQuery_test() {
+ $query = ORM::factory('company')->calcFound()->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT SQL_CALC_FOUND_ROWS company.* FROM company');
+ }
+
+ public function has_one_WithQuery_test() {
+
+ $query = ORM::factory('company')->with('companytype')->sqlMode(true)->fetch();
+ //single join created for the many-to-one or one-to-one relationship
+ $this->assertEquals($query, 'SELECT company.*, companytype.* FROM company LEFT JOIN companytype ON company.companytype_ID = companytype.ID');
+
+ }
+
+ public function has_many_WithQuery_test() {
+
+ $query = ORM::factory('company')->with('user')->sqlMode(true)->fetch();
+ //single join created for the one-to-many relationship
+ $this->assertEquals($query, 'SELECT company.*, user.* FROM company LEFT JOIN user ON company.ID = user.company_ID');
+
+ }
+
+ public function belongs_to_many_WithQuery_test() {
+
+ $query = ORM::factory('companytype')->with('company')->sqlMode(true)->fetch();
+ //single join created for the one-to-many relationship
+ $this->assertEquals($query, 'SELECT companytype.*, company.* FROM companytype LEFT JOIN company ON company.companytype_ID = companytype.ID');
+
+ }
+
+ public function has_and_belongs_to_many_WithQuery_test() {
+
+ $query = ORM::factory('company')->with('category')->sqlMode(true)->fetch();
+ //should use a junction table and then join through that
+ //two joins created.
+ $this->assertEquals($query, 'SELECT company.*, category.* FROM company LEFT JOIN category_company ON company.ID = category_company.company_ID LEFT JOIN category ON category_company.category_ID = category.ID');
+
+ }
+
+ public function multiWith_test() {
+ $query = ORM::factory('company')->with('companytype', 'category', 'user')->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.*, companytype.*, category.*, user.* FROM company LEFT JOIN companytype ON company.companytype_ID = companytype.ID LEFT JOIN category_company ON company.ID = category_company.company_ID LEFT JOIN category ON category_company.category_ID = category.ID LEFT JOIN user ON company.ID = user.company_ID');
+ }
+
+ public function nestedWith_test() {
+ $query = ORM::factory('company')->with(array('user', 'usertype'))->sqlMode(true)->fetch();
+ $this->assertEquals($query, 'SELECT company.*, user.*, usertype.* FROM company LEFT JOIN user ON company.ID = user.company_ID LEFT JOIN usertype ON user.usertype_ID = usertype.ID');
+ }
+
+ public function fullQuery_test() {
+
+ $query = ORM::factory('company')->with('companytype', 'category', array('user', 'usertype', array('email', 'emailtype')))->order('user.name DESC')->calcFound()->sqlMode(true)->fetch('massive');
+ $this->assertEquals($query, 'SELECT SQL_CALC_FOUND_ROWS company.*, companytype.*, category.*, user.*, usertype.*, email.*, emailtype.* FROM company LEFT JOIN companytype ON company.companytype_ID = companytype.ID LEFT JOIN category_company ON company.ID = category_company.company_ID LEFT JOIN category ON category_company.category_ID = category.ID LEFT JOIN user ON company.ID = user.company_ID LEFT JOIN usertype ON user.usertype_ID = usertype.ID LEFT JOIN email ON user.email_ID = email.ID LEFT JOIN emailtype ON email.emailtype_ID = emailtype.ID WHERE company.name = "massive" ORDER BY user.name DESC');
+
+ }
+
+}
@@ -1,13 +0,0 @@
-<?php
-
-class super_test extends unit_test {
-
- function woot_test() {
- $this->assertTrue(true);
- }
-
- function super_awesome_test() {
- $this->assertFalse(true);
- }
-
-}
@@ -1,18 +0,0 @@
-<?php
-
-class test_test extends unit_test {
-
- function addA_test() {
- $str = 'look';
- $this->assertEquals($this->event->call('test::addA', $str), 'lookA!');
- }
-
- function super_awesome_test() {
- $this->assertFalse(true);
- }
-
- function woot() {
- echo 'yay';
- }
-
-}
Oops, something went wrong.

0 comments on commit a955373

Please sign in to comment.