本文整理汇总了PHP中Jam::build方法的典型用法代码示例。如果您正苦于以下问题:PHP Jam::build方法的具体用法?PHP Jam::build怎么用?PHP Jam::build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jam
的用法示例。
在下文中一共展示了Jam::build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_available_for_purchase
/**
* @covers Model_Collection_Promo_Code::available_for_purchase
*/
public function test_available_for_purchase()
{
$purchase = Jam::build('purchase', array('id' => 10));
$sql = (string) Jam::all('promo_code')->available_for_purchase($purchase);
$expected_sql = "SELECT `promo_codes`.* FROM `promo_codes` LEFT JOIN `purchases` ON (`purchases`.`promo_code_id` = `promo_codes`.`id`) WHERE (`promo_codes`.`allow_multiple` = '1' OR `purchases`.`id` IS NULL OR `purchases`.`id` = 10)";
$this->assertEquals($expected_sql, $sql);
}
示例2: test_empty_value
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);
}
示例3: test_change_password
/**
* @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);
}
示例4: test_deep
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();
}
示例5: duplicate
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;
}
示例6: create_session
/**
* Build a new Model_Visitor object, save it to the session and trigger model.create_session event
* @return Model_Visitor
*/
public static function create_session()
{
$visitor = Jam::build('visitor');
static::session($visitor);
$visitor->meta()->events()->trigger('model.create_session', $visitor);
return $visitor;
}
示例7: test_model_before_check
/**
* @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' => 'test@email.com', '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());
}
示例8: test_validate
/**
* @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());
}
示例9: test_default_price
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());
}
示例10: test_build_user_token
public function test_build_user_token()
{
$user = Jam::build('test_user')->load_fields(array('id' => '1', 'email' => 'admin@example.com', 'username' => 'admin'));
$now = time();
$token = $user->build_user_token();
$this->assertGreaterThan($now, $token->expires);
$this->assertNotNull($token->token);
}
示例11: test_applies_to
/**
* @covers Model_Promotion_Promocode::applies_to
*/
public function test_applies_to()
{
$brand_purchase = Jam::build('brand_purchase');
$promotion = $this->getMock('Model_Promotion_Promocode', array('matches_brand_purchase_promo_code'), array('promotion'));
$promotion->expects($this->exactly(2))->method('matches_brand_purchase_promo_code')->with($this->identicalTo($brand_purchase))->will($this->onConsecutiveCalls(TRUE, FALSE));
$this->assertTrue($promotion->applies_to($brand_purchase));
$this->assertFalse($promotion->applies_to($brand_purchase));
}
示例12: buildModelArray
public function buildModelArray($model_name, array $params)
{
$items = array();
foreach ($params as $group_params) {
$items[] = Jam::build($model_name, $group_params);
}
return $items;
}
示例13: test_validate
/**
* @covers Jam_Validator_Rule_Price::validate
*/
public function test_validate()
{
$product = Jam::build('product', array('price' => -1));
$this->assertFalse($product->check());
$product->price = 0;
$this->assertTrue($product->check());
$product = Jam::build('product', array('price' => 12));
$this->assertTrue($product->check());
}
示例14: test_format
public function test_format()
{
$field = new Jam_Field_Range();
$field->format = ':min - :max days';
$model = Jam::build('test_position');
$range = $field->get($model, '10|20', FALSE);
$this->assertInstanceOf('Jam_Range', $range);
$this->assertEquals('10 - 20 days', $range->humanize());
}
示例15: update_brand_purchase_items
/**
* If the promotion applies to the brand_purchase - add a purchase_item for this promotion, otherwise remove the associated purchase item
* @param Model_Brand_Purchase $brand_purchase
*/
public function update_brand_purchase_items($applies, &$items)
{
$promo_item = Jam::build('purchase_item_promotion', array('reference' => $this));
$items = array_filter($items, function ($item) use($promo_item) {
return !$item->is_same($promo_item);
});
if ($applies) {
$items[] = $promo_item;
}
}