public function testAddOptions() { $colorRed = $this->createOption('Red', 'red', 'color', 'colorRed'); $sizeXl = $this->createOption('Extra Large', 'XL', 'size', 'sizeXl'); $og = new OptionGroup(); // DO NOT SET THE NAME IN THE GROUP! $og->addOption($colorRed); $this->assertEquals('color', $og->getType(), 'if the type is not set, the name should be set to the type of the Option'); $this->assertSame($colorRed, $og->getOption('colorRed'), 'the option value should be found by its value'); $this->assertSame($colorRed, $og->getOptionByDisplay('Red'), 'the name of the option node should be set to the value'); $noTypeGreen = $this->createOption('Green', 'green', null, 'colorGreen'); $og->addOption($noTypeGreen); $this->assertSame($noTypeGreen, $og->getOption('colorGreen'), 'if the type is not set, the option should be added to the group'); $this->assertSame('color', $noTypeGreen->getType(), 'if the type is not set, type option type should be set to the name of the group'); $this->setExpectedException('UnexpectedValueException', 'All OptionsNodes in this type must be color'); $og->addOption($sizeXl); $noTypeBlue = $this->createOption('Blue', 'blue', null, 'colorBlue'); $og = new OptionGroup(); // DO NOT SET THE NAME IN THE GROUP! $this->setExpectedException('UnexpectedValueException', 'The OptionGroup must have the name set or the Option must have the group type set'); $og->addOption($noTypeBlue); }