@@ 61-93 (lines=33) @@ | ||
58 | $this->assertEquals([], $field->getStoreAsArray()); |
|
59 | } |
|
60 | ||
61 | public function testFirst() |
|
62 | { |
|
63 | $field = $this->sut; |
|
64 | ||
65 | // Test: Source data is simple JSON array |
|
66 | // Return type: Array |
|
67 | $field->setReturnType('array'); |
|
68 | $field->setValue($this->getFixture('array')); |
|
69 | $this->assertInternalType('array', $field->first()); |
|
70 | $this->assertCount(1, $field->first()); |
|
71 | $this->assertEquals([0 => 'great wall'], $field->first()); |
|
72 | ||
73 | // Test: Source data is simple JSON array |
|
74 | // Return type: JSON |
|
75 | $field->setReturnType('json'); |
|
76 | $field->setValue($this->getFixture('array')); |
|
77 | $this->assertInternalType('string', $field->first()); |
|
78 | $this->assertEquals('["great wall"]', $field->first()); |
|
79 | ||
80 | // Test: Source data is simple JSON array |
|
81 | // Return type: SilverStripe |
|
82 | $field->setReturnType('silverstripe'); |
|
83 | $field->setValue($this->getFixture('array')); |
|
84 | $this->assertInternalType('array', $field->first()); |
|
85 | $this->assertInstanceOf('\SilverStripe\ORM\FieldType\DBVarchar', $field->first()[0]); |
|
86 | $this->assertEquals('great wall', $field->first()[0]->getValue()); |
|
87 | ||
88 | // Test: Empty |
|
89 | $field->setReturnType('array'); |
|
90 | $field->setValue(''); |
|
91 | $this->assertInternalType('array', $field->first()); |
|
92 | $this->assertCount(0, $field->first()); |
|
93 | } |
|
94 | ||
95 | public function testLast() |
|
96 | { |
|
@@ 95-127 (lines=33) @@ | ||
92 | $this->assertCount(0, $field->first()); |
|
93 | } |
|
94 | ||
95 | public function testLast() |
|
96 | { |
|
97 | $field = $this->sut; |
|
98 | ||
99 | // Test: Source data is simple JSON array |
|
100 | // Return type: Array |
|
101 | $field->setReturnType('array'); |
|
102 | $field->setValue($this->getFixture('array')); |
|
103 | $this->assertInternalType('array', $field->last()); |
|
104 | $this->assertCount(1, $field->last()); |
|
105 | $this->assertEquals([6 => 33.3333], $field->last()); |
|
106 | ||
107 | // Test: Source data is simple JSON array |
|
108 | // Return type: JSON |
|
109 | $field->setReturnType('json'); |
|
110 | $field->setValue($this->getFixture('array')); |
|
111 | $this->assertInternalType('string', $field->last()); |
|
112 | $this->assertEquals('{"6":33.3333}', $field->last()); |
|
113 | ||
114 | // Test: Source data is simple JSON array |
|
115 | // Return type: SilverStripe |
|
116 | $field->setReturnType('silverstripe'); |
|
117 | $field->setValue($this->getFixture('array')); |
|
118 | $this->assertInternalType('array', $field->last()); |
|
119 | $this->assertInstanceOf('\SilverStripe\ORM\FieldType\DBFloat', $field->last()[6]); |
|
120 | $this->assertEquals(33.3333, $field->last()[6]->getValue()); |
|
121 | ||
122 | // Test: Empty |
|
123 | $field->setReturnType('array'); |
|
124 | $field->setValue(''); |
|
125 | $this->assertInternalType('array', $field->last()); |
|
126 | $this->assertCount(0, $field->last()); |
|
127 | } |
|
128 | ||
129 | public function testNth() |
|
130 | { |