aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/selenium/catalog/SagePayDirectTest.php
blob: 8e65fe690dfb8a9bbe5c7a7db275ccbade5207d6 (plain)
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
<?php

class CatalogSagePayExpressTest extends OpenCartSeleniumTest {

	private $moduleInstalled = false;

	/**
	 * @before
	 */
	protected function before() {
		$this->setBrowser('firefox');
		$this->setBrowserUrl(HTTP_SERVER);
	}

	public function setUpPage() {
		if (!$this->moduleInstalled) {
			$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
			$db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order");
			$db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order_transaction");
			$db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order_recurring");
			$db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_card");

			$this->url("admin/");

			$this->byCssSelector('input[name="username"]')->click();
			$this->keys(ADMIN_USERNAME);

			$this->byCssSelector('input[name="password"]')->click();
			$this->keys(ADMIN_PASSWORD);

			$this->byCssSelector('button[type="submit"]')->click();

			$this->moduleInstalled = true;

			$this->waitToLoad('Dashboard');

			// Installing the payment module
			$this->clickOnElement('button-menu');

			$this->waitToAppearAndClick('#extension a');
			$this->waitToAppearAndClick('#extension li:nth-child(5) a');

			$this->waitToLoad('Payment');

			$i = 1;

			for ( ; ; $i++) {
				$element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");

				if ($element->text() == 'SagePay Direct') {
					break;
				}
			}

			$this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
			$this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");

			$this->waitToLoad('SagePay Direct');

			$this->clickOnElement('sagepay_direct_vendor');
			$this->keys(SAGEPAY_DIRECT_VENDOR);

			$this->byCssSelector('#input-test option[value="test"]')->click();

			$this->clickOnElement('sagepay_direct_total');
			$this->keys('0.00');

			// Adding the Cart Layout
			$this->waitToAppearAndClick('#system a');
			$this->waitToAppearAndClick('#system li:nth-child(2) a');
			$this->waitToAppearAndClick('#system li:nth-child(2) li:first-child a');

			$this->waitToLoad('Layouts');
			$this->byCssSelector('.fa-plus-circle')->click();

			$this->waitToAppearAndClick('#input-name');
			$this->keys('Cart');

			$this->byCssSelector('.fa-plus-circle')->click();

			$this->byCssSelector('input[name="layout_route[0][route]"]')->click();
			$this->keys('checkout/cart');

			$this->byCssSelector('.fa-check-circle')->click();

			// Installing the payment button
			$this->waitToAppearAndClick('#extension a');
			$this->waitToAppearAndClick('#extension li:nth-child(3) a');

			$i = 1;

			for ( ; ; $i++) {
				$element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");

				if ($element->text() == 'PayPal Express Checkout button') {
					break;
				}
			}

			$this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
			$this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");

			$this->waitToLoad('PayPal Express Checkout button');
			$this->byCssSelector('.fa-plus-circle')->click();

			for ($i = 1; ; $i++) {
				$element = $this->byCssSelector("select[name=\"pp_button_module[0][layout_id]\"] option:nth-child($i)");

				if ($element->text() == 'Cart') {
					$element->click();
					break;
				}
			}

			$this->byCssSelector('button[title="Save"]')->click();
		}
	}

	public function testOneProduct() {
		$this->url('index.php?route=product/product&product_id=43');
		$this->clickOnElement('button-cart');

		$this->url('index.php?route=checkout/cart');
		$this->waitToLoad('Shopping Cart');

		$this->byCssSelector('.pp-express-button')->click();

		$this->waitToLoad("Pay with a PayPal", 30000);

		$this->clickOnElement('login_email');
		$this->keys(PP_EXPRESS_USERNAME);

		$this->clickOnElement('login_password');
		$this->keys(PP_EXPRESS_PASSWORD);

		$this->clickOnElement('submitLogin');

		$this->waitToLoad("Review your information", 30000);

		$this->clickOnElement('continue_abovefold');

		$this->waitToLoad("Confirm order", 30000);

		$this->byCssSelector('.pull-right .btn-primary')->click();

		$this->waitToLoad("Your order has been placed!");

		$element = $this->byCssSelector('#content h1');

		$this->assertEquals('Your order has been placed!', $element->text());
	}

}