2013-11-28 12:45:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'vendor/autoload.php';
|
|
|
|
|
2013-11-29 11:47:25 +02:00
|
|
|
class Cops extends Sauce\Sausage\WebDriverTestCase
|
2013-11-28 12:45:54 +02:00
|
|
|
{
|
|
|
|
public static $browsers = array(
|
2013-11-28 19:25:19 +02:00
|
|
|
// run FF15 on Windows 8 on Sauce
|
|
|
|
array(
|
|
|
|
'browserName' => 'firefox',
|
|
|
|
'desiredCapabilities' => array(
|
2014-04-12 13:40:46 +03:00
|
|
|
'version' => '28',
|
2014-01-03 15:23:33 +02:00
|
|
|
'platform' => 'Windows 8.1',
|
|
|
|
)
|
2014-01-04 10:58:47 +02:00
|
|
|
),
|
2013-11-28 19:25:19 +02:00
|
|
|
// run IE9 on Windows 7 on Sauce
|
|
|
|
array(
|
|
|
|
'browserName' => 'internet explorer',
|
|
|
|
'desiredCapabilities' => array(
|
|
|
|
'version' => '9',
|
|
|
|
'platform' => 'Windows 7',
|
|
|
|
)
|
|
|
|
),
|
2013-11-28 19:01:30 +02:00
|
|
|
// run IE10 on Windows 8 on Sauce
|
|
|
|
array(
|
|
|
|
'browserName' => 'internet explorer',
|
|
|
|
'desiredCapabilities' => array(
|
2014-01-03 15:23:33 +02:00
|
|
|
'version' => '11',
|
|
|
|
'platform' => 'Windows 8.1',
|
2013-11-28 19:01:30 +02:00
|
|
|
)
|
2013-11-28 19:25:19 +02:00
|
|
|
),
|
2014-01-03 15:23:33 +02:00
|
|
|
// run Safari 7 on Maverick on Sauce
|
|
|
|
array(
|
|
|
|
'browserName' => 'safari',
|
|
|
|
'desiredCapabilities' => array(
|
|
|
|
'version' => '7',
|
|
|
|
'platform' => 'OS X 10.9',
|
|
|
|
)
|
|
|
|
),
|
2013-11-28 19:25:19 +02:00
|
|
|
// run Mobile Safari on iOS
|
|
|
|
array(
|
|
|
|
'browserName' => '',
|
|
|
|
'desiredCapabilities' => array(
|
|
|
|
'app' => 'safari',
|
|
|
|
'device' => 'iPhone Simulator',
|
2014-04-12 13:40:46 +03:00
|
|
|
'version' => '7.1',
|
|
|
|
'platform' => 'Mac 10.9',
|
2013-11-28 19:25:19 +02:00
|
|
|
)
|
|
|
|
),
|
2014-01-03 15:23:33 +02:00
|
|
|
// run Mobile Browser on Android
|
|
|
|
array(
|
|
|
|
'browserName' => 'Android',
|
|
|
|
'desiredCapabilities' => array(
|
2014-04-12 13:40:46 +03:00
|
|
|
'version' => '4.3',
|
2014-01-03 15:23:33 +02:00
|
|
|
'platform' => 'Linux',
|
|
|
|
)
|
|
|
|
),
|
2013-11-28 12:45:54 +02:00
|
|
|
// run Chrome on Linux on Sauce
|
2013-11-28 19:25:19 +02:00
|
|
|
array(
|
|
|
|
'browserName' => 'chrome',
|
|
|
|
'desiredCapabilities' => array(
|
2014-04-12 13:40:46 +03:00
|
|
|
'version' => '33',
|
2013-11-28 19:25:19 +02:00
|
|
|
'platform' => 'Linux'
|
|
|
|
)
|
|
|
|
)
|
2014-01-04 00:29:50 +02:00
|
|
|
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-28 12:45:54 +02:00
|
|
|
// run Chrome locally
|
|
|
|
//array(
|
|
|
|
//'browserName' => 'chrome',
|
|
|
|
//'local' => true,
|
|
|
|
//'sessionStrategy' => 'shared'
|
|
|
|
//)
|
|
|
|
);
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2013-11-29 11:47:25 +02:00
|
|
|
if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
|
|
|
|
$caps = $this->getDesiredCapabilities();
|
|
|
|
$caps['build'] = getenv ("TRAVIS_JOB_NUMBER");
|
2014-01-04 00:29:50 +02:00
|
|
|
$caps['idle-timeout'] = "180";
|
2013-11-29 11:47:25 +02:00
|
|
|
$this->setDesiredCapabilities($caps);
|
|
|
|
}
|
|
|
|
parent::setUp ();
|
2013-11-28 12:45:54 +02:00
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-28 12:45:54 +02:00
|
|
|
public function setUpPage()
|
|
|
|
{
|
2013-11-29 11:47:25 +02:00
|
|
|
if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
|
|
|
|
$this->url('http://127.0.0.1:8888/index.php');
|
|
|
|
} else {
|
|
|
|
$this->url('http://cops-demo.slucas.fr/index.php');
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-29 16:35:12 +02:00
|
|
|
$driver = $this;
|
|
|
|
$title_test = function($value) use ($driver) {
|
|
|
|
$text = $driver->byXPath('//h1')->text ();
|
|
|
|
return $text == $value;
|
|
|
|
};
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-29 16:35:12 +02:00
|
|
|
$this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
|
2013-11-28 12:45:54 +02:00
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-28 12:45:54 +02:00
|
|
|
public function string_to_ascii($string)
|
|
|
|
{
|
|
|
|
$ascii = NULL;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-28 12:45:54 +02:00
|
|
|
for ($i = 0; $i < strlen($string); $i++)
|
|
|
|
{
|
|
|
|
$ascii += ord($string[$i]);
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-11-28 12:45:54 +02:00
|
|
|
return mb_detect_encoding($string) . "X" . $ascii;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// public function testTitle()
|
|
|
|
// {
|
|
|
|
// $driver = $this;
|
|
|
|
// $title_test = function($value) use ($driver) {
|
|
|
|
// $text = $driver->byXPath('//h1')->text ();
|
|
|
|
// return $text == $value;
|
|
|
|
// };
|
2013-11-28 12:45:54 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// $author = $this->byXPath ('//h2[contains(text(), "Authors")]');
|
|
|
|
// $author->click ();
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// $this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]);
|
|
|
|
// }
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// public function testCog()
|
|
|
|
// {
|
|
|
|
// $cog = $this->byId ("searchImage");
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// $search = $this->byName ("query");
|
|
|
|
// $this->assertFalse ($search->displayed ());
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// $cog->click ();
|
2013-12-05 11:52:51 +02:00
|
|
|
|
2013-12-13 09:53:28 +02:00
|
|
|
// $search = $this->byName ("query");
|
|
|
|
// $this->assertTrue ($search->displayed ());
|
|
|
|
// }
|
2013-12-12 22:53:45 +02:00
|
|
|
|
2013-12-12 22:01:07 +02:00
|
|
|
public function testFilter()
|
|
|
|
{
|
2013-12-12 22:53:45 +02:00
|
|
|
$driver = $this;
|
|
|
|
$title_test = function($value) use ($driver) {
|
|
|
|
$text = $driver->byXPath('//h1')->text ();
|
|
|
|
return $text == $value;
|
|
|
|
};
|
|
|
|
|
2014-04-12 11:51:26 +03:00
|
|
|
$element_present = function ($using, $id) use ($driver) {
|
|
|
|
$elements = $driver->elements ($driver->using($using)->value($id));
|
|
|
|
return count($elements) == 1;
|
|
|
|
};
|
|
|
|
|
2013-12-12 22:01:07 +02:00
|
|
|
// Click on the wrench to enable tag filtering
|
|
|
|
$this->byClassName ("icon-wrench")->click ();
|
2013-12-12 22:53:45 +02:00
|
|
|
|
2014-04-12 11:51:26 +03:00
|
|
|
$this->spinWait ("", $element_present, [ "id", "html_tag_filter"]);
|
2013-12-12 22:01:07 +02:00
|
|
|
$this->byId ("html_tag_filter")->click ();
|
2013-12-12 22:53:45 +02:00
|
|
|
|
2013-12-12 22:01:07 +02:00
|
|
|
// Go back to home screen
|
|
|
|
$this->byClassName ("icon-home")->click ();
|
|
|
|
|
2013-12-12 22:53:45 +02:00
|
|
|
$this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
|
2013-12-12 22:01:07 +02:00
|
|
|
|
|
|
|
// Go on the recent page
|
|
|
|
$author = $this->byXPath ('//h2[contains(text(), "Recent")]');
|
|
|
|
$author->click ();
|
|
|
|
|
|
|
|
$this->spinAssert("Recent book title", $title_test, [ "RECENT ADDITIONS" ]);
|
|
|
|
|
|
|
|
// Click on the cog to show tag filters
|
|
|
|
$cog = $this->byId ("searchImage");
|
|
|
|
$cog->click ();
|
|
|
|
sleep (1);
|
|
|
|
// Filter on War & Military
|
|
|
|
$filter = $this->byXPath ('//li[contains(text(), "War")]');
|
|
|
|
$filter->click ();
|
|
|
|
sleep (1);
|
|
|
|
// Only one book
|
|
|
|
$filtered = $this->elements ($this->using('css selector')->value('*[class="books"]'));
|
|
|
|
$this->assertEquals (1, count($filtered));
|
|
|
|
$filter->click ();
|
|
|
|
sleep (1);
|
|
|
|
// 13 book
|
|
|
|
$filtered = $this->elements ($this->using('css selector')->value('*[class="books"]'));
|
|
|
|
$this->assertEquals (13, count($filtered));
|
|
|
|
}
|
2014-04-11 09:48:57 +03:00
|
|
|
|
2014-04-10 22:52:04 +03:00
|
|
|
public function normalSearch ($src, $out)
|
|
|
|
{
|
|
|
|
$driver = $this;
|
|
|
|
$title_test = function($value) use ($driver) {
|
|
|
|
$text = $driver->byXPath('//h1')->text ();
|
|
|
|
return $text == $value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Click on the cog to show the search
|
|
|
|
$cog = $this->byId ("searchImage");
|
|
|
|
$cog->click ();
|
|
|
|
sleep (1);
|
|
|
|
|
|
|
|
// Focus the input and type
|
|
|
|
$queryInput = $this->byName ("query");
|
|
|
|
$queryInput->click ();
|
2014-04-11 09:48:57 +03:00
|
|
|
$queryInput->value ($src);
|
2014-04-10 22:52:04 +03:00
|
|
|
$queryInput->submit ();
|
|
|
|
|
|
|
|
$this->spinAssert("Home Title", $title_test, [ "SEARCH RESULT FOR *" . $out . "*" ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchWithoutAccentuatedCharacters()
|
|
|
|
{
|
|
|
|
$this->normalSearch ("ali", "ALI");
|
2014-04-11 09:48:57 +03:00
|
|
|
}
|
2014-04-10 22:52:04 +03:00
|
|
|
|
|
|
|
public function testSearchWithAccentuatedCharacters()
|
|
|
|
{
|
|
|
|
$this->normalSearch ("é", "É");
|
|
|
|
}
|
2013-11-28 12:45:54 +02:00
|
|
|
}
|