public function testVFI() { // Given a simple definition, spec should be properly fleshed out $spec = VirtualFieldIndex::get_vfi_spec('Product'); $this->assertEquals('simple', $spec['Price2']['Type']); $this->assertEquals('all', $spec['Price2']['DependsOn']); $this->assertEquals('sellingPrice', $spec['Price2']['Source']); // Given a simple array definition, spec should be properly fleshed out $spec = VirtualFieldIndex::get_vfi_spec('Product'); $this->assertEquals('list', $spec['Category']['Type']); $this->assertEquals('all', $spec['Category']['DependsOn']); $this->assertEquals('Parent', $spec['Category']['Source'][0]); // build the vfi just in case VirtualFieldIndex::build('Product'); $p = $this->objFromFixture('Product', 'p4'); $cats = new ArrayList(array($this->objFromFixture('ProductCategory', 'c1'), $this->objFromFixture('ProductCategory', 'c2'), $this->objFromFixture('ProductCategory', 'c3'))); // vfi fields should be present and correct $this->assertTrue($p->hasField('VFI_Price'), 'Price index exists'); $this->assertEquals(5, $p->VFI_Price, 'Price is correct'); $this->assertTrue($p->hasField('VFI_Category'), 'Category index exists'); $this->assertEquals('>ProductCategory|' . implode('|', $cats->column('ID')) . '|', $p->VFI_Category, 'Category index is correct'); // vfi accessors work $this->assertEquals(5, $p->getVFI('Price'), 'Simple getter works'); $this->assertEquals($cats->toArray(), $p->getVFI('Category'), 'List getter works'); $this->assertNull($p->getVFI('NonExistentField'), 'Non existent field should return null'); }