forked from matt-daneshvar/laravel-survey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SurveyTest.php
105 lines (78 loc) · 2.56 KB
/
SurveyTest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace MattDaneshvar\Survey\Tests;
use MattDaneshvar\Survey\Models\Question;
use MattDaneshvar\Survey\Models\Survey;
class SurveyTest extends TestCase
{
/** @test */
public function it_has_a_name()
{
$survey = create(Survey::class, ['name' => 'Cat Survey']);
$this->assertEquals('Cat Survey', $survey->name);
}
/** @test */
public function it_may_have_settings()
{
$survey = new Survey([
'name' => 'Cat Survey',
'settings' => ['accept-guest-entries' => true],
]);
$this->assertCount(1, $survey->settings);
}
/** @test */
public function it_can_add_questions()
{
$survey = create(Survey::class);
$survey->questions()->create(['content' => 'How many cats do you have?']);
$this->assertEquals(1, $survey->questions->count());
}
/** @test */
public function it_can_add_multiple_questions_at_once()
{
$survey = create(Survey::class);
$questions = factory(Question::class, 2)->create();
$survey->questions()->saveMany($questions);
$this->assertEquals(2, $survey->questions->count());
}
/** @test */
public function it_combines_the_rules_of_its_questions()
{
$q1 = create(Question::class, ['rules' => ['numeric', 'min:0']]);
$q2 = create(Question::class, ['rules' => ['date']]);
$survey = create(Survey::class);
$survey->questions()->saveMany([$q1, $q2]);
$this->assertArrayHasKey($q1->key, $survey->rules);
}
/** @test */
public function it_has_a_limit_per_participant()
{
$survey = new Survey([]);
$this->assertEquals(1, $survey->limitPerParticipant());
$anotherSurvey = new Survey([
'settings' => ['limit-per-participant' => 5],
]);
$this->assertEquals(5, $anotherSurvey->limitPerParticipant());
}
/** @test */
public function it_may_have_no_limits_per_participant()
{
$survey = new Survey([
'settings' => ['limit-per-participant' => -1],
]);
$this->assertNull($survey->limitPerParticipant());
}
/** @test */
public function it_does_not_accept_guest_entries_by_default()
{
$survey = new Survey([]);
$this->assertFalse($survey->acceptsGuestEntries());
}
/** @test */
public function it_may_accept_guest_entries()
{
$survey = new Survey([
'settings' => ['accept-guest-entries' => true],
]);
$this->assertTrue($survey->acceptsGuestEntries());
}
}