/** * Test inserting a field after another in a set. */ public function testInsertAfterFieldToSet() { $fields = new FieldList(); /* 3 fields are added to the set */ $fields->push(new TextField('Country')); $fields->push(new TextField('Email')); $fields->push(new TextField('FirstName')); /* We now have 3 fields in the set */ $this->assertEquals(3, $fields->Count()); /* A field called Title is inserted after the Country field */ $fields->insertAfter(new TextField('Title'), 'Country'); /* The field we just added actually exists in the set */ $this->assertNotNull($fields->dataFieldByName('Title')); /* We now have 4 fields in the FieldList */ $this->assertEquals(4, $fields->Count()); /* The position of the Title field should be at number 2 */ $this->assertEquals('Title', $fields[1]->getName()); /* Test arguments are accepted in either order */ $fields->insertAfter('FirstName', new TextField('Surname')); /* The field we just added actually exists in the set */ $this->assertNotNull($fields->dataFieldByName('Surname')); /* We now have 5 fields in the set */ $this->assertEquals(5, $fields->Count()); /* The position of the Surname field is at number 5 */ $this->assertEquals('Surname', $fields[4]->getName()); }