Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
6.8KB

  1. <?php
  2. require_once 'vendor/autoload.php';
  3. class Cops extends Sauce\Sausage\WebDriverTestCase
  4. {
  5. public static $browsers = array(
  6. // run FF15 on Windows 8 on Sauce
  7. array(
  8. 'browserName' => 'firefox',
  9. 'desiredCapabilities' => array(
  10. 'version' => '28',
  11. 'platform' => 'Windows 8.1',
  12. )
  13. ),
  14. // run IE9 on Windows 7 on Sauce
  15. array(
  16. 'browserName' => 'internet explorer',
  17. 'desiredCapabilities' => array(
  18. 'version' => '9',
  19. 'platform' => 'Windows 7',
  20. )
  21. ),
  22. // run IE10 on Windows 8 on Sauce
  23. array(
  24. 'browserName' => 'internet explorer',
  25. 'desiredCapabilities' => array(
  26. 'version' => '11',
  27. 'platform' => 'Windows 8.1',
  28. )
  29. ),
  30. // run Safari 7 on Maverick on Sauce
  31. array(
  32. 'browserName' => 'safari',
  33. 'desiredCapabilities' => array(
  34. 'version' => '7',
  35. 'platform' => 'OS X 10.9',
  36. )
  37. ),
  38. // run Mobile Safari on iOS
  39. array(
  40. 'browserName' => 'iphone',
  41. 'desiredCapabilities' => array(
  42. 'app' => 'safari',
  43. 'device' => 'iPhone 6',
  44. 'version' => '9.2',
  45. 'platform' => 'OS X 10.10',
  46. )
  47. ),
  48. // run Mobile Browser on Android
  49. array(
  50. 'browserName' => 'Android',
  51. 'desiredCapabilities' => array(
  52. 'version' => '5.1',
  53. 'platform' => 'Linux',
  54. )
  55. ),
  56. // run Chrome on Linux on Sauce
  57. array(
  58. 'browserName' => 'chrome',
  59. 'desiredCapabilities' => array(
  60. 'version' => '33',
  61. 'platform' => 'Linux'
  62. )
  63. )
  64. // run Chrome locally
  65. //array(
  66. //'browserName' => 'chrome',
  67. //'local' => true,
  68. //'sessionStrategy' => 'shared'
  69. //)
  70. );
  71. public function setUp()
  72. {
  73. if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
  74. $caps = $this->getDesiredCapabilities();
  75. $caps['build'] = getenv ("TRAVIS_JOB_NUMBER");
  76. $caps['tunnel-identifier'] = getenv ("TRAVIS_JOB_NUMBER");
  77. $caps['idle-timeout'] = "180";
  78. $this->setDesiredCapabilities($caps);
  79. }
  80. parent::setUp ();
  81. }
  82. public function setUpPage()
  83. {
  84. if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
  85. $this->url('http://127.0.0.1:8888/index.php');
  86. } else {
  87. $this->url('http://cops-demo.slucas.fr/index.php');
  88. }
  89. $driver = $this;
  90. $title_test = function($value) use ($driver) {
  91. $text = $driver->byXPath('//h1')->text ();
  92. return $text == $value;
  93. };
  94. $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
  95. }
  96. public function string_to_ascii($string)
  97. {
  98. $ascii = NULL;
  99. for ($i = 0; $i < strlen($string); $i++)
  100. {
  101. $ascii += ord($string[$i]);
  102. }
  103. return mb_detect_encoding($string) . "X" . $ascii;
  104. }
  105. // public function testTitle()
  106. // {
  107. // $driver = $this;
  108. // $title_test = function($value) use ($driver) {
  109. // $text = $driver->byXPath('//h1')->text ();
  110. // return $text == $value;
  111. // };
  112. // $author = $this->byXPath ('//h2[contains(text(), "Authors")]');
  113. // $author->click ();
  114. // $this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]);
  115. // }
  116. // public function testCog()
  117. // {
  118. // $cog = $this->byId ("searchImage");
  119. // $search = $this->byName ("query");
  120. // $this->assertFalse ($search->displayed ());
  121. // $cog->click ();
  122. // $search = $this->byName ("query");
  123. // $this->assertTrue ($search->displayed ());
  124. // }
  125. public function testFilter()
  126. {
  127. $driver = $this;
  128. $title_test = function($value) use ($driver) {
  129. $text = $driver->byXPath('//h1')->text ();
  130. return $text == $value;
  131. };
  132. $element_present = function ($using, $id) use ($driver) {
  133. $elements = $driver->elements ($driver->using($using)->value($id));
  134. return count($elements) == 1;
  135. };
  136. // Click on the wrench to enable tag filtering
  137. $this->spinWait ("", $element_present, [ "class name", 'icon-wrench']);
  138. $this->byClassName ("icon-wrench")->click ();
  139. $this->spinWait ("", $element_present, [ "id", "html_tag_filter"]);
  140. $this->byId ("html_tag_filter")->click ();
  141. // Go back to home screen
  142. $this->byClassName ("icon-home")->click ();
  143. $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
  144. // Go on the recent page
  145. $author = $this->byXPath ('//h2[contains(text(), "Recent")]');
  146. $author->click ();
  147. $this->spinAssert("Recent book title", $title_test, [ "RECENT ADDITIONS" ]);
  148. // Click on the cog to show tag filters
  149. $cog = $this->byId ("searchImage");
  150. $cog->click ();
  151. sleep (1);
  152. // Filter on War & Military
  153. $filter = $this->byXPath ('//li[contains(text(), "War")]');
  154. $filter->click ();
  155. sleep (1);
  156. // Only one book
  157. $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]'));
  158. $this->assertEquals (1, count($filtered));
  159. $filter->click ();
  160. sleep (1);
  161. // 13 book
  162. $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]'));
  163. $this->assertEquals (14, count($filtered));
  164. }
  165. public function normalSearch ($src, $out)
  166. {
  167. $driver = $this;
  168. $title_test = function($value) use ($driver) {
  169. $text = $driver->byXPath('//h1')->text ();
  170. return $text == $value;
  171. };
  172. // Click on the cog to show the search
  173. $cog = $this->byId ("searchImage");
  174. $cog->click ();
  175. //sleep (1);
  176. // Focus the input and type
  177. $this->waitUntil(function () {
  178. if ($this->byName ("query")) {
  179. return true;
  180. }
  181. return null;
  182. }, 1000);
  183. $queryInput = $this->byName ("query");
  184. $queryInput->click ();
  185. $queryInput->value ($src);
  186. $queryInput->submit ();
  187. $this->spinAssert("Home Title", $title_test, [ "SEARCH RESULT FOR *" . $out . "*" ]);
  188. }
  189. public function testSearchWithoutAccentuatedCharacters()
  190. {
  191. $this->normalSearch ("ali", "ALI");
  192. }
  193. public function testSearchWithAccentuatedCharacters()
  194. {
  195. if ($this->getBrowser() == "Android") {
  196. $this->markTestIncomplete();
  197. return;
  198. }
  199. $this->normalSearch ("é", "É");
  200. }
  201. }