예제 #1
0
 /**
  * @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
0
 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
0
 /**
  * @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
0
 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
0
 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
0
 /**
  * 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
0
 /**
  * @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());
 }
예제 #8
0
 /**
  * @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
0
 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
0
 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);
 }
예제 #11
0
 /**
  * @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
0
 public function buildModelArray($model_name, array $params)
 {
     $items = array();
     foreach ($params as $group_params) {
         $items[] = Jam::build($model_name, $group_params);
     }
     return $items;
 }
예제 #13
0
 /**
  * @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
0
 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
0
 /**
  * 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;
     }
 }
예제 #16
0
파일: CountTest.php 프로젝트: Konro1/pms
 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $options, $error, $is_valid)
 {
     $element = Jam::build('test_element');
     Jam::validator_rule('count', $options)->validate($element, 'count', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'count', $error);
     } else {
         $this->assertHasError($element, 'count', $error);
     }
 }
예제 #17
0
 public function test_actions()
 {
     $city = Jam::build('test_city')->load_fields(array('id' => 1, 'name' => 'First Name', 'population' => 300));
     $actions = new Tart_Column_Actions(function ($item) {
         return HTML::anchor(Tart::uri($item), 'Edit') . '<span> info </span>';
     });
     $rendered = $actions->item($city)->render();
     $this->assertSelectEquals('a[href="' . Tart::uri($city) . '"]', 'Edit', TRUE, $rendered);
     $this->assertSelectEquals('span', 'info', TRUE, $rendered);
 }
예제 #18
0
파일: UploadTest.php 프로젝트: Konro1/pms
 public function test_save_and_delete()
 {
     $image = Jam::build('test_image');
     $image->file = Upload_Util::combine($this->test_local, 'source', 'logo.gif');
     $image->save();
     $file = $image->file->file();
     $this->assertFileExists($file);
     $image->delete();
     $this->assertFileNotExists($file);
 }
예제 #19
0
 public function test_check()
 {
     $child = Jam::build('test_closurelist')->load_fields(array('id' => 1));
     $parent = $this->getMockBuilder('Model_Test_Closurelist')->setMethods(array('check'))->setConstructorArgs(array('test_closurelist'))->getMock();
     $parent->load_fields(array('id' => 2));
     $parent->expects($this->once())->method('check')->will($this->returnValue(TRUE));
     $parent->name = 'new name';
     $child->parent = $parent;
     $this->association->model_after_check($child, new Jam_Event_Data(array()), array('parent' => $parent));
 }
예제 #20
0
 public function action_new()
 {
     $session = Jam::build('tart_session', $this->request->post());
     $session->login_on_check = TRUE;
     if ($this->request->method() === Request::POST and $session->check()) {
         $this->redirect(Session::instance()->get_once('requested_url', Tart::uri()));
     } else {
         $this->template->content = View::factory('tart/session/new', array('session' => $session));
     }
 }
예제 #21
0
파일: AcceptedTest.php 프로젝트: Konro1/pms
 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $accept, $is_valid)
 {
     $element = Jam::build('test_element');
     Jam::validator_rule('accepted', array('accept' => $accept))->validate($element, 'name', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'name', 'accepted');
     } else {
         $this->assertHasError($element, 'name', 'accepted');
     }
 }
예제 #22
0
 public function form($form = NULL)
 {
     if ($form !== NULL) {
         $this->_form = $form;
         return $this;
     }
     if (!$this->_form) {
         $this->_form = Jam::form(Jam::build('tart_filter', $this->data()), 'tart_filter');
     }
     return $this->_form;
 }
예제 #23
0
 public function test_inverse_of_with_serialize()
 {
     $test_blog = Jam::build('test_blog');
     $post1 = Jam::build('test_post');
     $test_blog->test_posts->add($post1);
     $test_blog = unserialize(serialize($test_blog));
     foreach ($test_blog->test_posts as $test_post) {
         $this->assertSame($test_blog, $test_post->test_blog);
     }
     $this->assertSame($test_blog, $test_blog->test_posts[0]->test_blog);
 }
예제 #24
0
 /**
  * @covers Model_Promotion_Promocode_Percent::price_for_purchase_item
  */
 public function test_price_for_purchase_item()
 {
     $monetary = new Monetary(new Source_Static());
     $total_price = new Jam_Price(12, 'GBP', $monetary);
     $brand_purchase = $this->getMock('Model_Brand_Purchase', array('total_price'), array('brand_purchase'));
     $brand_purchase->expects($this->once())->method('total_price')->with($this->equalTo('product'))->will($this->returnValue($total_price));
     $purchase_item = Jam::build('purchase_item_promotion', array('brand_purchase' => $brand_purchase));
     $promotion = Jam::build('promotion_promocode_percent', array('amount' => 0.12));
     $expected_price = new Jam_Price(-1.44, 'GBP', $monetary);
     $this->assertEquals($expected_price, $promotion->price_for_purchase_item($purchase_item));
 }
