'one', 2 => 'two', 3 => 'three');
$f = new LookupField('test', 'test', $source);
$f->setValue(null);
$this->assertEquals(
'(none)',
$f->Field()
);
}
public function testStringValueWithNumericArraySource() {
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
$f = new LookupField('test', 'test', $source);
$f->setValue(1);
$this->assertEquals(
'one',
$f->Field()
);
}
public function testUnknownStringValueWithNumericArraySource() {
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
$f = new LookupField('test', 'test', $source);
$f->setValue('w00t');
$f->dontEscape = true; // simulates CMSMain->compareversions()
$this->assertEquals(
'w00t',
$f->Field()
);
}
public function testArrayValueWithAssociativeArraySource() {
// Array values (= multiple selections) might be set e.g. from ListboxField
$source = array('one' => 'one val', 'two' => 'two val', 'three' => 'three val');
$f = new LookupField('test', 'test', $source);
$f->setValue(array('one','two'));
$this->assertEquals('one val, two val'
. '',
$f->Field()
);
}
public function testArrayValueWithNumericArraySource() {
// Array values (= multiple selections) might be set e.g. from ListboxField
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
$f = new LookupField('test', 'test', $source);
$f->setValue(array(1,2));
$this->assertEquals(
'one, two',
$f->Field()
);
}
public function testArrayValueWithSqlMapSource() {
$member1 = $this->objFromFixture('Member', 'member1');
$member2 = $this->objFromFixture('Member', 'member2');
$member3 = $this->objFromFixture('Member', 'member3');
$source = DataObject::get('Member');
$f = new LookupField('test', 'test', $source->map());
$f->setValue(array($member1->ID, $member2->ID));
$this->assertEquals(
sprintf(
'member1, member2'
. '',
$member1->ID,
$member2->ID
),
$f->Field()
);
}
}