Пример #1
0
 /**
  * Tests various aspects of a newly constructed field.
  *
  * @dataProvider provider_construction
  */
 public function test_construction(Jam_Field $field, $expected)
 {
     $model = Jam::build('test_position');
     // Ensure the following properties have been set
     foreach ($expected as $key => $value) {
         // NULL set is the expected value when allow_null is TRUE, skip it
         if ($key === 'null_set') {
             continue;
         }
         $this->assertSame($field->{$key}, $value, 'Field properties must match');
     }
     // Ensure that null values are handled properly
     if ($field->allow_null) {
         $this->assertSame($field->set($model, NULL, TRUE), NULL, 'Field must return NULL when given NULL since `allow_null` is TRUE');
     } else {
         $this->assertSame($field->set($model, NULL, TRUE), $expected['null_set'], 'Since `allow_null` is FALSE, field must return expected value when given NULL');
     }
     // Ensure convert_empty works
     if ($field->convert_empty) {
         // allow_null must be true if convert_empty is TRUE and empty_value is NULL
         if ($field->empty_value === NULL) {
             $this->assertTrue($field->allow_null, 'allow_null must be TRUE since convert_empty is TRUE');
         }
         // Test setting a few empty values
         foreach (array(NULL, FALSE, '', '0', 0) as $value) {
             $this->assertSame($field->set($model, $value, TRUE), $field->empty_value);
         }
     }
 }
Пример #2
0
 public function initialize(Jam_Meta $meta, $name)
 {
     parent::initialize($meta, $name);
     if (!in_array($this->method, Jam_Field_Serialized::$allowed)) {
         throw new Kohana_Exception("Unnown serialization method ':method', can use only :allowed", array(':method' => $this->method, ':allowed' => Jam_Field_Serialized::$allowed));
     }
 }
Пример #3
0
 /**
  * Ensures convert_empty is not set on the field, as it prevents FALSE
  * from ever being set on the field.
  *
  * @param   array  $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     // Ensure convert_empty is FALSE
     if ($this->convert_empty) {
         throw new Kohana_Exception(':class cannot have convert_empty set to TRUE', array(':class' => get_class($this)));
     }
 }
Пример #4
0
 /**
  * Ensures allow_null is not set to FALSE on the field, as it prevents
  * proper auto-incrementing of a primary key.
  *
  * @param  array  $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     // Ensure allow_null is TRUE
     if (!$this->allow_null) {
         throw new Kohana_Exception(':class cannot have allow_null set to FALSE', array(':class' => get_class($this)));
     }
 }
Пример #5
0
 /**
  * Sets the default to 0 if we have no format, or an empty string otherwise.
  *
  * @param  array  $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (!isset($options['default']) and !$this->allow_null) {
         // Having a implies saving we're format a string, so we want a proper default
         $this->default = $this->format ? '' : 0;
     }
     if ($this->timezone === NULL) {
         $this->timezone = Jam_Timezone::instance();
     }
 }