예제 #25
0
 /**
  * @dataProvider data_model_set_geoip_defaults
  * @covers ::set_geoip_defaults
  * @covers ::_set_new_country
  * @covers ::_set_new_currency
  */
 public function test_model_set_geoip_defaults($ip, $geoip_record, $options, $expected)
 {
     $this->env->backup_and_set(array('Request::$client_ip' => $ip));
     $visitor = Jam::build('visitor');
     $behavior = $this->getMock('Jam_Behavior_Visitor_Defaults', array('geoip_record'), array($options));
     $behavior->expects($this->once())->method('geoip_record')->with($this->equalTo($ip))->will($this->returnValue($geoip_record));
     $behavior->set_geoip_defaults($visitor);
     foreach ($expected as $field => $expected_value) {
         $this->assertEquals($expected_value, is_object($visitor->{$field}) ? $visitor->{$field}->name() : $visitor->{$field});
     }
 }
예제 #26
0
 public function build_user($data, $create = TRUE)
 {
     if ($this->logged_in() and !empty($data)) {
         $user = Jam::build($this->_user_model);
         if ($user->load_service_values($this, $data, $create) === FALSE) {
             return FALSE;
         }
         $user->roles->add(Jam::find($this->_role_model, 'login'));
         $user->set($this->_service_field, $this->service_uid());
         return $user;
     }
 }
예제 #27
0
 public function test_not_loaded()
 {
     $this->array->collection($this->collection);
     $this->array->parent(Jam::build('test_author'));
     $this->assertNull($this->array->content());
     $model = Jam::build('test_element')->load_fields(array('id' => 4, 'name' => 'four'));
     $this->array->add($model);
     $this->assertTrue($this->array->has($model));
     $this->array->parent($this->parent);
     $this->assertTrue($this->array->has($model));
     $this->assertEquals(array(4 => 'four', 1 => 'one', 3 => 'three'), $this->array->as_array('id', 'name'));
 }
예제 #28
0
 /**
  * @covers Jam_Behavior_Location_Parent::model_before_check
  */
 public function test_model_before_check()
 {
     $france = Jam::find('location', 'France');
     $address = Jam::build('address');
     $address->city = Jam::build('location', array('name' => 'Paris'));
     $address->country = $france;
     $address->check();
     $this->assertEquals($france, $address->city->parent);
     $address->save();
     $paris = Jam::find('location', 'Paris');
     $this->assertEquals($france, $paris->parent);
 }
예제 #29
0
 /**
  * @dataProvider data_model_before_check
  * @covers Jam_Behavior_Location_Auto::model_before_check
  */
 public function test_model_before_check($ip, $geoip_record, $expected)
 {
     $this->env->backup_and_set(array('Request::$client_ip' => $ip));
     $user = Jam::build('user');
     $behavior = $this->getMock('Jam_Behavior_Location_Auto', array('geoip_record'), array(array('locations' => array('city' => 'city', 'country' => 'country_name'))));
     $behavior->expects($this->once())->method('geoip_record')->with($this->equalTo($ip))->will($this->returnValue($geoip_record));
     $behavior->model_before_check($user);
     foreach ($expected as $attribute => $value) {
         $this->assertInstanceOf('Model_Location', $user->{$attribute});
         $this->assertEquals($value, $user->{$attribute}->name());
     }
 }
예제 #30
0
파일: FormatTest.php 프로젝트: Konro1/pms
 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $options, $error, $expected_attributes, $is_valid)
 {
     $element = Jam::build('test_element');
     $validator_rule = Jam::validator_rule('format', $options);
     $this->assertEquals($expected_attributes, $validator_rule->html5_validation());
     $validator_rule->validate($element, 'name', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'name', $error);
     } else {
         $this->assertHasError($element, 'name', $error);
     }
 }