Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ShoppingCartTest.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  */
10 
11 use Goutte\Client;
12 
13 class ShoppingCartTest extends CTestCase {
14 
15  protected $client;
16 
17  public function setUp() {
18  parent::setUp();
19  $this->client = new Client();
20  }
21 
22  public function open($route, $params=array()) {
23  $url = explode('phpunit', Yii::app()->createUrl($route, $params));
24  if( empty($url[1]) ){
25  return TEST_BASE_URL.$route;
26  } else {
27  return TEST_BASE_URL.$url[1];
28  }
29  }
30 
31  public function testAddToCart()
32  {
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');
36 
37  $form = $crawler->filter('#item-1')->form();
38  $crawler = $this->client->submit($form);
39 
40  $this->assertEquals('1', trim($crawler->filter('.item_quantity')->text()), 'Error in adding item to cart');
41  }
42 
43  public function testCartProceed()
44  {
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');
48 
49  $form = $crawler->filter('#item-1')->form();
50  $crawler = $this->client->submit($form);
51 
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());
55 
56  $this->assertNotEmpty(trim($crawler->filter('.item_quantity')->text()), 'Cart is empty');
57 
58  $form = $crawler->filter('input[type=submit]')->form();
59  /* Submit 1st step */
60  $crawler = $this->client->submit($form);
61 
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';
74  /* Submit 2nd step */
75  $crawler = $this->client->submit($form);
76 
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();
80  /* Submit 3rd step */
81  $crawler = $this->client->submit($form);
82 
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');
86 
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');
89 
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');
92 
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');
95 
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');
98 
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');
101 
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');
104 
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');
107 
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');
110 
111  $form = $crawler->filter('#order-finish-form')->form();
112  $form['Order[verifyCode]'] = Yii::app()->params['captcha'];
113  /* Submit 4th step */
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');
117  }
118 }