forked from matt-daneshvar/laravel-survey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CastingTest.php
51 lines (39 loc) · 1.26 KB
/
CastingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace MattDaneshvar\Survey\Tests;
use MattDaneshvar\Survey\Models\Entry;
use MattDaneshvar\Survey\Models\Survey;
class CastingTest extends TestCase
{
/** @test */
public function strings_are_stored_as_they_are()
{
$survey = create(Survey::class, [
'settings' => ['accept-guest-entries' => true],
]);
$q1 = $survey->questions()->create([
'content' => 'Name of your cat?',
'type' => 'text',
]);
$entry = (new Entry)
->for($survey)
->fromArray([$q1->id => 'Jafar']);
$entry->push();
$this->assertEquals('Jafar', $entry->answers->first()->value);
}
/** @test */
public function array_values_are_stored_as_readable_comma_separated_values()
{
$survey = create(Survey::class, [
'settings' => ['accept-guest-entries' => true],
]);
$q1 = $survey->questions()->create([
'content' => 'Your favorite cat colors?',
'type' => 'multiselect',
]);
$entry = (new Entry)
->for($survey)
->fromArray([$q1->id => ['Orange', 'Black']]);
$entry->push();
$this->assertEquals('Orange, Black', $entry->answers->first()->value);
}
}