17 public function setUp() {
19 $this->client =
new Client();
22 public function open($route, $params=array()) {
23 $url = explode(
'phpunit', Yii::app()->createUrl($route, $params));
25 return TEST_BASE_URL.$route;
27 return TEST_BASE_URL.$url[1];
31 public function testAddToCart()
33 $crawler = $this->client->request(
'GET', $this->open(
'widgetsTests/shoppingCart'));
34 preg_match(
'/Cart is empty/', $this->client->getResponse()->getContent(), $match);
35 $this->assertNotEmpty($match,
'Error in cart establishment');
37 $form = $crawler->filter(
'#item-1')->form();
38 $crawler = $this->client->submit($form);
40 $this->assertEquals(
'1', trim($crawler->filter(
'.item_quantity')->text()),
'Error in adding item to cart');
43 public function testCartProceed()
45 $crawler = $this->client->request(
'GET', $this->open(
'widgetsTests/shoppingCart'));
46 preg_match(
'/Cart is empty/', $this->client->getResponse()->getContent(), $match);
47 $this->assertNotEmpty($match,
'Error in cart establishment');
49 $form = $crawler->filter(
'#item-1')->form();
50 $crawler = $this->client->submit($form);
52 $this->assertEquals(
'1', trim($crawler->filter(
'.item_quantity')->text()),
'Error in adding item to cart');
53 $this->assertNotEmpty(trim($crawler->filter(
'.metanavlink')->text()),
'All items link does not exists');
54 $crawler = $this->client->click($crawler->filter(
'.all-items-link')->link());
56 $this->assertNotEmpty(trim($crawler->filter(
'.item_quantity')->text()),
'Cart is empty');
58 $form = $crawler->filter(
'input[type=submit]')->form();
60 $crawler = $this->client->submit($form);
62 $form = $crawler->filter(
'#tmp-user-form')->form();
63 $form[
'TmpUser[salutation]'] =
'Hi';
64 $form[
'TmpUser[firstname]'] =
'Bob';
65 $form[
'TmpUser[lastname]'] =
'Anderson';
66 $form[
'TmpUser[street]'] =
'Bob Avenue';
67 $form[
'TmpUser[zip_code]'] =
'12345';
68 $form[
'TmpUser[city]'] =
'Lux';
69 $form[
'TmpUser[country]'] =
'Lux';
70 $form[
'TmpUser[email]'] =
'bob@avenue.lux';
71 $form[
'TmpUser[company]'] =
'XXX';
72 $form[
'TmpUser[telephone]'] =
'123456789';
73 $form[
'TmpUser[birthday]'] =
'Jan 1, 1970';
75 $crawler = $this->client->submit($form);
77 preg_match(
'/Shipping Info/', $this->client->getResponse()->getContent(), $match);
78 $this->assertNotEmpty($match,
'Shipping Info is not found at 3rd step');
79 $form = $crawler->filter(
'#order-form')->form();
81 $crawler = $this->client->submit($form);
83 $this->assertNotEmpty(trim($crawler->filter(
'.item_quantity')->text()),
'Cart is empty');
84 preg_match(
'/<td class\=\"label\">Salutation<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Hi<\/td>/', $this->client->getResponse()->getContent(), $match);
85 $this->assertNotEmpty($match,
'Salutation is empty');
87 preg_match(
'/<td class\=\"label\">First\sName<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Bob<\/td>/', $this->client->getResponse()->getContent(), $match);
88 $this->assertNotEmpty($match,
'First Name is empty');
90 preg_match(
'/<td class\=\"label\">Last\sName<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Anderson<\/td>/', $this->client->getResponse()->getContent(), $match);
91 $this->assertNotEmpty($match,
'Last Name is empty');
93 preg_match(
'/<td class\=\"label\">Date\sOf\sBirth<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Jan\s1\,\s1970<\/td>/', $this->client->getResponse()->getContent(), $match);
94 $this->assertNotEmpty($match,
'Date Of Birth is empty');
96 preg_match(
'/<td class\=\"label\">Street<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Bob\sAvenue<\/td>/', $this->client->getResponse()->getContent(), $match);
97 $this->assertNotEmpty($match,
'Street is empty');
99 preg_match(
'/<td class\=\"label\">Zip\sCode<\/td>'.PHP_EOL.
'.*<td class\=\"value\">12345<\/td>/', $this->client->getResponse()->getContent(), $match);
100 $this->assertNotEmpty($match,
'Zip Code is empty');
102 preg_match(
'/<td class\=\"label\">City<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Lux<\/td>/', $this->client->getResponse()->getContent(), $match);
103 $this->assertNotEmpty($match,
'City is empty');
105 preg_match(
'/<td class\=\"label\">Country<\/td>'.PHP_EOL.
'.*<td class\=\"value\">Lux<\/td>/', $this->client->getResponse()->getContent(), $match);
106 $this->assertNotEmpty($match,
'Country is empty');
108 preg_match(
'/<td class\=\"label\">Email<\/td>'.PHP_EOL.
'.*<td class\=\"value\">bob\@avenue\.lux<\/td>/', $this->client->getResponse()->getContent(), $match);
109 $this->assertNotEmpty($match,
'Email is empty');
111 $form = $crawler->filter(
'#order-finish-form')->form();
112 $form[
'Order[verifyCode]'] = Yii::app()->params[
'captcha'];
114 $crawler = $this->client->submit($form);
115 preg_match(
'/Cart is empty/', $this->client->getResponse()->getContent(), $match);
116 $this->assertNotEmpty($match,
'Error of creating order');