PageRenderTime 255ms CodeModel.GetById 62ms RepoModel.GetById 1ms app.codeStats 0ms

/.dev/tests/Web/Customer/ACustomer.php

https://github.com/istran/core
PHP | 164 lines | 102 code | 20 blank | 42 comment | 3 complexity | 73a8d8036a1cc9559f8831c4e339b2ce MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. // vim: set ts=4 sw=4 sts=4 et:
  3. /**
  4. * LiteCommerce
  5. *
  6. * NOTICE OF LICENSE
  7. *
  8. * This source file is subject to the Open Software License (OSL 3.0)
  9. * that is bundled with this package in the file LICENSE.txt.
  10. * It is also available through the world-wide-web at this URL:
  11. * http://opensource.org/licenses/osl-3.0.php
  12. * If you did not receive a copy of the license and are unable to
  13. * obtain it through the world-wide-web, please send an email
  14. * to licensing@litecommerce.com so we can send you a copy immediately.
  15. *
  16. * @category LiteCommerce
  17. * @package Tests
  18. * @subpackage Web
  19. * @author Creative Development LLC <info@cdev.ru>
  20. * @copyright Copyright (c) 2010 Creative Development LLC <info@cdev.ru>. All rights reserved
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * @version GIT: $Id: 5858a1309a655f77698eafa4751ea52b9a4eea6e $
  23. * @link http://www.litecommerce.com/
  24. * @see ____file_see____
  25. * @since 3.0.0
  26. */
  27. require_once __DIR__ . '/../AWeb.php';
  28. abstract class XLite_Web_Customer_ACustomer extends XLite_Web_AWeb
  29. {
  30. protected function logIn($user = 'master', $password = 'master')
  31. {
  32. $this->open('user');
  33. if ($this->isLoggedIn()) {
  34. $this->logOut(true);
  35. }
  36. $this->type("//input[@name='name' and @type='text']", $user);
  37. $this->type("//input[@name='password' and @type='password']", $password);
  38. $this->click("//input[@id='edit-submit']");
  39. $this->waitForPageToLoad(3000);
  40. }
  41. protected function logOut($pageIsOpened = false)
  42. {
  43. if (!$pageIsOpened) {
  44. $this->open('user');
  45. }
  46. if ($this->isLoggedIn()) {
  47. $this->click("//a[text()='Log out']");
  48. $this->waitForPageToLoad(3000);
  49. }
  50. }
  51. protected function isLoggedIn()
  52. {
  53. return $this->isElementPresent("//a[text()='Log out']");
  54. }
  55. protected function getActiveProduct()
  56. {
  57. $result = \XLite\Core\Database::getRepo('XLite\Model\Product')
  58. ->findOneByEnabled(true);
  59. $this->assertNotNull($result, 'getActiveProduct() returned null');
  60. return $result;
  61. }
  62. protected function getActiveProducts()
  63. {
  64. return \XLite\Core\Database::getRepo('XLite\Model\Product')
  65. ->findByEnabled(true);
  66. }
  67. /**
  68. * Returns ID of a LiteCommerce widget in the list of LC Connector blocks (returns only the first Drupal block displaying the widget)
  69. *
  70. * @param string $widgetClass Class of the widget to look for
  71. *
  72. * @return int
  73. * @access protected
  74. * @see ____func_see____
  75. * @since 3.0.0
  76. */
  77. protected function findWidgetID($widgetClass)
  78. {
  79. $pdo = $this->query('SELECT bid FROM drupal_block_custom WHERE lc_class = "'.addslashes($widgetClass).'" LIMIT 1');
  80. $r = $pdo->fetch();
  81. $pdo->closeCursor();
  82. $id = is_array($r) ? array_shift($r) : null;
  83. return $id;
  84. }
  85. /**
  86. * Returns ID of the widget implementing a product list
  87. *
  88. * @return int
  89. * @access protected
  90. * @since 3.0.0
  91. */
  92. protected function getWidgetId()
  93. {
  94. $id = $this->findWidgetID($this->widgetClass);
  95. $this->assertFalse(is_null($id), "Can't find the widget in the database");
  96. return $id;
  97. }
  98. /**
  99. * Sets a widget parameter
  100. *
  101. * @param int $widgetId ID of the widget in the list of LC Connector blocks
  102. * @param string $param Param name
  103. * @param string $value Param value
  104. *
  105. * @return void
  106. * @access protected
  107. * @see ____func_see____
  108. * @since 3.0.0
  109. */
  110. protected function setWidgetParam($widgetId, $param, $value)
  111. {
  112. $this->query("UPDATE drupal_block_lc_widget_settings SET value = '" . addslashes($value) . "' WHERE bid = '" . addslashes($widgetId) . "' AND name = '" . addslashes($param) . "'");
  113. }
  114. /**
  115. * Executes an SQL query
  116. *
  117. * @param string $query SQL query to execute
  118. *
  119. * @return Doctrine\DBAL\Driver\PDOStatement
  120. * @access protected
  121. * @see ____func_see____
  122. * @since 3.0.0
  123. */
  124. protected function query($query)
  125. {
  126. return \XLite\Core\Database::getEM()->getConnection()->executeQuery($query, array());
  127. }
  128. /**
  129. * Resets the browser and instantiates a new browser session
  130. *
  131. * @return void
  132. * @access protected
  133. * @since 3.0.0
  134. */
  135. protected function resetBrowser()
  136. {
  137. $this->stop();
  138. $this->start();
  139. }
  140. }