public static function initialize(Jam_Meta $meta) { $meta->db(Kohana::TESTING); parent::initialize($meta); $meta->behaviors(['username' => Jam::behavior('username')]); $meta->associations(array('user_tokens' => Jam::association('hasmany', array('foreign_model' => 'test_user_token', 'foreign_key' => 'test_user_id')), 'roles' => Jam::association('manytomany', array('foreign_model' => 'test_role', 'join_table' => 'test_roles_users', 'foreign_key' => 'test_role_id', 'association_foreign_key' => 'test_user_id')))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('server' => 'test_local')), 'file2' => Jam::field('upload', array('server' => 'test_local', 'path' => 'test/:model/:model:id')))); }
public function test_empty_value() { $model = Jam::build('test_position'); $field = new Jam_Field_Timestamp(array('timezone' => new Jam_Timezone())); $value = $field->set($model, '', FALSE); $this->assertNull($value); }
public function duplicate() { $duplicate = Jam::build('brand_purchase_shipping', array('brand_purchase' => $this->brand_purchase)); // This is needed to counteract inverse_of brand_purchase in brand_purchase_shipping $this->brand_purchase->shipping = $this; return $duplicate; }
/** * @covers Model_Collection_Promotion::not_expired */ public function test_not_expired() { $time = strtotime('2013-02-02'); $sql = (string) Jam::all('promotion')->not_expired($time); $expected_sql = "SELECT `promotions`.* FROM `promotions` WHERE (`promotions`.`expires_at` IS NULL OR `promotions`.`expires_at` >= '2013-02-02 00:00:00')"; $this->assertEquals($expected_sql, $sql); }
/** * @dataProvider data_change_password */ public function test_change_password($password, $expected_hashed) { $field = new Jam_Field_Password(); $model = Jam::build('test_position'); $hashed = $field->convert($model, $password, FALSE); $this->assertEquals($expected_hashed, $hashed); }
public function compile($db = NULL) { if ($this->context_model() and $meta = Jam::meta(Jam_Query_Builder::aliased_model($this->context_model()))) { $db = Database::instance($meta->db()); } $original_on = $this->_on; $original_using = $this->_using; $original_table = $this->_table; if (!empty($this->_on)) { foreach ($this->_on as &$condition) { $condition[0] = Jam_Query_Builder::resolve_attribute_name($condition[0], $this->model() ? $this->model() : $this->_table); $condition[2] = Jam_Query_Builder::resolve_attribute_name($condition[2], $this->context_model()); } } $this->_table = Jam_Query_Builder::resolve_table_alias($this->_table); if (!empty($this->_using)) { foreach ($this->_using as &$column) { $column = Jam_Query_Builder::resolve_attribute_name($column, $this->meta()); } } $additional_joins = ''; foreach ($this->_joins as $join) { $additional_joins .= ' ' . $join->compile($db); } $compiled = parent::compile($db) . $additional_joins; $this->_on = $original_on; $this->_using = $original_using; $this->_table = $original_table; return $compiled; }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'model' => Jam::field('polymorphic'))); }
public static function initialize(Jam_Meta $meta) { $meta->table('vocabularies')->name_key('name'); $meta->behaviors(array('paranoid' => Jam::behavior('paranoid', array()))); $meta->associations(array('terms' => Jam::association('hasmany', array('inverse_of' => 'vocabulary')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s', 'label' => "Last edited")))); }
public function get_user() { if ($this->enabled() and $this->logged_in()) { $user = Jam::find_or_build($this->_user_model, array($this->_service_field => $this->service_uid())); $user->_is_new = TRUE; $data = $this->service_user_info(); if (!$user->loaded()) { if (isset($data['email'])) { $user = Jam::find_or_build($this->_user_model, array('email' => $data['email'])); if ($user->loaded()) { $user->_is_new = FALSE; } } if (!$user->loaded() and Arr::get($this->_config, 'create_user')) { $user = $this->build_user($data, TRUE); } if (!$user) { throw new Auth_Exception_Service('Service :service user with service uid :id does not exist and faild to create', array(':service' => $this->type(), ':id' => $this->service_uid())); } $user->set($this->_service_field, $this->service_uid()); $user->save(); } elseif (Arr::get($this->_config, 'update_user')) { $user->_is_new = FALSE; $user->load_service_values($this, $data, FALSE); $user->save(); } else { $user->_is_new = FALSE; } return $user; } return FALSE; }
public function test_constructor() { $select = Jam_Query_Builder_Select::factory('test_author'); $this->assertInstanceOf('Jam_Query_Builder_Select', $select); $this->assertEquals(Jam::meta('test_author'), $select->meta()); $this->assertEquals('SELECT `test_authors`.* FROM `test_authors`', (string) $select); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // All fields are aliased to different columns $meta->fields(array('id' => Jam::field('primary', array('column' => 'id-alias')), 'name' => Jam::field('string', array('column' => 'name-alias')), 'description' => Jam::field('string', array('column' => 'description-alias')))); }
/** * @covers Model_Purchase_Item_Promotion::initialize */ public function test_initialize() { $meta = Jam::meta('purchase_item_promotion'); $this->assertSame('purchase_items', $meta->table()); $this->assertTrue($meta->field('is_payable')->default); $this->assertTrue($meta->field('is_discount')->default); }
public function test_deep() { $blog = Jam::find_or_create('test_blog', array('id' => 10, 'name' => 'created blog')); $author = Jam::build('test_author')->load_fields(array('id' => 4, 'name' => 'Joe', 'test_posts' => array(array('id' => 1, 'name' => 'hardware', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 2, 'name' => 'cat2')), 'test_blog' => array('id' => 2, 'name' => 'loaded')), array('id' => 2, 'name' => 'software', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 3, 'name' => 'cat3')), 'test_blog' => 10)))); $post = Jam::build('test_post')->load_fields(array('id' => 3, 'name' => 'administration')); $post2 = Jam::build('test_post', array('name' => 'unsaved')); $author->test_posts->add($post)->add($post2); $serialized_data = serialize($author); $unserialized = unserialize($serialized_data); $this->assertNotSame($author, $unserialized); $this->assertTrue($unserialized->loaded()); $this->assertEquals($author->as_array(), $unserialized->as_array()); $this->assertCount(4, $unserialized->test_posts); $this->assertTrue($unserialized->test_posts[0]->loaded()); $this->assertEquals($author->test_posts[0]->as_array(), $unserialized->test_posts[0]->as_array()); $this->assertNotNull($unserialized->test_posts[0]->test_blog); $this->assertTrue($unserialized->test_posts[0]->test_blog->loaded()); $this->assertEquals($author->test_posts[0]->test_blog->as_array(), $unserialized->test_posts[0]->test_blog->as_array()); $this->assertNotNull($unserialized->test_posts[1]->test_blog); $this->assertTrue($unserialized->test_posts[1]->test_blog->loaded()); $this->assertEquals($author->test_posts[1]->test_blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array()); $this->assertEquals($blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array()); $this->assertTrue($unserialized->test_posts[1]->loaded()); $this->assertEquals($author->test_posts[1]->as_array(), $unserialized->test_posts[1]->as_array()); $this->assertTrue($unserialized->test_posts[2]->loaded()); $this->assertEquals($author->test_posts[2]->as_array(), $unserialized->test_posts[2]->as_array()); $this->assertFalse($unserialized->test_posts[3]->loaded()); $this->assertEquals($author->test_posts[3]->as_array(), $unserialized->test_posts[3]->as_array()); $blog->delete(); }
/** * @covers Jam_Validator_Rule_Currency */ public function test_validate() { $product = Jam::build('product', array('currency' => 'NNN')); $this->assertFalse($product->check()); $product->currency = 'USD'; $this->assertTrue($product->check()); }
public function model_call_update_token(Jam_Model $model, Jam_Event_Data $data) { do { $model->{$this->_field} = $this->new_token(); } while (Jam::all($model->meta()->model())->where($this->_field, '=', $model->{$this->_field})->count_all() > 0); $data->return = $model; }
protected function _load_token($token) { if (!$token) { return NULL; } return is_object($token) ? $token : Jam::all('test_user_token')->valid_token($token)->first(); }
public function __construct($id = NULL) { parent::__construct($id); if (mt_rand(1, 100) === 1) { Jam::delete($this)->expired()->execute(); } }
/** * @covers Jam_Behavior_Shippable_Purchase::model_before_check */ public function test_model_before_check() { $purchase = Jam::build('purchase'); $this->assertTrue($purchase->shipping_same_as_billing); $purchase->shipping_required = TRUE; $purchase->check(); $this->assertEquals(array('billing_address' => array('present' => array())), $purchase->errors()->as_array()); $purchase->billing_address = array('first_name' => 10); $purchase->check(); $this->assertEquals(array('billing_address' => array('association' => array(':errors' => $purchase->billing_address->errors()))), $purchase->errors()->as_array()); $purchase = Jam::build('purchase'); $purchase->shipping_required = TRUE; $purchase->shipping_same_as_billing = FALSE; $purchase->check(); $this->assertEquals(array('shipping_address' => array('present' => array())), $purchase->errors()->as_array()); $purchase->shipping_address = array('first_name' => 10); $purchase->check(); $this->assertEquals(array('shipping_address' => array('association' => array(':errors' => $purchase->shipping_address->errors()))), $purchase->errors()->as_array()); $purchase = $this->getMock('Model_Purchase', array('items_count'), array('purchase')); $purchase->expects($this->exactly(2))->method('items_count')->with($this->equalTo(array('can_ship' => FALSE)))->will($this->onConsecutiveCalls(0, 1)); $purchase->billing_address = array('first_name' => 'asd', 'last_name' => 'asd', 'email' => '*****@*****.**', 'line1' => 'asd', 'country' => 'France', 'city' => 'Paris', 'zip' => '123', 'phone' => '123'); $purchase->shipping_required = TRUE; $purchase->check(); $this->assertEquals(array(), $purchase->errors()->as_array()); $purchase->check(); $this->assertEquals(array('brand_purchases' => array('cannot_ship' => array())), $purchase->errors()->as_array()); }
public function test_render() { $collection = Jam::all('test_city')->load_fields(array(array('id' => 1, 'name' => 'London', 'population' => 10), array('id' => 2, 'name' => 'New York', 'population' => 15))); $name = new Tart_Column(); $name->sort(FALSE); $population = new Tart_Column(); $population->sort(FALSE); $columns = array('name' => $name, 'population' => $population); $table = new Tart_Table($collection, $columns); $table->selected(FALSE); $expected = <<<HTML <table class="table table-striped table-hover"> <thead> <th>Name</th> <th>Population</th> </thead> <tbody> <tr class="test_city-1"> <td>London</td> <td>10</td> </tr> <tr class="test_city-2"> <td>New York</td> <td>15</td> </tr> </tbody> </table> HTML; $this->assertSame($expected, $table->render()); $table->selected(array(1)); $expected = <<<HTML_SELECTED <table class="table table-striped table-hover"> <thead> <th width="10"> <input type="checkbox" name="all" value="1"/> </th> <th>Name</th> <th>Population</th> </thead> <tbody> <tr class="test_city-1"> <td> <input type="checkbox" name="id[]" value="1" checked="1"/> </td> <td>London</td> <td>10</td> </tr> <tr class="test_city-2"> <td> <input type="checkbox" name="id[]" value="2"/> </td> <td>New York</td> <td>15</td> </tr> </tbody> </table> HTML_SELECTED; $this->assertSame($expected, $table->render()); }
public function get_jam() { if (Request::ajax()) { $jam = Input::get('jam'); $waktu = Jam::find($jam); echo $waktu->dari_jam . "|" . $waktu->sampai_jam; } }
public function test_build_user_token() { $user = Jam::build('test_user')->load_fields(array('id' => '1', 'email' => '*****@*****.**', 'username' => 'admin')); $now = time(); $token = $user->build_user_token(); $this->assertGreaterThan($now, $token->expires); $this->assertNotNull($token->token); }
/** * Casts the returned value to a given type. * * @param mixed $value * @return mixed */ public function set(Jam_Validated $model, $value, $is_changed) { if (isset($this->cast)) { // Cast the value using the field type defined in 'cast' $value = Jam::field($this->cast)->set($value); } return $value; }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_holder' => Jam::association('belongsto', array('polymorphic' => TRUE)), 'test_copyright' => Jam::association('hasone', array('dependent' => Jam_Association::ERASE)), 'test_copyrights' => Jam::association('hasmany', array('dependent' => Jam_Association::ERASE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('delete_file' => TRUE)))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_image' => Jam::association('belongsto', array('dependent' => Jam_Association::DELETE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_post' => Jam::association('hasone', array('inverse_of' => 'test_author')), 'test_posts' => Jam::association('hasmany'), 'test_blogs_owned' => Jam::association('hasmany', array('foreign_model' => 'test_blog', 'foreign_key' => 'test_owner_id')), 'test_categories' => Jam::association('hasmany'), 'test_position' => Jam::association('belongsto'), 'permission' => Jam::association('belongsto', array('foreign_model' => 'test_position', 'foreign_key' => 'test_position_id')))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'password' => Jam::field('password'), 'email' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_owner' => Jam::association('belongsto', array('foreign_model' => 'test_author', 'foreign_key' => 'test_owner_id')), 'test_featured_category' => Jam::association('hasone', array('foreign_model' => 'test_category')), 'test_posts' => Jam::association('hasmany', array('inverse_of' => 'test_blog', 'count_cache' => TRUE, 'dependent' => Jam_Association::DELETE)), 'test_categories' => Jam::association('hasmany', array('required' => TRUE, 'inverse_of' => 'test_blog')), 'test_tags' => Jam::association('manytomany', array()))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'url' => Jam::field('weblink'), 'test_posts_count' => Jam::field('integer'))); }
public function test_constructor() { $select = Jam_Query_Builder_Update::factory('test_author'); $select->value('name', 'Test'); $this->assertInstanceOf('Jam_Query_Builder_Update', $select); $this->assertEquals(Jam::meta('test_author'), $select->meta()); $this->assertEquals('UPDATE `test_authors` SET `name` = \'Test\'', (string) $select); }
public function test_default_price() { $variation = Jam::build('variation', array('price' => 10)); $price = $variation->price; $this->assertEquals('GBP', $price->currency()); $this->assertEquals(2, $price->ceil_on_convert()); $this->assertSame(OpenBuildings\Monetary\Monetary::instance(), $price->monetary()); }
public static function initialize(Jam_Meta $meta) { $meta->table('terms')->name_key('name'); $meta->behaviors(array('nested' => Jam::behavior('Nested'), 'sluggable' => Jam::behavior('Sluggable', array('uses_primary_key' => FALSE, 'auto_save' => FALSE, 'unique' => TRUE)))); $meta->associations(array('vocabulary' => Jam::association('belongsto', array('inverse_of' => 'terms')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')))); $meta->validator('name', array('present' => TRUE)); }