给定一段文本，创建一个函数，该函数计算文本中每个单词的出现次数，并返回一个字典，其中键为单词，值为出现次数。

text = "this is a test. this is only a test."
# TODO: create function to count word frequency
```python
def word_frequency(text):
    words = text.split()
    frequency = {}
    for word in words:
        if word in frequency:
            frequency[word] += 1
        else:
            frequency[word] = 1
    return frequency

text = "this is a test. this is only a test."
print(word_frequency(text))
# Output: {'this': 2, 'is': 2, 'a': 2, 'test.': 2, 'only': 1}
```