forked from hne3/EECS-393-Nutrition-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoodDatabaseTest.php
194 lines (177 loc) · 7.02 KB
/
FoodDatabaseTest.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
use Illuminate\Support\Facades\Artisan;
use App\Food;
use App\Nutrient;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class FoodDatabaseTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
use WithoutMiddleware;
protected static $dbSeeded = false;
protected static function setupDB()
{
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
}
public function setUp()
{
parent::setUp();
if(!static::$dbSeeded){
static::setupDB();
static::$dbSeeded = true;
}
}
public function spawnUser(){
$user = factory(App\User::class)->create();
$user->name = 'FoodHistoryTest';
$user->email = '[email protected]';
$user->password = 'password';
$user->gender = 'female';
$ageTemp = new \Carbon\Carbon();
$ageTemp->addYear(-23);
$user->bdate = $ageTemp->toDateString();
$user->daily_calories = 1500;
return $user;
}
public function testFoodSearchRedirect()
{
$user = $this->spawnUser();
$this->actingAs($user)
->visit('/home')
->see('Snackr')
->click('Food Search')
->seePageIs('/food');
}
public function testFoodSearchByPrefix()
{
//?q=Apple&method=search
$this->visit('/food')
->type('Apple', 'q')
->select('search', 'method')
->press('Go!')
->seePageStartsWith('/food')
->seePageHasGetParameters(['q'=>'Apple','method'=>'search'])
->see('Apple juice, canned or bottled, unsweetened, with added ascorbic acid');
}
public function testFoodSearchByName()
{
$this->visit('/food')
->type('Apple juice, canned or bottled, unsweetened, with added ascorbic acid', 'q')
->select('name', 'method')
->press('Go!')
->seePageStartsWith('/food')
->seePageHasGetParameters(['q'=>'Apple%20juice%2C%20canned%20or%20bottled%2C%20unsweetened%2C%20with%20added%20ascorbic%20acid','method'=>'name'])
->see('Apple juice, canned or bottled, unsweetened, with added ascorbic acid');
}
public function testFoodSearchBySimilarName()
{
$this->visit('/food')
->type('Apple', 'q')
->select('similar', 'method')
->select('1', 'restrictions')
->select('cal', 'sort')
->press('Go!')
->seePageStartsWith('/food')
->seePageHasGetParameters(['q'=>'Apple','method'=>'similar'])
->see('Apples, raw, gala, with skin');
}
// UNIT TESTS FOR FOOD DATABASE
public function testFoodCreation()
{
$food = Food::GetNameSimilarTo("apple")[0];
$this->assertEquals("Babyfood, apples, dices, toddler", $food->getName());
$this->assertEquals("3115", $food->getId());
// 51 calories
$this->assertEquals("51", $food->getCalories());
// 0.0 caffiene
$this->assertEquals("0.0", $food->getCaffeine());
$this->assertEquals("mg", $food->getCaffieneUnits());
// 0.02 mg copper
$this->assertEquals("0.02", $food->getCopper());
$this->assertEquals("mg", $food->getCopperUnits());
// 0.1 g fat
$this->assertEquals("0.1", $food->getFat());
$this->assertEquals("g", $food->getFatUnits());
// 0.9 g fiber
$this->assertEquals("0.9", $food->getFiber());
$this->assertEquals("g", $food->getFiberUnits());
// 0.2 mg iron
$this->assertEquals("0.2", $food->getIron());
$this->assertEquals("mg", $food->getIronUnits());
// 6.0 mg magnesium
$this->assertEquals("6.0", $food->getMagnesium());
$this->assertEquals("mg", $food->getMagnesiumUnits());
// 13.0 mg phosphorus
$this->assertEquals("13.0", $food->getPhosphorus());
$this->assertEquals("mg", $food->getPhosphorusUnits());
// 0.04 mg manganese
$this->assertEquals("0.04", $food->getManganese());
$this->assertEquals("mg", $food->getManganeseUnits());
// 0 mg potassium
$this->assertEquals("0", $food->getPotassium());
$this->assertEquals("mg", $food->getPotassiumUnits());
// 0 mg sodium
$this->assertEquals("0", $food->getSodium());
$this->assertEquals("mg", $food->getSodiumUnits());
// 10.0 calcium
$this->assertEquals("10.0", $food->getCalcium());
// Calcium unit: mg
$this->assertEquals("mg", $food->getCalciumUnits());
// 12.1 carbohydrates
$this->assertEquals("12.1", $food->getCarbohydrates());
// Carbohydrates units: g
$this->assertEquals("g", $food->getCarbohydratesUnits());
// 0.2g protein
$this->assertEquals("0.2", $food->getProtein());
$this->assertEquals("g", $food->getProteinUnits());
// 10.83g sugar
$this->assertEquals("10.83", $food->getSugar());
$this->assertEquals("g", $food->getSugarUnits());
// 2.0 ug vitamin a
$this->assertEquals("2.0", $food->getVitaminA());
$this->assertEquals("ug", $food->getVitaminAUnits());
// 0.0 ug vitamin b12
$this->assertEquals("0.0", $food->getVitaminB12());
$this->assertEquals("ug", $food->getVitaminB12Units());
// 0.05 mg vitamin b6
$this->assertEquals("0.05", $food->getVitaminB6());
$this->assertEquals("mg", $food->getVitaminB6Units());
// 31.3 mg vitamin c
$this->assertEquals("31.3", $food->getVitaminC());
$this->assertEquals("mg", $food->getVitaminCUnits());
// 0.0 ug vitamin d
$this->assertEquals("0.0", $food->getVitaminD());
$this->assertEquals("ug", $food->getVitaminDUnits());
// 0.23 mg vitamin e
$this->assertEquals("0.23", $food->getVitaminE());
$this->assertEquals("mg", $food->getVitaminEUnits());
// 0.6 ug vitamin k
$this->assertEquals("0.6", $food->getVitaminK());
$this->assertEquals("ug", $food->getVitaminKUnits());
// 0.04 mg zinc
$this->assertEquals("0.04", $food->getZinc());
$this->assertEquals("mg", $food->getZincUnits());
}
public function testNutrients()
{
$protein = Nutrient::Protein();
$carbohydrates = Nutrient::Carbohydrates();
$fat = Nutrient::Fat();
// Test units, ID, and all foods with protein
$this->assertEquals("g", $protein->getUnits());
$this->assertEquals("203", $protein->getID());
$this->assertEquals("6607", count($protein->getFoods()));
// Test units, ID, and all foods with carbs
$this->assertEquals("g", $carbohydrates->getUnits());
$this->assertEquals("205", $carbohydrates->getID());
$this->assertEquals("5940", count($carbohydrates->getFoods()));
// Test units, ID, and all foods with fat
$this->assertEquals("g", $fat->getUnits());
$this->assertEquals("204", $fat->getID());
$this->assertEquals("6595", count($fat->getFoods()));
}
}