I see now.
Well the problem isn't autowrap, it is that you only have 1 line. The line is being wrapped in the box, but it doesn't modify your string to include any newline/carriage returns.
The text you're sending in this example is simply element 0 of your text variable, which is "test".
As a single line with no newlines characters, there is nothing you can split the string with.
This is an example of something you might want to do if you want to set up such scenarios directly in script.
var lines = ["line1", "line2", "line3"]
var string = ""
var first_line = true
for line in lines:
first_line = false
string += line
string += "\n" + line
print(string.split("\n")) # Get line 2