forked from oroinc/orocommerce
/
AjaxLineItemControllerTest.php
143 lines (122 loc) · 4.6 KB
/
AjaxLineItemControllerTest.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
<?php
namespace OroB2B\Bundle\ShoppingListBundle\Tests\Functional\Controller;
use Symfony\Component\DomCrawler\Form;
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
use OroB2B\Bundle\ProductBundle\Entity\Product;
use OroB2B\Bundle\ProductBundle\Entity\ProductUnit;
use OroB2B\Bundle\ShoppingListBundle\Entity\LineItem;
use OroB2B\Bundle\ShoppingListBundle\Entity\ShoppingList;
use OroB2B\Bundle\ShoppingListBundle\Tests\Functional\DataFixtures\LoadShoppingLists;
/**
* @dbIsolation
*/
class AjaxLineItemControllerTest extends WebTestCase
{
protected function setUp()
{
$this->initClient([], $this->generateBasicAuthHeader());
$this->loadFixtures(
[
'OroB2B\Bundle\ShoppingListBundle\Tests\Functional\DataFixtures\LoadShoppingListLineItems',
]
);
}
public function testCreate()
{
/** @var ShoppingList $shoppingList */
$shoppingList = $this->getReference(LoadShoppingLists::SHOPPING_LIST_1);
/** @var ProductUnit $unit */
$unit = $this->getReference('product_unit.bottle');
/** @var Product $product2 */
$product = $this->getReference('product.2');
$crawler = $this->client->request(
'GET',
$this->getUrl(
'orob2b_shopping_list_line_item_create_widget',
[
'shoppingListId' => $shoppingList->getId(),
'_widgetContainer' => 'dialog',
'_wid' => 'test-uuid'
]
)
);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$form = $crawler->selectButton('Save')->form(
[
'orob2b_shopping_list_line_item[product]' => $product->getId(),
'orob2b_shopping_list_line_item[quantity]' => 22.2,
'orob2b_shopping_list_line_item[notes]' => 'test_notes',
'orob2b_shopping_list_line_item[unit]' => $unit->getCode()
]
);
$this->assertSaved($form);
}
public function testCreateDuplicate()
{
/** @var LineItem $lineItem */
$lineItem = $this->getReference('shopping_list_line_item.1');
$crawler = $this->client->request(
'GET',
$this->getUrl(
'orob2b_shopping_list_line_item_create_widget',
[
'shoppingListId' => $lineItem->getShoppingList()->getId(),
'_widgetContainer' => 'dialog',
'_wid' => 'test-uuid'
]
)
);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$form = $crawler->selectButton('Save')->form(
[
'orob2b_shopping_list_line_item[product]' => $lineItem->getProduct()->getId(),
'orob2b_shopping_list_line_item[quantity]' => 100,
'orob2b_shopping_list_line_item[notes]' => 'test_notes',
'orob2b_shopping_list_line_item[unit]' => $lineItem->getUnit()->getCode()
]
);
$this->assertSaved($form);
}
public function testUpdate()
{
/** @var LineItem $lineItem */
$lineItem = $this->getReference('shopping_list_line_item.1');
/** @var ProductUnit $unit */
$unit = $this->getReference('product_unit.liter');
$crawler = $this->client->request(
'GET',
$this->getUrl(
'orob2b_shopping_list_line_item_update_widget',
[
'id' => $lineItem->getId(),
'_widgetContainer' => 'dialog',
'_wid' => 'test-uuid'
]
)
);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$form = $crawler->selectButton('Save')->form(
[
'orob2b_shopping_list_line_item[quantity]' => 33.3,
'orob2b_shopping_list_line_item[unit]' => $unit->getCode(),
'orob2b_shopping_list_line_item[notes]' => 'Updated test notes',
]
);
$this->assertSaved($form);
}
/**
* @param Form $form
*/
protected function assertSaved(Form $form)
{
$this->client->followRedirects(true);
$crawler = $this->client->submit($form);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$html = $crawler->html();
$this->assertRegExp('/"savedId":\s*\d+/i', $html);
}
}