예제 #1
0
 public function testUpdatesResourceType()
 {
     $unchanged = new AttributeValue(1, 'value');
     $toChange = new AttributeValue(2, 'value');
     $toAdd = new AttributeValue(3, 'value');
     $id = 11;
     $type = new ResourceType($id, 'name', 'desc');
     $type->WithAttribute($unchanged);
     $type->WithAttribute(new AttributeValue(100, 'should be removed'));
     $type->WithAttribute(new AttributeValue(2, 'new value'));
     $attributes = array($unchanged, $toChange, $toAdd);
     $type->ChangeAttributes($attributes);
     $this->repository->UpdateResourceType($type);
     $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $id, CustomAttributeCategory::RESOURCE_TYPE);
     $removeOldCommand = new RemoveAttributeValueCommand(100, $id);
     $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $id);
     $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $id, CustomAttributeCategory::RESOURCE_TYPE);
     $expectedCommand = new UpdateResourceTypeCommand($type->Id(), $type->Name(), $type->Description());
     $this->assertEquals($expectedCommand, $this->db->_Commands[0]);
     $this->assertEquals($removeOldCommand, $this->db->_Commands[1]);
     $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted");
     $this->assertEquals($addUpdated, $this->db->_Commands[3]);
     $this->assertEquals($addNewCommand, $this->db->_Commands[4]);
 }