Services_Openstreetmap icon indicating copy to clipboard operation
Services_Openstreetmap copied to clipboard

tests/TagsWithSameValueTest.php not adressing the problem

Open Maturion opened this issue 8 years ago • 1 comments

Sorry if the title of this issue sounds a bit harsh. I'm not a native English speaker, so no offense intended. ;)

I have recently submitted issue #12 and you created the TagsWithSameValueTest.php test class for verifying that. I can indeed confirm that my original issue does not occur in this test class.

Puzzled by this, I tried around a bit and found out that my original problem does not occur when creating a new node (This is what's being done in TagsWithSameValueTest.php). It only happens when you are editing an existing node.

The cause of this behaviour is the following: array_diff($this->getTags(), $set) does compare $this->getTags() and $set.

Values are assigned to $set this way:

$set = array();
            for ($i = 0; $i < $tags->length; $i++) {
                $key = $tags->item($i)->getAttribute('k');
                $val = $tags->item($i)->getAttribute('v');
                $set[$key] = $val;
            }

$set contains the values of an object before your new ChangeSet is applied. Hence when you create a new object, $set is empty and array_diff($this->getTags(), $set) will save two tags with the same value. However, when you're editing an existing object, $set is not empty, and the output of array_diff will indeed not contain two tags with the same value.

I didn't submit a pull request because I'm not sure wether this problem can be replicated without changing "real" data on the OSM database.

Maturion avatar Mar 01 '17 18:03 Maturion

No offence taken - please do provide a test/example that does demonstrate the problem conclusively though!

kenguest avatar Mar 06 '17 22:03 kenguest