init
This commit is contained in:
55
vendor/codeception/base/tests/unit/Codeception/Module/AMQPTest.php
vendored
Normal file
55
vendor/codeception/base/tests/unit/Codeception/Module/AMQPTest.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
|
||||
class AMQPTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $config = array(
|
||||
'host' => 'localhost',
|
||||
'username' => 'guest',
|
||||
'password' => 'guest',
|
||||
'port' => '5672',
|
||||
'vhost' => '/',
|
||||
'cleanup' => false,
|
||||
'queues' => array('queue1')
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\AMQP
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\AMQP(make_container());
|
||||
$this->module->_setConfig($this->config);
|
||||
$res = @stream_socket_client('tcp://localhost:5672');
|
||||
if ($res === false) {
|
||||
$this->markTestSkipped('AMQP is not running');
|
||||
}
|
||||
|
||||
$this->module->_initialize();
|
||||
$connection = $this->module->connection;
|
||||
$connection->channel()->queue_declare('queue1');
|
||||
}
|
||||
|
||||
public function testPushToQueue()
|
||||
{
|
||||
$this->module->pushToQueue('queue1', 'hello');
|
||||
$this->module->seeMessageInQueueContainsText('queue1', 'hello');
|
||||
}
|
||||
|
||||
public function testPushToExchange()
|
||||
{
|
||||
$queue = 'test-queue';
|
||||
$exchange = 'test-exchange';
|
||||
$topic = 'test.3';
|
||||
$message = 'test-message';
|
||||
|
||||
$this->module->declareExchange($exchange, 'topic', false, true, false);
|
||||
$this->module->declareQueue($queue, false, true, false, false);
|
||||
$this->module->bindQueueToExchange($queue, $exchange, 'test.#');
|
||||
|
||||
$this->module->pushToExchange($exchange, $message, $topic);
|
||||
$this->module->seeMessageInQueueContainsText($queue , $message);
|
||||
}
|
||||
}
|
||||
73
vendor/codeception/base/tests/unit/Codeception/Module/AssertsTest.php
vendored
Normal file
73
vendor/codeception/base/tests/unit/Codeception/Module/AssertsTest.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
class AssertsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testAsserts()
|
||||
{
|
||||
$module = new \Codeception\Module\Asserts(make_container());
|
||||
$module->assertEquals(1, 1);
|
||||
$module->assertContains(1, [1, 2]);
|
||||
$module->assertSame(1, 1);
|
||||
$module->assertNotSame(1, '1');
|
||||
$module->assertRegExp('/^[\d]$/', '1');
|
||||
$module->assertNotRegExp('/^[a-z]$/', '1');
|
||||
$module->assertStringStartsWith('fo', 'foo');
|
||||
$module->assertStringStartsNotWith('ba', 'foo');
|
||||
$module->assertEmpty([]);
|
||||
$module->assertNotEmpty([1]);
|
||||
$module->assertNull(null);
|
||||
$module->assertNotNull('');
|
||||
$module->assertNotNull(false);
|
||||
$module->assertNotNull(0);
|
||||
$module->assertTrue(true);
|
||||
$module->assertNotTrue(false);
|
||||
$module->assertNotTrue(null);
|
||||
$module->assertNotTrue('foo');
|
||||
$module->assertFalse(false);
|
||||
$module->assertNotFalse(true);
|
||||
$module->assertNotFalse(null);
|
||||
$module->assertNotFalse('foo');
|
||||
$module->assertFileExists(__FILE__);
|
||||
$module->assertFileNotExists(__FILE__ . '.notExist');
|
||||
$module->assertInstanceOf('Exception', new Exception());
|
||||
$module->assertInternalType('integer', 5);
|
||||
$module->assertArrayHasKey('one', ['one' => 1, 'two' => 2]);
|
||||
$module->assertArraySubset(['foo' => [1]], ['foo' => [1, 2]]);
|
||||
$module->assertCount(3, [1, 2, 3]);
|
||||
}
|
||||
|
||||
public function testExceptions()
|
||||
{
|
||||
$module = new \Codeception\Module\Asserts(make_container());
|
||||
$module->expectException('Exception', function () {
|
||||
throw new Exception;
|
||||
});
|
||||
$module->expectException(new Exception('here'), function () {
|
||||
throw new Exception('here');
|
||||
});
|
||||
$module->expectException(new Exception('here', 200), function () {
|
||||
throw new Exception('here', 200);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
*/
|
||||
public function testExceptionFails()
|
||||
{
|
||||
$module = new \Codeception\Module\Asserts(make_container());
|
||||
$module->expectException(new Exception('here', 200), function () {
|
||||
throw new Exception('here', 2);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessageRegExp /RuntimeException/
|
||||
*/
|
||||
public function testOutputExceptionTimeWhenNothingCaught()
|
||||
{
|
||||
$module = new \Codeception\Module\Asserts(make_container());
|
||||
$module->expectException(RuntimeException::class, function () {
|
||||
});
|
||||
}
|
||||
}
|
||||
50
vendor/codeception/base/tests/unit/Codeception/Module/BeanstalkdTest.php
vendored
Normal file
50
vendor/codeception/base/tests/unit/Codeception/Module/BeanstalkdTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use Pheanstalk\Exception\ConnectionException;
|
||||
|
||||
class BeanstalkdTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $config = array(
|
||||
'type' => 'beanstalkq',
|
||||
'host' => 'localhost'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\Queue
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\Queue(make_container());
|
||||
$this->module->_setConfig($this->config);
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
try {
|
||||
$this->module->clearQueue('default');
|
||||
} catch (ConnectionException $e) {
|
||||
$this->markTestSkipped("Beanstalk is not running");
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function flow()
|
||||
{
|
||||
$this->module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default');
|
||||
$this->module->clearQueue('default');
|
||||
|
||||
$this->module->seeQueueExists('default');
|
||||
$this->module->dontSeeQueueExists('fake_queue');
|
||||
|
||||
$this->module->seeEmptyQueue('default');
|
||||
$this->module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default');
|
||||
$this->module->dontSeeEmptyQueue('default');
|
||||
|
||||
$this->module->seeQueueHasTotalCount('default', 2);
|
||||
|
||||
$this->module->seeQueueHasCurrentCount('default', 1);
|
||||
$this->module->dontSeeQueueHasCurrentCount('default', 9999);
|
||||
|
||||
$this->module->grabQueues();
|
||||
}
|
||||
}
|
||||
84
vendor/codeception/base/tests/unit/Codeception/Module/Db/MySqlDbTest.php
vendored
Normal file
84
vendor/codeception/base/tests/unit/Codeception/Module/Db/MySqlDbTest.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
require_once \Codeception\Configuration::testsDir().'unit/Codeception/Module/Db/TestsForDb.php';
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
*/
|
||||
class MySqlDbTest extends TestsForDb
|
||||
{
|
||||
public function getPopulator()
|
||||
{
|
||||
if (getenv('APPVEYOR')) {
|
||||
$this->markTestSkipped('Disabled on Appveyor');
|
||||
}
|
||||
|
||||
if (getenv('WERCKER_ROOT')) {
|
||||
$this->markTestSkipped('Disabled on Wercker CI');
|
||||
}
|
||||
$config = $this->getConfig();
|
||||
$password = $config['password'] ? '-p'.$config['password'] : '';
|
||||
return "mysql -u \$user $password \$dbname < {$config['dump']}";
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return [
|
||||
'dsn' => 'mysql:host=localhost;dbname=codeception_test',
|
||||
'user' => 'root',
|
||||
'password' => getenv('APPVEYOR') ? 'Password12!' : '',
|
||||
'dump' => 'tests/data/dumps/mysql.sql',
|
||||
'reconnect' => true,
|
||||
'cleanup' => true,
|
||||
'populate' => true
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden, Using MYSQL CONNECTION_ID to get current connection
|
||||
*/
|
||||
public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
|
||||
{
|
||||
$testCase1 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
$testCase2 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
$testCase3 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
|
||||
|
||||
$this->module->_setConfig(['reconnect' => false]);
|
||||
$this->module->_beforeSuite();
|
||||
|
||||
// Simulate a test that runs
|
||||
$this->module->_before($testCase1);
|
||||
$connection1 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
|
||||
$this->module->_after($testCase1);
|
||||
|
||||
// Simulate a second test that runs
|
||||
$this->module->_before($testCase2);
|
||||
$connection2 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
|
||||
$this->module->_after($testCase2);
|
||||
$this->module->_afterSuite();
|
||||
|
||||
$this->module->_setConfig(['reconnect' => true]);
|
||||
$this->module->_before($testCase3);
|
||||
$connection3 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
|
||||
$this->module->_after($testCase3);
|
||||
|
||||
$this->assertEquals($connection1, $connection2);
|
||||
$this->assertNotEquals($connection3, $connection2);
|
||||
}
|
||||
|
||||
public function testGrabColumnFromDatabase()
|
||||
{
|
||||
$emails = $this->module->grabColumnFromDatabase('users', 'email');
|
||||
$this->assertEquals(
|
||||
[
|
||||
'davert@mail.ua',
|
||||
'nick@mail.ua',
|
||||
'miles@davis.com',
|
||||
'charlie@parker.com',
|
||||
],
|
||||
$emails);
|
||||
}
|
||||
|
||||
}
|
||||
43
vendor/codeception/base/tests/unit/Codeception/Module/Db/Populator/DbPopulatorTest.php
vendored
Normal file
43
vendor/codeception/base/tests/unit/Codeception/Module/Db/Populator/DbPopulatorTest.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Lib\DbPopulator;
|
||||
|
||||
/**
|
||||
* @group db
|
||||
* Class DbPopulatorTest
|
||||
*/
|
||||
class DbPopulatorTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function testCommandBuilderInterpolatesVariables()
|
||||
{
|
||||
$populator = new DbPopulator(
|
||||
[
|
||||
'populate' => true,
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=my_db',
|
||||
'dump' => 'tests/data/dumps/sqlite.sql',
|
||||
'user' => 'root',
|
||||
'populator' => 'mysql -u $user -h $host -D $dbname < $dump'
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'mysql -u root -h 127.0.0.1 -D my_db < tests/data/dumps/sqlite.sql',
|
||||
$populator->getBuiltCommand()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCommandBuilderWontTouchVariablesNotFound()
|
||||
{
|
||||
$populator = new DbPopulator([
|
||||
'populator' => 'noop_tool -u $user -h $host -D $dbname < $dump',
|
||||
'user' => 'root',
|
||||
]);
|
||||
$this->assertEquals(
|
||||
'noop_tool -u root -h $host -D $dbname < $dump',
|
||||
$populator->getBuiltCommand()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
vendor/codeception/base/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php
vendored
Normal file
38
vendor/codeception/base/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once \Codeception\Configuration::testsDir().'unit/Codeception/Module/Db/TestsForDb.php';
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
*/
|
||||
class PostgreSqlDbTest extends TestsForDb
|
||||
{
|
||||
public function getPopulator()
|
||||
{
|
||||
if (getenv('APPVEYOR')) {
|
||||
$this->markTestSkipped('Disabled on Appveyor');
|
||||
}
|
||||
if (getenv('WERCKER_ROOT')) {
|
||||
$this->markTestSkipped('Disabled on Wercker CI');
|
||||
}
|
||||
return "psql -d codeception_test -U postgres < tests/data/dumps/postgres.sql";
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
if (!function_exists('pg_connect')) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
return [
|
||||
'dsn' => 'pgsql:host=localhost;dbname=codeception_test',
|
||||
'user' => 'postgres',
|
||||
'password' => getenv('APPVEYOR') ? 'Password12!' : null,
|
||||
'dump' => defined('HHVM_VERSION') ? 'tests/data/dumps/postgres-hhvm.sql' : 'tests/data/dumps/postgres.sql',
|
||||
'reconnect' => true,
|
||||
'cleanup' => true,
|
||||
'populate' => true
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
77
vendor/codeception/base/tests/unit/Codeception/Module/Db/SqliteDbTest.php
vendored
Normal file
77
vendor/codeception/base/tests/unit/Codeception/Module/Db/SqliteDbTest.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
require_once \Codeception\Configuration::testsDir().'unit/Codeception/Module/Db/TestsForDb.php';
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
* @group db
|
||||
* Class SqliteDbTest
|
||||
*/
|
||||
class SqliteDbTest extends TestsForDb
|
||||
{
|
||||
public function getPopulator()
|
||||
{
|
||||
if (getenv('APPVEYOR')) {
|
||||
$this->markTestSkipped('Disabled on Appveyor');
|
||||
}
|
||||
|
||||
if (getenv('WERCKER_ROOT')) {
|
||||
$this->markTestSkipped('Disabled on Wercker CI');
|
||||
}
|
||||
|
||||
$this->markTestSkipped('Currently Travis CI uses old SQLite :(');
|
||||
|
||||
$config = $this->getConfig();
|
||||
@chmod('tests/data/sqlite.db', 0777);
|
||||
return 'cat '. $config['dump'] .' | sqlite3 tests/data/sqlite.db';
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$dumpFile = 'dumps/sqlite-54.sql';
|
||||
} else {
|
||||
$dumpFile = 'dumps/sqlite.sql';
|
||||
}
|
||||
|
||||
return [
|
||||
'dsn' => 'sqlite:tests/data/sqlite.db',
|
||||
'user' => 'root',
|
||||
'password' => '',
|
||||
'dump' => 'tests/data/' . $dumpFile,
|
||||
'reconnect' => true,
|
||||
'cleanup' => true,
|
||||
'populate' => true
|
||||
];
|
||||
}
|
||||
|
||||
public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
|
||||
{
|
||||
$testCase1 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
$testCase2 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
$testCase3 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
|
||||
|
||||
$this->module->_setConfig(['reconnect' => false]);
|
||||
$this->module->_beforeSuite();
|
||||
|
||||
// Simulate a test that runs
|
||||
$this->module->_before($testCase1);
|
||||
$connection1 = spl_object_hash($this->module->dbh);
|
||||
$this->module->_after($testCase1);
|
||||
|
||||
// Simulate a second test that runs
|
||||
$this->module->_before($testCase2);
|
||||
$connection2 = spl_object_hash($this->module->dbh);
|
||||
$this->module->_after($testCase2);
|
||||
$this->module->_afterSuite();
|
||||
|
||||
$this->module->_setConfig(['reconnect' => true]);
|
||||
$this->module->_before($testCase3);
|
||||
$connection3 = spl_object_hash($this->module->dbh);
|
||||
$this->module->_after($testCase3);
|
||||
|
||||
$this->assertEquals($connection1, $connection2);
|
||||
$this->assertNotEquals($connection3, $connection2);
|
||||
}
|
||||
}
|
||||
206
vendor/codeception/base/tests/unit/Codeception/Module/Db/TestsForDb.php
vendored
Normal file
206
vendor/codeception/base/tests/unit/Codeception/Module/Db/TestsForDb.php
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Lib\Driver\Db;
|
||||
|
||||
abstract class TestsForDb extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Module\Db
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
abstract public function getConfig();
|
||||
abstract public function getPopulator();
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
Db::create($config['dsn'], $config['user'], $config['password'])->cleanup();
|
||||
|
||||
$this->module = new \Codeception\Module\Db(make_container(), $config);
|
||||
$this->module->_beforeSuite();
|
||||
$this->module->_before(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
$this->assertTrue($this->module->isPopulated());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->module->_resetConfig();
|
||||
$this->module->_after(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
}
|
||||
|
||||
public function testConnectionIsKeptForTheWholeSuite()
|
||||
{
|
||||
$testCase1 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
$testCase2 = \Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface');
|
||||
|
||||
$this->module->_reconfigure(['reconnect' => false]);
|
||||
$this->module->_beforeSuite();
|
||||
|
||||
// Simulate a test that runs
|
||||
$this->module->_before($testCase1);
|
||||
// Save these object instances IDs
|
||||
$driverAndConn1 = [
|
||||
$this->module->driver,
|
||||
$this->module->dbh
|
||||
];
|
||||
$this->module->_after($testCase1);
|
||||
|
||||
// Simulate a second test that runs
|
||||
$this->module->_before($testCase2);
|
||||
$driverAndConn2 = [
|
||||
$this->module->driver,
|
||||
$this->module->dbh
|
||||
];
|
||||
$this->module->_after($testCase2);
|
||||
$this->assertEquals($driverAndConn2, $driverAndConn1);
|
||||
|
||||
$this->module->_afterSuite();
|
||||
}
|
||||
|
||||
|
||||
public function testSeeInDatabase()
|
||||
{
|
||||
$this->module->seeInDatabase('users', ['name' => 'davert']);
|
||||
}
|
||||
|
||||
public function testCountInDatabase()
|
||||
{
|
||||
$this->module->seeNumRecords(1, 'users', ['name' => 'davert']);
|
||||
$this->module->seeNumRecords(0, 'users', ['name' => 'davert', 'email' => 'xxx@yyy.zz']);
|
||||
$this->module->seeNumRecords(0, 'users', ['name' => 'user1']);
|
||||
}
|
||||
|
||||
public function testDontSeeInDatabase()
|
||||
{
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'user1']);
|
||||
}
|
||||
|
||||
public function testDontSeeInDatabaseWithEmptyTable()
|
||||
{
|
||||
$this->module->dontSeeInDatabase('empty_table');
|
||||
}
|
||||
|
||||
public function testCleanupDatabase()
|
||||
{
|
||||
$this->module->seeInDatabase('users', ['name' => 'davert']);
|
||||
$this->module->_cleanup();
|
||||
|
||||
// Since table does not exist it should fail
|
||||
// TODO: Catch this exception at the driver level and re-throw a general one
|
||||
// just for "table not found" across all the drivers
|
||||
$this->setExpectedException('PDOException');
|
||||
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'davert']);
|
||||
}
|
||||
|
||||
public function testHaveAndSeeInDatabase()
|
||||
{
|
||||
$userId = $this->module->haveInDatabase('users', ['name' => 'john', 'email' => 'john@jon.com']);
|
||||
$this->module->haveInDatabase('groups', ['name' => 'john', 'enabled' => false]);
|
||||
$this->assertInternalType('integer', $userId);
|
||||
$this->module->seeInDatabase('users', ['name' => 'john', 'email' => 'john@jon.com']);
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'john', 'email' => null]);
|
||||
$this->module->_after(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
|
||||
$this->module->_before(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'john']);
|
||||
}
|
||||
|
||||
public function testHaveInDatabaseWithCompositePrimaryKey()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
$this->markTestSkipped('Does not support WITHOUT ROWID on travis');
|
||||
}
|
||||
|
||||
$insertQuery = 'INSERT INTO composite_pk (group_id, id, status) VALUES (?, ?, ?)';
|
||||
//this test checks that module does not delete columns by partial primary key
|
||||
$this->module->driver->executeQuery($insertQuery, [1, 2, 'test']);
|
||||
$this->module->driver->executeQuery($insertQuery, [2, 1, 'test2']);
|
||||
$testData = ['id' => 2, 'group_id' => 2, 'status' => 'test3'];
|
||||
$this->module->haveInDatabase('composite_pk', $testData);
|
||||
$this->module->seeInDatabase('composite_pk', $testData);
|
||||
$this->module->_reconfigure(['cleanup' => false]);
|
||||
$this->module->_after(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
|
||||
$this->module->_before(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
$this->module->dontSeeInDatabase('composite_pk', $testData);
|
||||
$this->module->seeInDatabase('composite_pk', ['group_id' => 1, 'id' => 2, 'status' => 'test']);
|
||||
$this->module->seeInDatabase('composite_pk', ['group_id' => 2, 'id' => 1, 'status' => 'test2']);
|
||||
}
|
||||
|
||||
public function testHaveInDatabaseWithoutPrimaryKey()
|
||||
{
|
||||
$testData = ['status' => 'test'];
|
||||
$this->module->haveInDatabase('no_pk', $testData);
|
||||
$this->module->seeInDatabase('no_pk', $testData);
|
||||
$this->module->_after(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
|
||||
$this->module->_before(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
$this->module->dontSeeInDatabase('no_pk', $testData);
|
||||
}
|
||||
|
||||
public function testGrabFromDatabase()
|
||||
{
|
||||
$email = $this->module->grabFromDatabase('users', 'email', ['name' => 'davert']);
|
||||
$this->assertEquals('davert@mail.ua', $email);
|
||||
}
|
||||
|
||||
public function testGrabNumRecords()
|
||||
{
|
||||
$num = $this->module->grabNumRecords('users', ['name' => 'davert']);
|
||||
$this->assertEquals($num, 1);
|
||||
$num = $this->module->grabNumRecords('users', ['name' => 'davert', 'email' => 'xxx@yyy.zz']);
|
||||
$this->assertEquals($num, 0);
|
||||
$num = $this->module->grabNumRecords('users', ['name' => 'user1']);
|
||||
$this->assertEquals($num, 0);
|
||||
}
|
||||
|
||||
public function testLoadWithPopulator()
|
||||
{
|
||||
$this->module->_cleanup();
|
||||
$this->assertFalse($this->module->isPopulated());
|
||||
try {
|
||||
$this->module->seeInDatabase('users', ['name' => 'davert']);
|
||||
} catch (\PDOException $noTable) {
|
||||
$noTable;
|
||||
// No table was found...
|
||||
}
|
||||
$this->module->_reconfigure(
|
||||
[
|
||||
'populate' => true,
|
||||
'populator' => $this->getPopulator(),
|
||||
'cleanup' => true,
|
||||
]
|
||||
);
|
||||
$this->module->_loadDump();
|
||||
$this->assertTrue($this->module->isPopulated());
|
||||
$this->module->seeInDatabase('users', ['name' => 'davert']);
|
||||
}
|
||||
|
||||
public function testUpdateInDatabase()
|
||||
{
|
||||
$this->module->seeInDatabase('users', ['name' => 'davert']);
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'user1']);
|
||||
|
||||
$this->module->updateInDatabase('users', ['name' => 'user1'], ['name' => 'davert']);
|
||||
|
||||
$this->module->dontSeeInDatabase('users', ['name' => 'davert']);
|
||||
$this->module->seeInDatabase('users', ['name' => 'user1']);
|
||||
|
||||
$this->module->updateInDatabase('users', ['name' => 'davert'], ['name' => 'user1']);
|
||||
}
|
||||
|
||||
public function testInsertInDatabase()
|
||||
{
|
||||
$testData = ['status' => 'test'];
|
||||
$this->module->_insertInDatabase('no_pk', $testData);
|
||||
$this->module->seeInDatabase('no_pk', $testData);
|
||||
$this->module->_reconfigure(['cleanup' => false]);
|
||||
$this->module->_after(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
|
||||
$this->module->_before(\Codeception\Util\Stub::makeEmpty('\Codeception\TestInterface'));
|
||||
$this->module->seeInDatabase('no_pk', $testData);
|
||||
}
|
||||
|
||||
}
|
||||
124
vendor/codeception/base/tests/unit/Codeception/Module/FTPTest.php
vendored
Normal file
124
vendor/codeception/base/tests/unit/Codeception/Module/FTPTest.php
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
/**
|
||||
* Module for testing remote ftp systems.
|
||||
*
|
||||
* ## Status
|
||||
*
|
||||
* Maintainer: **nathanmac**
|
||||
* Stability: **stable**
|
||||
* Contact: nathan.macnamara@outlook.com
|
||||
*
|
||||
*/
|
||||
class FTPTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $config = array(
|
||||
'host' => '127.0.0.1',
|
||||
'tmp' => 'temp',
|
||||
'user' => 'user',
|
||||
'password' => 'password'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\FTP
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\FTP(make_container());
|
||||
$this->module->_setConfig($this->config);
|
||||
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled Test - for travis testing, requires testing server
|
||||
*/
|
||||
public function flow()
|
||||
{
|
||||
// Check root directory
|
||||
$this->assertEquals('/', $this->module->grabDirectory());
|
||||
|
||||
// Create directory
|
||||
$this->module->makeDir('TESTING');
|
||||
// Move to new directory
|
||||
$this->module->amInPath('TESTING');
|
||||
// Verify current directory
|
||||
$this->assertEquals('/TESTING', $this->module->grabDirectory());
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
// Create files on server
|
||||
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
|
||||
$this->module->writeToFile('test_ftp_567.txt', 'some data added here');
|
||||
$this->module->writeToFile('test_ftp_678.txt', 'some data added here');
|
||||
|
||||
// Grab file list
|
||||
$files = $this->module->grabFileList();
|
||||
// Verify files are listed
|
||||
$this->assertContains('test_ftp_123.txt', $files);
|
||||
$this->assertContains('test_ftp_567.txt', $files);
|
||||
$this->assertContains('test_ftp_678.txt', $files);
|
||||
|
||||
$this->module->seeFileFound('test_ftp_123.txt');
|
||||
$this->module->dontSeeFileFound('test_ftp_321.txt');
|
||||
$this->module->seeFileFoundMatches('/^test_ftp_([0-9]{3}).txt$/');
|
||||
$this->module->dontSeeFileFoundMatches('/^test_([0-9]{3})_ftp.txt$/');
|
||||
|
||||
$this->assertGreaterThan(0, $this->module->grabFileCount());
|
||||
$this->assertGreaterThan(0, $this->module->grabFileSize('test_ftp_678.txt'));
|
||||
$this->assertGreaterThan(0, $this->module->grabFileModified('test_ftp_678.txt'));
|
||||
|
||||
$this->module->openFile('test_ftp_567.txt');
|
||||
$this->module->deleteThisFile();
|
||||
$this->module->dontSeeFileFound('test_ftp_567.txt');
|
||||
|
||||
// Open file (download local copy)
|
||||
$this->module->openFile('test_ftp_123.txt');
|
||||
$this->module->seeInThisFile('data');
|
||||
|
||||
$this->module->dontSeeInThisFile('banana');
|
||||
$this->module->seeFileContentsEqual('some data added here');
|
||||
|
||||
$this->module->renameFile('test_ftp_678.txt', 'test_ftp_987.txt');
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
// Verify old file is not listed
|
||||
$this->assertNotContains('test_ftp_678.txt', $files);
|
||||
// Verify renamed file is listed
|
||||
$this->assertContains('test_ftp_987.txt', $files);
|
||||
|
||||
$this->module->deleteFile('test_ftp_123.txt');
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
// Verify deleted file is not listed
|
||||
$this->assertNotContains('test_ftp_123.txt', $files);
|
||||
|
||||
// Move to root directory
|
||||
$this->module->amInPath('/');
|
||||
|
||||
$this->assertEquals('/', $this->module->grabDirectory());
|
||||
|
||||
$this->module->renameDir('TESTING', 'TESTING_NEW');
|
||||
|
||||
// Remove directory (with contents)
|
||||
$this->module->deleteDir('TESTING_NEW');
|
||||
|
||||
// Test Clearing the Directory
|
||||
$this->module->makeDir('TESTING');
|
||||
$this->module->amInPath('TESTING');
|
||||
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
|
||||
$this->module->amInPath('/');
|
||||
$this->assertGreaterThan(0, $this->module->grabFileCount('TESTING'));
|
||||
$this->module->cleanDir('TESTING');
|
||||
$this->assertEquals(0, $this->module->grabFileCount('TESTING'));
|
||||
$this->module->deleteDir('TESTING');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->module->_after(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
}
|
||||
90
vendor/codeception/base/tests/unit/Codeception/Module/FilesystemTest.php
vendored
Normal file
90
vendor/codeception/base/tests/unit/Codeception/Module/FilesystemTest.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Module\Filesystem;
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
class FilesystemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\Filesystem
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new Filesystem(make_container());
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->module->_after(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
|
||||
public function testSeeFileFoundPassesWhenFileExists()
|
||||
{
|
||||
$this->module->seeFileFound('tests/data/dumps/mysql.sql');
|
||||
}
|
||||
|
||||
public function testSeeFileFoundPassesWhenFileExistsInSubdirectoryOfPath()
|
||||
{
|
||||
$this->module->seeFileFound('mysql.sql', 'tests/data/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessage File "does-not-exist" not found at
|
||||
*/
|
||||
public function testSeeFileFoundFailsWhenFileDoesNotExist()
|
||||
{
|
||||
$this->module->seeFileFound('does-not-exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessageRegExp /Directory does not exist: .*does-not-exist/
|
||||
*/
|
||||
public function testSeeFileFoundFailsWhenPathDoesNotExist()
|
||||
{
|
||||
$this->module->seeFileFound('mysql.sql', 'does-not-exist');
|
||||
}
|
||||
|
||||
public function testDontSeeFileFoundPassesWhenFileDoesNotExists()
|
||||
{
|
||||
$this->module->dontSeeFileFound('does-not-exist');
|
||||
}
|
||||
|
||||
public function testDontSeeFileFoundPassesWhenFileDoesNotExistsInPath()
|
||||
{
|
||||
$this->module->dontSeeFileFound('does-not-exist', 'tests/data/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessage Failed asserting that file "tests/data/dumps/mysql.sql" does not exist.
|
||||
*/
|
||||
public function testDontSeeFileFoundFailsWhenFileExists()
|
||||
{
|
||||
$this->module->dontSeeFileFound('tests/data/dumps/mysql.sql');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessageRegExp /Directory does not exist: .*does-not-exist/
|
||||
*/
|
||||
public function testDontSeeFileFoundFailsWhenPathDoesNotExist()
|
||||
{
|
||||
$this->module->dontSeeFileFound('mysql.sql', 'does-not-exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
* @expectedExceptionMessageRegExp /Failed asserting that file ".*tests\/data\/dumps\/mysql.sql" does not exist/
|
||||
*/
|
||||
public function testDontSeeFileFoundFailsWhenFileExistsInSubdirectoryOfPath()
|
||||
{
|
||||
$this->module->dontSeeFileFound('mysql.sql', 'tests/data/');
|
||||
}
|
||||
}
|
||||
95
vendor/codeception/base/tests/unit/Codeception/Module/FrameworksTest.php
vendored
Normal file
95
vendor/codeception/base/tests/unit/Codeception/Module/FrameworksTest.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
require_once __DIR__ . '/TestsForWeb.php';
|
||||
|
||||
/**
|
||||
* @group appveyor
|
||||
*/
|
||||
class FrameworksTest extends TestsForWeb
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Lib\Framework
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\UniversalFramework(make_container());
|
||||
}
|
||||
|
||||
public function testHttpAuth()
|
||||
{
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->see('Unauthorized');
|
||||
$this->module->amHttpAuthenticated('davert', 'password');
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->dontSee('Unauthorized');
|
||||
$this->module->see("Welcome, davert");
|
||||
$this->module->amHttpAuthenticated('davert', '123456');
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->see('Forbidden');
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownOnRedirectToExternalUrl()
|
||||
{
|
||||
$this->setExpectedException('\Codeception\Exception\ExternalUrlException');
|
||||
$this->module->amOnPage('/external_url');
|
||||
$this->module->click('Next');
|
||||
}
|
||||
|
||||
public function testMoveBackOneStep()
|
||||
{
|
||||
$this->module->amOnPage('/iframe');
|
||||
$this->module->switchToIframe('content');
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
$this->module->click('Ссылочка');
|
||||
$this->module->seeCurrentUrlEquals('/');
|
||||
$this->module->moveBack();
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
$this->module->click('Sign in!');
|
||||
$this->module->seeCurrentUrlEquals('/login');
|
||||
}
|
||||
|
||||
public function testMoveBackTwoSteps()
|
||||
{
|
||||
$this->module->amOnPage('/iframe');
|
||||
$this->module->switchToIframe('content');
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
$this->module->click('Ссылочка');
|
||||
$this->module->seeCurrentUrlEquals('/');
|
||||
$this->module->moveBack(2);
|
||||
$this->module->seeCurrentUrlEquals('/iframe');
|
||||
}
|
||||
|
||||
public function testMoveBackThrowsExceptionIfNumberOfStepsIsInvalid()
|
||||
{
|
||||
$this->module->amOnPage('/iframe');
|
||||
$this->module->switchToIframe('content');
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
$this->module->click('Ссылочка');
|
||||
$this->module->seeCurrentUrlEquals('/');
|
||||
|
||||
$invalidValues = [0, -5, 1.5, 'a', 3];
|
||||
foreach ($invalidValues as $invalidValue) {
|
||||
try {
|
||||
$this->module->moveBack($invalidValue);
|
||||
$this->fail('Expected to get exception here');
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
codecept_debug('Exception: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateSnapshotOnFail()
|
||||
{
|
||||
$module = Stub::construct(get_class($this->module), [make_container()], [
|
||||
'_savePageSource' => \Codeception\Stub\Expected::once(function ($filename) {
|
||||
$this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
|
||||
}),
|
||||
]);
|
||||
$module->amOnPage('/');
|
||||
$cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
|
||||
$module->_failed($cest, new \PHPUnit\Framework\AssertionFailedError());
|
||||
}
|
||||
}
|
||||
148
vendor/codeception/base/tests/unit/Codeception/Module/MongoDbLegacyTest.php
vendored
Normal file
148
vendor/codeception/base/tests/unit/Codeception/Module/MongoDbLegacyTest.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Module\MongoDb;
|
||||
|
||||
class MongoDbLegacyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $mongoConfig = array(
|
||||
'dsn' => 'mongodb://localhost:27017/test'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var MongoDb
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* @var \MongoDb
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \MongoCollection
|
||||
*/
|
||||
private $userCollection;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Mongo')) {
|
||||
$this->markTestSkipped('Mongo is not installed');
|
||||
}
|
||||
if (!class_exists('MongoDB\Client')) {
|
||||
$this->markTestSkipped('MongoDb\Client is not installed');
|
||||
}
|
||||
|
||||
$mongo = new \MongoClient();
|
||||
|
||||
$this->module = new MongoDb(make_container());
|
||||
$this->module->_setConfig($this->mongoConfig);
|
||||
$this->module->_initialize();
|
||||
|
||||
$this->db = $mongo->selectDB('test');
|
||||
$this->userCollection = $this->db->createCollection('users');
|
||||
$this->userCollection->insert(array('id' => 1, 'email' => 'miles@davis.com'));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (!is_null($this->userCollection)) {
|
||||
$this->userCollection->drop();
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeeInCollection()
|
||||
{
|
||||
$this->module->seeInCollection('users', array('email' => 'miles@davis.com'));
|
||||
}
|
||||
|
||||
public function testDontSeeInCollection()
|
||||
{
|
||||
$this->module->dontSeeInCollection('users', array('email' => 'davert@davert.com'));
|
||||
}
|
||||
|
||||
public function testHaveAndSeeInCollection()
|
||||
{
|
||||
$this->module->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
|
||||
$this->module->seeInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
|
||||
}
|
||||
|
||||
public function testGrabFromCollection()
|
||||
{
|
||||
$user = $this->module->grabFromCollection('users', array('id' => 1));
|
||||
$this->assertArrayHasKey('email', $user);
|
||||
$this->assertEquals('miles@davis.com', $user['email']);
|
||||
}
|
||||
|
||||
public function testSeeNumElementsInCollection()
|
||||
{
|
||||
$this->module->seeNumElementsInCollection('users', 1);
|
||||
$this->module->seeNumElementsInCollection('users', 1, array('email' => 'miles@davis.com'));
|
||||
$this->module->seeNumElementsInCollection('users', 0, array('name' => 'Doe'));
|
||||
}
|
||||
|
||||
public function testGrabCollectionCount()
|
||||
{
|
||||
$this->userCollection->insert(array('id' => 2, 'email' => 'louis@armstrong.com'));
|
||||
$this->userCollection->insert(array('id' => 3, 'email' => 'dizzy@gillespie.com'));
|
||||
|
||||
$this->assertEquals(1, $this->module->grabCollectionCount('users', array('id' => 3)));
|
||||
$this->assertEquals(3, $this->module->grabCollectionCount('users'));
|
||||
}
|
||||
|
||||
public function testSeeElementIsArray()
|
||||
{
|
||||
$this->userCollection->insert(array('id' => 4, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
|
||||
$this->module->seeElementIsArray('users', array('id' => 4), 'trumpets');
|
||||
}
|
||||
|
||||
|
||||
public function testSeeElementIsArrayThrowsError()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
|
||||
$this->userCollection->insert(array('id' => 5, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
$this->userCollection->insert(array('id' => 6, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
$this->module->seeElementIsArray('users', array(), 'trumpets');
|
||||
}
|
||||
|
||||
public function testSeeElementIsObject()
|
||||
{
|
||||
$trumpet = new \StdClass;
|
||||
|
||||
$trumpet->name = 'Trumpet 1';
|
||||
$trumpet->pitch = 'B♭';
|
||||
$trumpet->price = array('min' => 458, 'max' => 891);
|
||||
|
||||
$this->userCollection->insert(array('id' => 6, 'trumpet' => $trumpet));
|
||||
|
||||
$this->module->seeElementIsObject('users', array('id' => 6), 'trumpet');
|
||||
}
|
||||
|
||||
public function testSeeElementIsObjectThrowsError()
|
||||
{
|
||||
$trumpet = new \StdClass;
|
||||
|
||||
$trumpet->name = 'Trumpet 1';
|
||||
$trumpet->pitch = 'B♭';
|
||||
$trumpet->price = array('min' => 458, 'max' => 891);
|
||||
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
|
||||
$this->userCollection->insert(array('id' => 5, 'trumpet' => $trumpet));
|
||||
$this->userCollection->insert(array('id' => 6, 'trumpet' => $trumpet));
|
||||
|
||||
$this->module->seeElementIsObject('users', array(), 'trumpet');
|
||||
}
|
||||
|
||||
public function testUseDatabase()
|
||||
{
|
||||
$this->module->useDatabase('example');
|
||||
$this->module->haveInCollection('stuff', array('name' => 'Ashley', 'email' => 'me@ashleyclarke.me'));
|
||||
$this->module->seeInCollection('stuff', array('name' => 'Ashley', 'email' => 'me@ashleyclarke.me'));
|
||||
$this->module->dontSeeInCollection('users', array('email' => 'miles@davis.com'));
|
||||
}
|
||||
}
|
||||
170
vendor/codeception/base/tests/unit/Codeception/Module/MongoDbTest.php
vendored
Normal file
170
vendor/codeception/base/tests/unit/Codeception/Module/MongoDbTest.php
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Module\MongoDb;
|
||||
use Codeception\Exception\ModuleException;
|
||||
use Codeception\Test\Unit;
|
||||
|
||||
class MongoDbTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $mongoConfig = array(
|
||||
'dsn' => 'mongodb://localhost:27017/test?connectTimeoutMS=300',
|
||||
'dump' => 'tests/data/dumps/mongo.js',
|
||||
'populate' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* @var MongoDb
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* @var \MongoDB\Database
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \MongoDB\Collection
|
||||
*/
|
||||
private $userCollection;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('\MongoDB\Client')) {
|
||||
$this->markTestSkipped('MongoDB is not installed');
|
||||
}
|
||||
|
||||
$mongo = new \MongoDB\Client();
|
||||
|
||||
$this->module = new MongoDb(make_container());
|
||||
$this->module->_setConfig($this->mongoConfig);
|
||||
try {
|
||||
$this->module->_initialize();
|
||||
} catch (ModuleException $e) {
|
||||
$this->markTestSkipped($e->getMessage());
|
||||
}
|
||||
|
||||
$this->db = $mongo->selectDatabase('test');
|
||||
$this->userCollection = $this->db->users;
|
||||
$this->userCollection->insertOne(array('id' => 1, 'email' => 'miles@davis.com'));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (!is_null($this->userCollection)) {
|
||||
$this->userCollection->drop();
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeeInCollection()
|
||||
{
|
||||
$this->module->seeInCollection('users', array('email' => 'miles@davis.com'));
|
||||
}
|
||||
|
||||
public function testDontSeeInCollection()
|
||||
{
|
||||
$this->module->dontSeeInCollection('users', array('email' => 'davert@davert.com'));
|
||||
}
|
||||
|
||||
public function testHaveAndSeeInCollection()
|
||||
{
|
||||
$this->module->haveInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
|
||||
$this->module->seeInCollection('users', array('name' => 'John', 'email' => 'john@coltrane.com'));
|
||||
}
|
||||
|
||||
public function testGrabFromCollection()
|
||||
{
|
||||
$user = $this->module->grabFromCollection('users', array('id' => 1));
|
||||
$this->assertArrayHasKey('email', $user);
|
||||
$this->assertEquals('miles@davis.com', $user['email']);
|
||||
}
|
||||
|
||||
public function testSeeNumElementsInCollection()
|
||||
{
|
||||
$this->module->seeNumElementsInCollection('users', 1);
|
||||
$this->module->seeNumElementsInCollection('users', 1, array('email' => 'miles@davis.com'));
|
||||
$this->module->seeNumElementsInCollection('users', 0, array('name' => 'Doe'));
|
||||
}
|
||||
|
||||
public function testGrabCollectionCount()
|
||||
{
|
||||
$this->userCollection->insertOne(array('id' => 2, 'email' => 'louis@armstrong.com'));
|
||||
$this->userCollection->insertOne(array('id' => 3, 'email' => 'dizzy@gillespie.com'));
|
||||
|
||||
$this->assertEquals(1, $this->module->grabCollectionCount('users', array('id' => 3)));
|
||||
$this->assertEquals(3, $this->module->grabCollectionCount('users'));
|
||||
}
|
||||
|
||||
public function testSeeElementIsArray()
|
||||
{
|
||||
$this->userCollection->insertOne(array('id' => 4, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
|
||||
$this->module->seeElementIsArray('users', array('id' => 4), 'trumpets');
|
||||
}
|
||||
|
||||
|
||||
public function testSeeElementIsArrayThrowsError()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
|
||||
$this->userCollection->insertOne(array('id' => 5, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
$this->userCollection->insertOne(array('id' => 6, 'trumpets' => array('piccolo', 'bass', 'slide')));
|
||||
$this->module->seeElementIsArray('users', array(), 'trumpets');
|
||||
}
|
||||
|
||||
public function testSeeElementIsObject()
|
||||
{
|
||||
$trumpet = new \StdClass;
|
||||
|
||||
$trumpet->name = 'Trumpet 1';
|
||||
$trumpet->pitch = 'B♭';
|
||||
$trumpet->price = array('min' => 458, 'max' => 891);
|
||||
|
||||
$this->userCollection->insertOne(array('id' => 6, 'trumpet' => $trumpet));
|
||||
|
||||
$this->module->seeElementIsObject('users', array('id' => 6), 'trumpet');
|
||||
}
|
||||
|
||||
public function testSeeElementIsObjectThrowsError()
|
||||
{
|
||||
$trumpet = new \StdClass;
|
||||
|
||||
$trumpet->name = 'Trumpet 1';
|
||||
$trumpet->pitch = 'B♭';
|
||||
$trumpet->price = array('min' => 458, 'max' => 891);
|
||||
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
|
||||
$this->userCollection->insertOne(array('id' => 5, 'trumpet' => $trumpet));
|
||||
$this->userCollection->insertOne(array('id' => 6, 'trumpet' => $trumpet));
|
||||
|
||||
$this->module->seeElementIsObject('users', array(), 'trumpet');
|
||||
}
|
||||
|
||||
public function testUseDatabase()
|
||||
{
|
||||
$this->module->useDatabase('example');
|
||||
$this->module->haveInCollection('stuff', array('name' => 'Ashley', 'email' => 'me@ashleyclarke.me'));
|
||||
$this->module->seeInCollection('stuff', array('name' => 'Ashley', 'email' => 'me@ashleyclarke.me'));
|
||||
$this->module->dontSeeInCollection('users', array('email' => 'miles@davis.com'));
|
||||
}
|
||||
|
||||
public function testLoadDump()
|
||||
{
|
||||
$testRecords = [
|
||||
['name' => 'Michael Jordan', 'position' => 'sg'],
|
||||
['name' => 'Ron Harper','position' => 'pg'],
|
||||
['name' => 'Steve Kerr','position' => 'pg'],
|
||||
['name' => 'Toni Kukoc','position' => 'sf'],
|
||||
['name' => 'Luc Longley','position' => 'c'],
|
||||
['name' => 'Scottie Pippen','position' => 'sf'],
|
||||
['name' => 'Dennis Rodman','position' => 'pf']
|
||||
];
|
||||
|
||||
foreach ($testRecords as $testRecord) {
|
||||
$this->module->haveInCollection('96_bulls', $testRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
326
vendor/codeception/base/tests/unit/Codeception/Module/PhpBrowserRestTest.php
vendored
Normal file
326
vendor/codeception/base/tests/unit/Codeception/Module/PhpBrowserRestTest.php
vendored
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Codeception\Util\Stub as Stub;
|
||||
|
||||
class PhpBrowserRestTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Module\REST
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\PhpBrowser
|
||||
*/
|
||||
protected $phpBrowser;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->phpBrowser = new \Codeception\Module\PhpBrowser(make_container());
|
||||
$url = 'http://localhost:8010';
|
||||
$this->phpBrowser->_setConfig(['url' => $url]);
|
||||
$this->phpBrowser->_initialize();
|
||||
|
||||
$this->module = Stub::make('\Codeception\Module\REST');
|
||||
$this->module->_inject($this->phpBrowser);
|
||||
$this->module->_initialize();
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
|
||||
$this->phpBrowser->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
|
||||
}
|
||||
|
||||
private function setStubResponse($response)
|
||||
{
|
||||
$this->phpBrowser = Stub::make('\Codeception\Module\PhpBrowser', ['_getResponseContent' => $response]);
|
||||
$this->module->_inject($this->phpBrowser);
|
||||
$this->module->_initialize();
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContains('davert');
|
||||
$this->module->seeResponseContainsJson(['name' => 'davert']);
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSeeResponseCodeIs(404);
|
||||
}
|
||||
|
||||
public function testSendAbsoluteUrlGet()
|
||||
{
|
||||
$this->module->sendGET('http://127.0.0.1:8010/rest/user/');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
}
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$this->module->sendPOST('/rest/user/', ['name' => 'john']);
|
||||
$this->module->seeResponseContains('john');
|
||||
$this->module->seeResponseContainsJson(['name' => 'john']);
|
||||
}
|
||||
|
||||
public function testValidJson()
|
||||
{
|
||||
$this->setStubResponse('{"xxx": "yyy"}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->setStubResponse('{"xxx": "yyy", "zzz": ["a","b"]}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseEquals('{"xxx": "yyy", "zzz": ["a","b"]}');
|
||||
}
|
||||
|
||||
public function testInvalidJson()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
$this->setStubResponse('{xxx = yyy}');
|
||||
$this->module->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function testValidXml()
|
||||
{
|
||||
$this->setStubResponse('<xml></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
$this->setStubResponse('<xml><name>John</name></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
$this->module->seeResponseEquals('<xml><name>John</name></xml>');
|
||||
}
|
||||
|
||||
public function testInvalidXml()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
$this->setStubResponse('<xml><name>John</surname></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
}
|
||||
|
||||
public function testSeeInJson()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'{"ticket": {"title": "Bug should be fixed", "user": {"name": "Davert"}, "labels": null}}'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContainsJson(['name' => 'Davert']);
|
||||
$this->module->seeResponseContainsJson(['user' => ['name' => 'Davert']]);
|
||||
$this->module->seeResponseContainsJson(['ticket' => ['title' => 'Bug should be fixed']]);
|
||||
$this->module->seeResponseContainsJson(['ticket' => ['user' => ['name' => 'Davert']]]);
|
||||
$this->module->seeResponseContainsJson(array('ticket' => array('labels' => null)));
|
||||
}
|
||||
|
||||
public function testSeeInJsonCollection()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContainsJson(array('tags' => array('web-dev', 'java')));
|
||||
$this->module->seeResponseContainsJson(array('user' => 'John Doe', 'age' => 27));
|
||||
}
|
||||
|
||||
public function testArrayJson()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"id":1,"title": "Bug should be fixed"},{"title": "Feature should be implemented","id":2}]'
|
||||
);
|
||||
$this->module->seeResponseContainsJson(array('id' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/4202
|
||||
*/
|
||||
public function testSeeResponseContainsJsonFailsGracefullyWhenJsonResultIsNotArray()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->setStubResponse(json_encode('no_status'));
|
||||
$this->module->seeResponseContainsJson(array('id' => 1));
|
||||
}
|
||||
|
||||
public function testDontSeeResponseJsonMatchesJsonPathPassesWhenJsonResultIsNotArray()
|
||||
{
|
||||
$this->setStubResponse(json_encode('no_status'));
|
||||
$this->module->dontSeeResponseJsonMatchesJsonPath('$.error');
|
||||
}
|
||||
|
||||
public function testDontSeeInJson()
|
||||
{
|
||||
$this->setStubResponse('{"ticket": {"title": "Bug should be fixed", "user": {"name": "Davert"}}}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->dontSeeResponseContainsJson(array('name' => 'Davet'));
|
||||
$this->module->dontSeeResponseContainsJson(array('user' => array('name' => 'Davet')));
|
||||
$this->module->dontSeeResponseContainsJson(array('user' => array('title' => 'Bug should be fixed')));
|
||||
}
|
||||
|
||||
public function testApplicationJsonIncludesJsonAsContent()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendPOST('/', array('name' => 'john'));
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertContains('application/json', $request->getServer());
|
||||
$server = $request->getServer();
|
||||
$this->assertEquals('application/json', $server['HTTP_CONTENT_TYPE']);
|
||||
$this->assertJson($request->getContent());
|
||||
$this->assertEmpty($request->getParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/3516
|
||||
*/
|
||||
public function testApplicationJsonHeaderCheckIsCaseInsensitive()
|
||||
{
|
||||
$this->module->haveHttpHeader('content-type', 'application/json');
|
||||
$this->module->sendPOST('/', array('name' => 'john'));
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$server = $request->getServer();
|
||||
$this->assertEquals('application/json', $server['HTTP_CONTENT_TYPE']);
|
||||
$this->assertJson($request->getContent());
|
||||
$this->assertEmpty($request->getParameters());
|
||||
}
|
||||
|
||||
public function testGetApplicationJsonNotIncludesJsonAsContent()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendGET('/', array('name' => 'john'));
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertNull($request->getContent());
|
||||
$this->assertContains('john', $request->getParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue https://github.com/Codeception/Codeception/issues/2075
|
||||
* Client is undefined for the second test
|
||||
*/
|
||||
public function testTwoTests()
|
||||
{
|
||||
$cest1 = Stub::makeEmpty('\Codeception\Test\Cest');
|
||||
$cest2 = Stub::makeEmpty('\Codeception\Test\Cest');
|
||||
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContains('davert');
|
||||
$this->module->seeResponseContainsJson(array('name' => 'davert'));
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSeeResponseCodeIs(404);
|
||||
|
||||
$this->phpBrowser->_after($cest1);
|
||||
$this->module->_after($cest1);
|
||||
$this->module->_before($cest2);
|
||||
$this->phpBrowser->_before($cest2);
|
||||
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContains('davert');
|
||||
$this->module->seeResponseContainsJson(array('name' => 'davert'));
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSeeResponseCodeIs(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue https://github.com/Codeception/Codeception/issues/2070
|
||||
*/
|
||||
public function testArrayOfZeroesInJsonResponse()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendGET('/rest/zeroes');
|
||||
$this->module->dontSeeResponseContainsJson([
|
||||
'responseCode' => 0,
|
||||
'data' => [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testFileUploadWithKeyValueArray()
|
||||
{
|
||||
$tmpFileName = tempnam('/tmp', 'test_');
|
||||
file_put_contents($tmpFileName, 'test data');
|
||||
$files = [
|
||||
'file' => $tmpFileName,
|
||||
];
|
||||
$this->module->sendPOST('/rest/file-upload', [], $files);
|
||||
$this->module->seeResponseContainsJson([
|
||||
'uploaded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testFileUploadWithFilesArray()
|
||||
{
|
||||
$tmpFileName = tempnam('/tmp', 'test_');
|
||||
file_put_contents($tmpFileName, 'test data');
|
||||
$files = [
|
||||
'file' => [
|
||||
'name' => 'file.txt',
|
||||
'type' => 'text/plain',
|
||||
'size' => 9,
|
||||
'tmp_name' => $tmpFileName,
|
||||
]
|
||||
];
|
||||
$this->module->sendPOST('/rest/file-upload', [], $files);
|
||||
$this->module->seeResponseContainsJson([
|
||||
'uploaded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCanInspectResultOfPhpBrowserRequest()
|
||||
{
|
||||
$this->phpBrowser->amOnPage('/rest/user/');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeResponseIsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue https://github.com/Codeception/Codeception/issues/1650
|
||||
*/
|
||||
public function testHostHeader()
|
||||
{
|
||||
if (getenv('dependencies') === 'lowest') {
|
||||
$this->markTestSkipped('This test can\'t pass with the lowest versions of dependencies');
|
||||
}
|
||||
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->module->seeResponseContains('host: "localhost:8010"');
|
||||
|
||||
$this->module->haveHttpHeader('Host', 'www.example.com');
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->module->seeResponseContains('host: "www.example.com"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue 4203 https://github.com/Codeception/Codeception/issues/4203
|
||||
* @depends testHostHeader
|
||||
*/
|
||||
public function testSessionHeaderBackup()
|
||||
{
|
||||
if (getenv('dependencies') === 'lowest') {
|
||||
$this->markTestSkipped('This test can\'t pass with the lowest versions of dependencies');
|
||||
}
|
||||
|
||||
$this->module->haveHttpHeader('Host', 'www.example.com');
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->module->seeResponseContains('host: "www.example.com"');
|
||||
|
||||
$session = $this->phpBrowser->_backupSession();
|
||||
|
||||
$this->module->haveHttpHeader('Host', 'www.localhost.com');
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->module->seeResponseContains('host: "www.localhost.com"');
|
||||
|
||||
$this->phpBrowser->_loadSession($session);
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->module->seeResponseContains('host: "www.example.com"');
|
||||
}
|
||||
|
||||
protected function shouldFail()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\AssertionFailedError');
|
||||
}
|
||||
|
||||
public function testGrabFromCurrentUrl()
|
||||
{
|
||||
$this->module->sendGET('/rest/http-host/');
|
||||
$this->assertEquals('/rest/http-host/', $this->phpBrowser->grabFromCurrentUrl());
|
||||
}
|
||||
}
|
||||
730
vendor/codeception/base/tests/unit/Codeception/Module/PhpBrowserTest.php
vendored
Normal file
730
vendor/codeception/base/tests/unit/Codeception/Module/PhpBrowserTest.php
vendored
Normal file
@@ -0,0 +1,730 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
require_once 'tests/data/app/data.php';
|
||||
require_once __DIR__ . '/TestsForBrowsers.php';
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class PhpBrowserTest extends TestsForBrowsers
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Module\PhpBrowser
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
protected $history = [];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\PhpBrowser(make_container());
|
||||
$url = 'http://localhost:8000';
|
||||
$this->module->_setConfig(array('url' => $url));
|
||||
$this->module->_initialize();
|
||||
$this->module->_before($this->makeTest());
|
||||
if (class_exists('GuzzleHttp\Url')) {
|
||||
$this->history = new \GuzzleHttp\Subscriber\History();
|
||||
$this->module->guzzle->getEmitter()->attach($this->history);
|
||||
} else {
|
||||
$this->module->guzzle->getConfig('handler')->push(\GuzzleHttp\Middleware::history($this->history));
|
||||
}
|
||||
}
|
||||
|
||||
private function getLastRequest()
|
||||
{
|
||||
if (is_array($this->history)) {
|
||||
return end($this->history)['request'];
|
||||
}
|
||||
|
||||
return $this->history->getLastRequest();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if ($this->module) {
|
||||
$this->module->_after($this->makeTest());
|
||||
}
|
||||
data::clean();
|
||||
}
|
||||
|
||||
protected function makeTest()
|
||||
{
|
||||
return Stub::makeEmpty('\Codeception\Test\Cept');
|
||||
}
|
||||
|
||||
public function testAjax()
|
||||
{
|
||||
$this->module->amOnPage('/');
|
||||
$this->module->sendAjaxGetRequest('/info');
|
||||
$this->assertNotNull(data::get('ajax'));
|
||||
|
||||
$this->module->sendAjaxPostRequest('/form/complex', array('show' => 'author'));
|
||||
$this->assertNotNull(data::get('ajax'));
|
||||
$post = data::get('form');
|
||||
$this->assertEquals('author', $post['show']);
|
||||
}
|
||||
|
||||
public function testLinksWithNonLatin()
|
||||
{
|
||||
$this->module->amOnPage('/info');
|
||||
$this->module->seeLink('Ссылочка');
|
||||
$this->module->click('Ссылочка');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/Codeception/Codeception/issues/4509
|
||||
*/
|
||||
public function testSeeTextAfterJSComparisionOperator()
|
||||
{
|
||||
$this->module->amOnPage('/info');
|
||||
$this->module->see('Text behind JS comparision');
|
||||
}
|
||||
|
||||
public function testSetMultipleCookies()
|
||||
{
|
||||
$this->module->amOnPage('/');
|
||||
$cookie_name_1 = 'test_cookie';
|
||||
$cookie_value_1 = 'this is a test';
|
||||
$this->module->setCookie($cookie_name_1, $cookie_value_1);
|
||||
|
||||
$cookie_name_2 = '2_test_cookie';
|
||||
$cookie_value_2 = '2 this is a test';
|
||||
$this->module->setCookie($cookie_name_2, $cookie_value_2);
|
||||
|
||||
$this->module->seeCookie($cookie_name_1);
|
||||
$this->module->seeCookie($cookie_name_2);
|
||||
$this->module->dontSeeCookie('evil_cookie');
|
||||
|
||||
$cookie1 = $this->module->grabCookie($cookie_name_1);
|
||||
$this->assertEquals($cookie_value_1, $cookie1);
|
||||
|
||||
$cookie2 = $this->module->grabCookie($cookie_name_2);
|
||||
$this->assertEquals($cookie_value_2, $cookie2);
|
||||
|
||||
$this->module->resetCookie($cookie_name_1);
|
||||
$this->module->dontSeeCookie($cookie_name_1);
|
||||
$this->module->seeCookie($cookie_name_2);
|
||||
$this->module->resetCookie($cookie_name_2);
|
||||
$this->module->dontSeeCookie($cookie_name_2);
|
||||
}
|
||||
|
||||
public function testSessionsHaveIndependentCookies()
|
||||
{
|
||||
$this->module->amOnPage('/');
|
||||
$cookie_name_1 = 'test_cookie';
|
||||
$cookie_value_1 = 'this is a test';
|
||||
$this->module->setCookie($cookie_name_1, $cookie_value_1);
|
||||
|
||||
$session = $this->module->_backupSession();
|
||||
$this->module->_initializeSession();
|
||||
|
||||
$this->module->dontSeeCookie($cookie_name_1);
|
||||
|
||||
$cookie_name_2 = '2_test_cookie';
|
||||
$cookie_value_2 = '2 this is a test';
|
||||
$this->module->setCookie($cookie_name_2, $cookie_value_2);
|
||||
|
||||
$this->module->_loadSession($session);
|
||||
|
||||
$this->module->dontSeeCookie($cookie_name_2);
|
||||
$this->module->seeCookie($cookie_name_1);
|
||||
}
|
||||
|
||||
public function testSubmitFormGet()
|
||||
{
|
||||
$I = $this->module;
|
||||
$I->amOnPage('/search');
|
||||
$I->submitForm('form', array('searchQuery' => 'test'));
|
||||
$I->see('Success');
|
||||
}
|
||||
|
||||
public function testHtmlRedirect()
|
||||
{
|
||||
$this->module->amOnPage('/redirect2');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
|
||||
$this->module->amOnPage('/redirect_interval');
|
||||
$this->module->seeCurrentUrlEquals('/redirect_interval');
|
||||
}
|
||||
|
||||
public function testHtmlRedirectWithParams()
|
||||
{
|
||||
$this->module->amOnPage('/redirect_params');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/search?one=1&two=2');
|
||||
}
|
||||
|
||||
public function testMetaRefresh()
|
||||
{
|
||||
$this->module->amOnPage('/redirect_meta_refresh');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
public function testMetaRefreshIsIgnoredIfIntervalIsLongerThanMaxInterval()
|
||||
{
|
||||
// prepare config
|
||||
$config = $this->module->_getConfig();
|
||||
$config['refresh_max_interval'] = 3; // less than 9
|
||||
$this->module->_reconfigure($config);
|
||||
$this->module->amOnPage('/redirect_meta_refresh');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/redirect_meta_refresh');
|
||||
}
|
||||
|
||||
public function testRefreshRedirect()
|
||||
{
|
||||
$this->module->amOnPage('/redirect3');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
|
||||
$this->module->amOnPage('/redirect_header_interval');
|
||||
$this->module->seeCurrentUrlEquals('/redirect_header_interval');
|
||||
$this->module->see('Welcome to test app!');
|
||||
}
|
||||
|
||||
public function testRedirectWithGetParams()
|
||||
{
|
||||
$this->module->amOnPage('/redirect4');
|
||||
$this->module->seeInCurrentUrl('/search?ln=test@gmail.com&sn=testnumber');
|
||||
$params = data::get('params');
|
||||
$this->assertContains('test@gmail.com', $params);
|
||||
}
|
||||
|
||||
public function testRedirectBaseUriHasPath()
|
||||
{
|
||||
// prepare config
|
||||
$config = $this->module->_getConfig();
|
||||
$config['url'] .= '/somepath'; // append path to the base url
|
||||
$this->module->_reconfigure($config);
|
||||
|
||||
$this->module->amOnPage('/redirect_base_uri_has_path');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/somepath/info');
|
||||
$this->module->see('Lots of valuable data here');
|
||||
}
|
||||
|
||||
public function testRedirectBaseUriHasPathAnd302Code()
|
||||
{
|
||||
// prepare config
|
||||
$config = $this->module->_getConfig();
|
||||
$config['url'] .= '/somepath'; // append path to the base url
|
||||
$this->module->_reconfigure($config);
|
||||
|
||||
$this->module->amOnPage('/redirect_base_uri_has_path_302');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/somepath/info');
|
||||
$this->module->see('Lots of valuable data here');
|
||||
}
|
||||
|
||||
public function testRelativeRedirect()
|
||||
{
|
||||
// test relative redirects where the effective request URI is in a
|
||||
// subdirectory
|
||||
$this->module->amOnPage('/relative/redirect');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/relative/info');
|
||||
|
||||
// also, test relative redirects where the effective request URI is not
|
||||
// in a subdirectory
|
||||
$this->module->amOnPage('/relative_redirect');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
public function testChainedRedirects()
|
||||
{
|
||||
$this->module->amOnPage('/redirect_twice');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
public function testDisabledRedirects()
|
||||
{
|
||||
$this->module->client->followRedirects(false);
|
||||
$this->module->amOnPage('/redirect_twice');
|
||||
$this->module->seeResponseCodeIs(302);
|
||||
$this->module->seeCurrentUrlEquals('/redirect_twice');
|
||||
}
|
||||
|
||||
public function testRedirectLimitReached()
|
||||
{
|
||||
$this->module->client->setMaxRedirects(1);
|
||||
try {
|
||||
$this->module->amOnPage('/redirect_twice');
|
||||
$this->assertTrue(false, 'redirect limit is not respected');
|
||||
} catch (\LogicException $e) {
|
||||
$this->assertEquals(
|
||||
'The maximum number (1) of redirections was reached.',
|
||||
$e->getMessage(),
|
||||
'redirect limit is respected'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectLimitNotReached()
|
||||
{
|
||||
$this->module->client->setMaxRedirects(2);
|
||||
$this->module->amOnPage('/redirect_twice');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
public function testLocationHeaderDoesNotRedirectWhenStatusCodeIs201()
|
||||
{
|
||||
$this->module->amOnPage('/location_201');
|
||||
$this->module->seeResponseCodeIs(201);
|
||||
$this->module->seeCurrentUrlEquals('/location_201');
|
||||
}
|
||||
|
||||
public function testRedirectToAnotherDomainUsingSchemalessUrl()
|
||||
{
|
||||
$this->module->amOnUrl('http://httpbin.org/redirect-to?url=//example.org/');
|
||||
$currentUrl = $this->module->client->getHistory()->current()->getUri();
|
||||
$this->assertSame('http://example.org/', $currentUrl);
|
||||
}
|
||||
|
||||
public function testSetCookieByHeader()
|
||||
{
|
||||
$this->module->amOnPage('/cookies2');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->seeCookie('a');
|
||||
$this->assertEquals('b', $this->module->grabCookie('a'));
|
||||
$this->module->seeCookie('c');
|
||||
}
|
||||
|
||||
public function testSettingContentTypeFromHtml()
|
||||
{
|
||||
$this->module->amOnPage('/content-iso');
|
||||
$charset = $this->module->client->getResponse()->getHeader('Content-Type');
|
||||
$this->assertEquals('text/html;charset=ISO-8859-1', $charset);
|
||||
}
|
||||
|
||||
public function testSettingCharsetFromHtml()
|
||||
{
|
||||
$this->module->amOnPage('/content-cp1251');
|
||||
$charset = $this->module->client->getResponse()->getHeader('Content-Type');
|
||||
$this->assertEquals('text/html;charset=windows-1251', $charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue https://github.com/Codeception/Codeception/issues/933
|
||||
*/
|
||||
public function testSubmitFormWithQueries()
|
||||
{
|
||||
$this->module->amOnPage('/form/example3');
|
||||
$this->module->seeElement('form');
|
||||
$this->module->submitForm('form', array(
|
||||
'name' => 'jon',
|
||||
));
|
||||
$form = data::get('form');
|
||||
$this->assertEquals('jon', $form['name']);
|
||||
$this->module->seeCurrentUrlEquals('/form/example3?validate=yes');
|
||||
}
|
||||
|
||||
public function testHeadersBySetHeader()
|
||||
{
|
||||
$this->module->setHeader('xxx', 'yyyy');
|
||||
$this->module->amOnPage('/');
|
||||
$this->assertTrue($this->getLastRequest()->hasHeader('xxx'));
|
||||
}
|
||||
|
||||
public function testDeleteHeaders()
|
||||
{
|
||||
$this->module->setHeader('xxx', 'yyyy');
|
||||
$this->module->deleteHeader('xxx');
|
||||
$this->module->amOnPage('/');
|
||||
$this->assertFalse($this->getLastRequest()->hasHeader('xxx'));
|
||||
}
|
||||
|
||||
public function testDeleteHeadersByEmptyValue()
|
||||
{
|
||||
$this->module->setHeader('xxx', 'yyyy');
|
||||
$this->module->setHeader('xxx', '');
|
||||
$this->module->amOnPage('/');
|
||||
$this->assertFalse($this->getLastRequest()->hasHeader('xxx'));
|
||||
}
|
||||
|
||||
public function testCurlOptions()
|
||||
{
|
||||
$this->module->_setConfig(array('url' => 'http://google.com', 'curl' => array('CURLOPT_NOBODY' => true)));
|
||||
$this->module->_initialize();
|
||||
if (method_exists($this->module->guzzle, 'getConfig')) {
|
||||
$config = $this->module->guzzle->getConfig();
|
||||
} else {
|
||||
$config = $this->module->guzzle->getDefaultOption('config');
|
||||
}
|
||||
$this->assertArrayHasKey('curl', $config);
|
||||
$this->assertArrayHasKey(CURLOPT_NOBODY, $config['curl']);
|
||||
}
|
||||
|
||||
|
||||
public function testCurlSslOptions()
|
||||
{
|
||||
if (getenv('WERCKER_ROOT')) {
|
||||
$this->markTestSkipped('Disabled on Wercker CI');
|
||||
}
|
||||
$this->module->_setConfig(array(
|
||||
'url' => 'https://google.com',
|
||||
'curl' => array(
|
||||
'CURLOPT_NOBODY' => true,
|
||||
'CURLOPT_SSL_CIPHER_LIST' => 'TLSv1',
|
||||
)));
|
||||
$this->module->_initialize();
|
||||
if (method_exists($this->module->guzzle, 'getConfig')) {
|
||||
$config = $this->module->guzzle->getConfig();
|
||||
} else {
|
||||
$config = $this->module->guzzle->getDefaultOption('config');
|
||||
}
|
||||
|
||||
$this->assertArrayHasKey('curl', $config);
|
||||
$this->assertArrayHasKey(CURLOPT_SSL_CIPHER_LIST, $config['curl']);
|
||||
$this->module->amOnPage('/');
|
||||
$this->assertSame('', $this->module->_getResponseContent(), 'CURLOPT_NOBODY setting is not respected');
|
||||
}
|
||||
|
||||
public function testHttpAuth()
|
||||
{
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->seeResponseCodeIs(401);
|
||||
$this->module->see('Unauthorized');
|
||||
$this->module->amHttpAuthenticated('davert', 'password');
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSee('Unauthorized');
|
||||
$this->module->see("Welcome, davert");
|
||||
$this->module->amHttpAuthenticated(null, null);
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->seeResponseCodeIs(401);
|
||||
$this->module->amHttpAuthenticated('davert', '123456');
|
||||
$this->module->amOnPage('/auth');
|
||||
$this->module->see('Forbidden');
|
||||
}
|
||||
|
||||
public function testRawGuzzle()
|
||||
{
|
||||
$code = $this->module->executeInGuzzle(function (\GuzzleHttp\Client $client) {
|
||||
$res = $client->get('/info');
|
||||
return $res->getStatusCode();
|
||||
});
|
||||
$this->assertEquals(200, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have a form with fields like
|
||||
* ```
|
||||
* <input type="file" name="foo" />
|
||||
* <input type="file" name="foo[bar]" />
|
||||
* ```
|
||||
* then only array variable will be used while simple variable will be ignored in php $_FILES
|
||||
* (eg $_FILES = [
|
||||
* foo => [
|
||||
* tmp_name => [
|
||||
* 'bar' => 'asdf'
|
||||
* ],
|
||||
* //...
|
||||
* ]
|
||||
* ]
|
||||
* )
|
||||
* (notice there is no entry for file "foo", only for file "foo[bar]"
|
||||
* this will check if current element contains inner arrays within it's keys
|
||||
* so we can ignore element itself and only process inner files
|
||||
*/
|
||||
public function testFormWithFilesInOnlyArray()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->module->amOnPage('/form/example13');
|
||||
$this->module->attachFile('foo', 'app/avatar.jpg');
|
||||
$this->module->attachFile('foo[bar]', 'app/avatar.jpg');
|
||||
$this->module->click('Submit');
|
||||
}
|
||||
|
||||
public function testDoubleSlash()
|
||||
{
|
||||
$I = $this->module;
|
||||
$I->amOnPage('/register');
|
||||
$I->submitForm('form', array('test' => 'test'));
|
||||
$formUrl = $this->module->client->getHistory()->current()->getUri();
|
||||
$formPath = parse_url($formUrl)['path'];
|
||||
$this->assertEquals($formPath, '/register');
|
||||
}
|
||||
|
||||
public function testFillFieldWithoutPage()
|
||||
{
|
||||
$this->setExpectedException("\\Codeception\\Exception\\ModuleException");
|
||||
$this->module->fillField('#name', 'Nothing special');
|
||||
}
|
||||
|
||||
public function testArrayFieldSubmitForm()
|
||||
{
|
||||
$this->skipForOldGuzzle();
|
||||
|
||||
$this->module->amOnPage('/form/example17');
|
||||
$this->module->submitForm(
|
||||
'form',
|
||||
[
|
||||
'FooBar' => ['bar' => 'booze'],
|
||||
'Food' => [
|
||||
'beer' => [
|
||||
'yum' => ['yeah' => 'crunked']
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$data = data::get('form');
|
||||
$this->assertEquals('booze', $data['FooBar']['bar']);
|
||||
$this->assertEquals('crunked', $data['Food']['beer']['yum']['yeah']);
|
||||
}
|
||||
|
||||
public function testCookiesForDomain()
|
||||
{
|
||||
$this->skipForOldGuzzle();
|
||||
|
||||
$mock = new \GuzzleHttp\Handler\MockHandler([
|
||||
new Response(200, ['X-Foo' => 'Bar']),
|
||||
]);
|
||||
$handler = \GuzzleHttp\HandlerStack::create($mock);
|
||||
$handler->push(\GuzzleHttp\Middleware::history($this->history));
|
||||
$client = new \GuzzleHttp\Client(['handler' => $handler, 'base_uri' => 'http://codeception.com']);
|
||||
$guzzleConnector = new \Codeception\Lib\Connector\Guzzle6();
|
||||
$guzzleConnector->setClient($client);
|
||||
$guzzleConnector->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie('hello', 'world'));
|
||||
$guzzleConnector->request('GET', 'http://codeception.com/');
|
||||
$this->assertArrayHasKey('cookies', $this->history[0]['options']);
|
||||
/** @var $cookie GuzzleHttp\Cookie\SetCookie **/
|
||||
$cookies = $this->history[0]['options']['cookies']->toArray();
|
||||
$cookie = reset($cookies);
|
||||
$this->assertEquals('codeception.com', $cookie['Domain']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/2653
|
||||
*/
|
||||
public function testSetCookiesByOptions()
|
||||
{
|
||||
$config = $this->module->_getConfig();
|
||||
$config['cookies'] = [
|
||||
[
|
||||
'Name' => 'foo',
|
||||
'Value' => 'bar1',
|
||||
],
|
||||
[
|
||||
'Name' => 'baz',
|
||||
'Value' => 'bar2',
|
||||
],
|
||||
];
|
||||
$this->module->_reconfigure($config);
|
||||
// this url redirects if cookies are present
|
||||
$this->module->amOnPage('/cookies');
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
private function skipForOldGuzzle()
|
||||
{
|
||||
if (class_exists('GuzzleHttp\Url')) {
|
||||
$this->markTestSkipped("Not for Guzzle <6");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/2234
|
||||
*/
|
||||
public function testEmptyValueOfCookie()
|
||||
{
|
||||
//set cookie
|
||||
$this->module->amOnPage('/cookies2');
|
||||
|
||||
$this->module->amOnPage('/unset-cookie');
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSeeCookie('a');
|
||||
}
|
||||
|
||||
public function testRequestApi()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleException');
|
||||
$response = $this->module->_request('POST', '/form/try', ['user' => 'davert']);
|
||||
$data = data::get('form');
|
||||
$this->assertEquals('davert', $data['user']);
|
||||
$this->assertInternalType('string', $response);
|
||||
$this->assertContains('Welcome to test app', $response);
|
||||
$this->module->click('Welcome to test app'); // page not loaded
|
||||
}
|
||||
|
||||
public function testLoadPageApi()
|
||||
{
|
||||
$this->module->_loadPage('POST', '/form/try', ['user' => 'davert']);
|
||||
$data = data::get('form');
|
||||
$this->assertEquals('davert', $data['user']);
|
||||
$this->module->see('Welcome to test app');
|
||||
$this->module->click('More info');
|
||||
$this->module->seeInCurrentUrl('/info');
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/2408
|
||||
*/
|
||||
public function testClickFailure()
|
||||
{
|
||||
$this->module->amOnPage('/info');
|
||||
$this->setExpectedException(
|
||||
'Codeception\Exception\ElementNotFound',
|
||||
"'Sign In!' is invalid CSS and XPath selector and Link or Button element with 'name=Sign In!' was not found"
|
||||
);
|
||||
$this->module->click('Sign In!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/2841
|
||||
*/
|
||||
public function testSubmitFormDoesNotKeepGetParameters()
|
||||
{
|
||||
$this->module->amOnPage('/form/bug2841?stuff=other');
|
||||
$this->module->fillField('#texty', 'thingshjere');
|
||||
$this->module->click('#submit-registration');
|
||||
$this->assertEmpty(data::get('query'), 'Query string is not empty');
|
||||
}
|
||||
|
||||
public function testClickLinkAndFillField()
|
||||
{
|
||||
$this->module->amOnPage('/info');
|
||||
$this->module->click('Sign in!');
|
||||
$this->module->seeCurrentUrlEquals('/login');
|
||||
$this->module->fillField('email', 'email@example.org');
|
||||
}
|
||||
|
||||
public function testClickSelectsClickableElementFromMatches()
|
||||
{
|
||||
$this->module->amOnPage('/form/multiple_matches');
|
||||
$this->module->click('Press Me!');
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
public function testClickSelectsClickableElementFromMatchesUsingCssLocator()
|
||||
{
|
||||
$this->module->amOnPage('/form/multiple_matches');
|
||||
$this->module->click(['css' => '.link']);
|
||||
$this->module->seeCurrentUrlEquals('/info');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\AssertionFailedError
|
||||
*/
|
||||
public function testClickingOnButtonOutsideFormDoesNotCauseFatalError()
|
||||
{
|
||||
$this->module->amOnPage('/form/button-not-in-form');
|
||||
$this->module->click('The Button');
|
||||
}
|
||||
|
||||
public function testSubmitFormWithoutEmptyOptionsInSelect()
|
||||
{
|
||||
$this->module->amOnPage('/form/bug3824');
|
||||
$this->module->submitForm('form', []);
|
||||
$this->module->dontSee('ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/3953
|
||||
*/
|
||||
public function testFillFieldInGetFormWithoutId()
|
||||
{
|
||||
$this->module->amOnPage('/form/bug3953');
|
||||
$this->module->selectOption('select_name', 'two');
|
||||
$this->module->fillField('search_name', 'searchterm');
|
||||
$this->module->click('Submit');
|
||||
$params = data::get('query');
|
||||
$this->assertEquals('two', $params['select_name']);
|
||||
$this->assertEquals('searchterm', $params['search_name']);
|
||||
}
|
||||
|
||||
public function testGrabPageSourceWhenNotOnPage()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
'\Codeception\Exception\ModuleException',
|
||||
'Page not loaded. Use `$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it'
|
||||
);
|
||||
$this->module->grabPageSource();
|
||||
}
|
||||
|
||||
public function testGrabPageSourceWhenOnPage()
|
||||
{
|
||||
$this->module->amOnPage('/minimal');
|
||||
$sourceExpected =
|
||||
<<<HTML
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
Minimal page
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Minimal page
|
||||
</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
HTML
|
||||
;
|
||||
$sourceActual = $this->module->grabPageSource();
|
||||
$this->assertXmlStringEqualsXmlString($sourceExpected, $sourceActual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @issue https://github.com/Codeception/Codeception/issues/4383
|
||||
*/
|
||||
public function testSecondAmOnUrlWithEmptyPath()
|
||||
{
|
||||
$this->module->amOnUrl('http://localhost:8000/info');
|
||||
$this->module->see('Lots of valuable data here');
|
||||
$this->module->amOnUrl('http://localhost:8000');
|
||||
$this->module->dontSee('Lots of valuable data here');
|
||||
}
|
||||
|
||||
public function testSetUserAgentUsingConfig()
|
||||
{
|
||||
$this->module->_setConfig(['headers' => ['User-Agent' => 'Codeception User Agent Test 1.0']]);
|
||||
$this->module->_initialize();
|
||||
|
||||
$this->module->amOnPage('/user-agent');
|
||||
$response = $this->module->grabPageSource();
|
||||
$this->assertEquals('Codeception User Agent Test 1.0', $response, 'Incorrect user agent');
|
||||
}
|
||||
|
||||
public function testIfStatusCodeIsWithin2xxRange()
|
||||
{
|
||||
$this->module->amOnPage('https://httpstat.us/200');
|
||||
$this->module->seeResponseCodeIsSuccessful();
|
||||
|
||||
$this->module->amOnPage('https://httpstat.us/299');
|
||||
$this->module->seeResponseCodeIsSuccessful();
|
||||
}
|
||||
|
||||
public function testIfStatusCodeIsWithin3xxRange()
|
||||
{
|
||||
$this->module->amOnPage('https://httpstat.us/300');
|
||||
$this->module->seeResponseCodeIsRedirection();
|
||||
|
||||
$this->module->amOnPage('https://httpstat.us/399');
|
||||
$this->module->seeResponseCodeIsRedirection();
|
||||
}
|
||||
|
||||
public function testIfStatusCodeIsWithin4xxRange()
|
||||
{
|
||||
$this->module->amOnPage('https://httpstat.us/400');
|
||||
$this->module->seeResponseCodeIsClientError();
|
||||
|
||||
$this->module->amOnPage('https://httpstat.us/499');
|
||||
$this->module->seeResponseCodeIsClientError();
|
||||
}
|
||||
|
||||
public function testIfStatusCodeIsWithin5xxRange()
|
||||
{
|
||||
$this->module->amOnPage('https://httpstat.us/500');
|
||||
$this->module->seeResponseCodeIsServerError();
|
||||
|
||||
$this->module->amOnPage('https://httpstat.us/599');
|
||||
$this->module->seeResponseCodeIsServerError();
|
||||
}
|
||||
}
|
||||
1387
vendor/codeception/base/tests/unit/Codeception/Module/RedisTest.php
vendored
Normal file
1387
vendor/codeception/base/tests/unit/Codeception/Module/RedisTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
456
vendor/codeception/base/tests/unit/Codeception/Module/RestTest.php
vendored
Normal file
456
vendor/codeception/base/tests/unit/Codeception/Module/RestTest.php
vendored
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Codeception\Util\Stub as Stub;
|
||||
|
||||
/**
|
||||
* Class RestTest
|
||||
* @group appveyor
|
||||
*/
|
||||
class RestTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var \Codeception\Module\REST
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$connector = new \Codeception\Lib\Connector\Universal();
|
||||
$connector->setIndex(\Codeception\Configuration::dataDir() . '/rest/index.php');
|
||||
|
||||
$connectionModule = new \Codeception\Module\UniversalFramework(make_container());
|
||||
$connectionModule->client = $connector;
|
||||
$connectionModule->_initialize();
|
||||
$this->module = Stub::make('\Codeception\Module\REST');
|
||||
$this->module->_inject($connectionModule);
|
||||
$this->module->_initialize();
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
$this->module->client->setServerParameters([
|
||||
'SCRIPT_FILENAME' => 'index.php',
|
||||
'SCRIPT_NAME' => 'index',
|
||||
'SERVER_NAME' => 'localhost',
|
||||
'SERVER_PROTOCOL' => 'http'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testConflictsWithAPI()
|
||||
{
|
||||
$this->assertInstanceOf('Codeception\Lib\Interfaces\ConflictsWithModule', $this->module);
|
||||
$this->assertEquals('Codeception\Lib\Interfaces\API', $this->module->_conflicts());
|
||||
}
|
||||
|
||||
private function setStubResponse($response)
|
||||
{
|
||||
$connectionModule = Stub::make('\Codeception\Module\UniversalFramework', ['_getResponseContent' => $response]);
|
||||
$this->module->_inject($connectionModule);
|
||||
$this->module->_initialize();
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
|
||||
public function testBeforeHookResetsVariables()
|
||||
{
|
||||
$this->module->haveHttpHeader('Origin', 'http://www.example.com');
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$server = $this->module->client->getInternalRequest()->getServer();
|
||||
$this->assertArrayHasKey('HTTP_ORIGIN', $server);
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$server = $this->module->client->getInternalRequest()->getServer();
|
||||
$this->assertArrayNotHasKey('HTTP_ORIGIN', $server);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->module->sendGET('/rest/user/');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContains('davert');
|
||||
$this->module->seeResponseContainsJson(['name' => 'davert']);
|
||||
$this->module->seeResponseCodeIs(200);
|
||||
$this->module->dontSeeResponseCodeIs(404);
|
||||
}
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$this->module->sendPOST('/rest/user/', ['name' => 'john']);
|
||||
$this->module->seeResponseContains('john');
|
||||
$this->module->seeResponseContainsJson(['name' => 'john']);
|
||||
}
|
||||
|
||||
public function testPut()
|
||||
{
|
||||
$this->module->sendPUT('/rest/user/', ['name' => 'laura']);
|
||||
$this->module->seeResponseContains('davert@mail.ua');
|
||||
$this->module->seeResponseContainsJson(['name' => 'laura']);
|
||||
$this->module->dontSeeResponseContainsJson(['name' => 'john']);
|
||||
}
|
||||
|
||||
public function testGrabDataFromResponseByJsonPath()
|
||||
{
|
||||
$this->module->sendGET('/rest/user/');
|
||||
// simple assoc array
|
||||
$this->assertEquals(['davert@mail.ua'], $this->module->grabDataFromResponseByJsonPath('$.email'));
|
||||
// nested assoc array
|
||||
$this->assertEquals(['Kyiv'], $this->module->grabDataFromResponseByJsonPath('$.address.city'));
|
||||
// nested index array
|
||||
$this->assertEquals(['DavertMik'], $this->module->grabDataFromResponseByJsonPath('$.aliases[0]'));
|
||||
// empty if data not found
|
||||
$this->assertEquals([], $this->module->grabDataFromResponseByJsonPath('$.address.street'));
|
||||
}
|
||||
|
||||
public function testValidJson()
|
||||
{
|
||||
$this->setStubResponse('{"xxx": "yyy"}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->setStubResponse('{"xxx": "yyy", "zzz": ["a","b"]}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseEquals('{"xxx": "yyy", "zzz": ["a","b"]}');
|
||||
}
|
||||
|
||||
public function testInvalidJson()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
$this->setStubResponse('{xxx = yyy}');
|
||||
$this->module->seeResponseIsJson();
|
||||
}
|
||||
public function testValidXml()
|
||||
{
|
||||
$this->setStubResponse('<xml></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
$this->setStubResponse('<xml><name>John</name></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
$this->module->seeResponseEquals('<xml><name>John</name></xml>');
|
||||
}
|
||||
|
||||
public function testXmlResponseEquals()
|
||||
{
|
||||
$this->setStubResponse('<xml></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
$this->module->seeXmlResponseEquals('<xml></xml>');
|
||||
}
|
||||
|
||||
public function testInvalidXml()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
|
||||
$this->setStubResponse('<xml><name>John</surname></xml>');
|
||||
$this->module->seeResponseIsXml();
|
||||
}
|
||||
|
||||
public function testSeeInJsonResponse()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'{"ticket": {"title": "Bug should be fixed", "user": {"name": "Davert"}, "labels": null}}'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContainsJson(['name' => 'Davert']);
|
||||
$this->module->seeResponseContainsJson(['user' => ['name' => 'Davert']]);
|
||||
$this->module->seeResponseContainsJson(['ticket' => ['title' => 'Bug should be fixed']]);
|
||||
$this->module->seeResponseContainsJson(['ticket' => ['user' => ['name' => 'Davert']]]);
|
||||
$this->module->seeResponseContainsJson(['ticket' => ['labels' => null]]);
|
||||
}
|
||||
|
||||
public function testSeeInJsonCollection()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":"42","tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseContainsJson(['tags' => ['web-dev', 'java']]);
|
||||
$this->module->seeResponseContainsJson(['user' => 'John Doe', 'age' => 27]);
|
||||
$this->module->seeResponseContainsJson([['user' => 'John Doe', 'age' => 27]]);
|
||||
$this->module->seeResponseContainsJson(
|
||||
[['user' => 'Blacknoir', 'age' => 42], ['user' => 'John Doe', 'age' => "27"]]
|
||||
);
|
||||
}
|
||||
|
||||
public function testArrayJson()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"id":1,"title": "Bug should be fixed"},{"title": "Feature should be implemented","id":2}]'
|
||||
);
|
||||
$this->module->seeResponseContainsJson(['id' => 1]);
|
||||
}
|
||||
|
||||
public function testDontSeeInJson()
|
||||
{
|
||||
$this->setStubResponse('{"ticket": {"title": "Bug should be fixed", "user": {"name": "Davert"}}}');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->dontSeeResponseContainsJson(['name' => 'Davet']);
|
||||
$this->module->dontSeeResponseContainsJson(['user' => ['name' => 'Davet']]);
|
||||
$this->module->dontSeeResponseContainsJson(['user' => ['title' => 'Bug should be fixed']]);
|
||||
}
|
||||
|
||||
public function testApplicationJsonIncludesJsonAsContent()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendPOST('/', ['name' => 'john']);
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertContains('application/json', $request->getServer());
|
||||
$server = $request->getServer();
|
||||
$this->assertEquals('application/json', $server['HTTP_CONTENT_TYPE']);
|
||||
$this->assertJson($request->getContent());
|
||||
$this->assertEmpty($request->getParameters());
|
||||
}
|
||||
|
||||
public function testApplicationJsonIncludesObjectSerialized()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendPOST('/', new JsonSerializedItem());
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertContains('application/json', $request->getServer());
|
||||
$this->assertJson($request->getContent());
|
||||
}
|
||||
|
||||
public function testGetApplicationJsonNotIncludesJsonAsContent()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/json');
|
||||
$this->module->sendGET('/', ['name' => 'john']);
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertNull($request->getContent());
|
||||
$this->assertContains('john', $request->getParameters());
|
||||
}
|
||||
|
||||
public function testUrlIsFull()
|
||||
{
|
||||
$this->module->sendGET('/api/v1/users');
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertEquals('http://localhost/api/v1/users', $request->getUri());
|
||||
}
|
||||
|
||||
public function testSeeHeaders()
|
||||
{
|
||||
$response = new \Symfony\Component\BrowserKit\Response("", 200, [
|
||||
'Cache-Control' => ['no-cache', 'no-store'],
|
||||
'Content_Language' => 'en-US'
|
||||
]);
|
||||
$this->module->client->mockResponse($response);
|
||||
$this->module->sendGET('/');
|
||||
$this->module->seeHttpHeader('Cache-Control');
|
||||
$this->module->seeHttpHeader('content_language', 'en-US');
|
||||
$this->module->seeHttpHeader('Content-Language', 'en-US');
|
||||
$this->module->dontSeeHttpHeader('Content-Language', 'en-RU');
|
||||
$this->module->dontSeeHttpHeader('Content-Language1');
|
||||
$this->module->seeHttpHeaderOnce('Content-Language');
|
||||
$this->assertEquals('en-US', $this->module->grabHttpHeader('Content-Language'));
|
||||
$this->assertEquals('no-cache', $this->module->grabHttpHeader('Cache-Control'));
|
||||
$this->assertEquals(['no-cache', 'no-store'], $this->module->grabHttpHeader('Cache-Control', false));
|
||||
}
|
||||
|
||||
public function testSeeHeadersOnce()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$response = new \Symfony\Component\BrowserKit\Response("", 200, [
|
||||
'Cache-Control' => ['no-cache', 'no-store'],
|
||||
]);
|
||||
$this->module->client->mockResponse($response);
|
||||
$this->module->sendGET('/');
|
||||
$this->module->seeHttpHeaderOnce('Cache-Control');
|
||||
}
|
||||
|
||||
public function testSeeResponseJsonMatchesXpath()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseJsonMatchesXpath('//user');
|
||||
}
|
||||
|
||||
public function testSeeResponseJsonMatchesJsonPath()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->seeResponseJsonMatchesJsonPath('$[*].user');
|
||||
$this->module->seeResponseJsonMatchesJsonPath('$[1].tags');
|
||||
}
|
||||
|
||||
|
||||
public function testDontSeeResponseJsonMatchesJsonPath()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->dontSeeResponseJsonMatchesJsonPath('$[*].profile');
|
||||
}
|
||||
|
||||
public function testDontSeeResponseJsonMatchesXpath()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->dontSeeResponseJsonMatchesXpath('//status');
|
||||
}
|
||||
|
||||
public function testDontSeeResponseJsonMatchesXpathFails()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->dontSeeResponseJsonMatchesXpath('//user');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Issue https://github.com/Codeception/Codeception/issues/2775
|
||||
*/
|
||||
public function testSeeResponseJsonMatchesXPathWorksWithAmpersand()
|
||||
{
|
||||
$this->setStubResponse('{ "product":[ { "category":[ { "comment":"something & something" } ] } ] }');
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseJsonMatchesXpath('//comment');
|
||||
}
|
||||
|
||||
|
||||
public function testSeeResponseJsonMatchesJsonPathFails()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->setStubResponse(
|
||||
'[{"user":"Blacknoir","age":27,"tags":["wed-dev","php"]},'
|
||||
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseJsonMatchesJsonPath('$[*].profile');
|
||||
}
|
||||
|
||||
|
||||
public function testStructuredJsonPathAndXPath()
|
||||
{
|
||||
$this->setStubResponse(
|
||||
'{ "store": {"book": [{ "category": "reference", "author": "Nigel Rees", '
|
||||
. '"title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", '
|
||||
. '"title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", '
|
||||
. '"title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", '
|
||||
. '"author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", '
|
||||
. '"price": 22.99 } ], "bicycle": {"color": "red", "price": 19.95 } } }'
|
||||
);
|
||||
$this->module->seeResponseIsJson();
|
||||
$this->module->seeResponseJsonMatchesXpath('//book/category');
|
||||
$this->module->seeResponseJsonMatchesJsonPath('$..book');
|
||||
$this->module->seeResponseJsonMatchesJsonPath('$.store.book[2].author');
|
||||
$this->module->dontSeeResponseJsonMatchesJsonPath('$.invalid');
|
||||
$this->module->dontSeeResponseJsonMatchesJsonPath('$.store.book.*.invalidField');
|
||||
}
|
||||
|
||||
public function testApplicationJsonSubtypeIncludesObjectSerialized()
|
||||
{
|
||||
$this->module->haveHttpHeader('Content-Type', 'application/resource+json');
|
||||
$this->module->sendPOST('/', new JsonSerializedItem());
|
||||
/** @var $request \Symfony\Component\BrowserKit\Request **/
|
||||
$request = $this->module->client->getRequest();
|
||||
$this->assertContains('application/resource+json', $request->getServer());
|
||||
$this->assertJson($request->getContent());
|
||||
}
|
||||
|
||||
public function testJsonTypeMatches()
|
||||
{
|
||||
$this->setStubResponse('{"xxx": "yyy", "user_id": 1}');
|
||||
$this->module->seeResponseMatchesJsonType(['xxx' => 'string', 'user_id' => 'integer:<10']);
|
||||
$this->module->dontSeeResponseMatchesJsonType(['xxx' => 'integer', 'user_id' => 'integer:<10']);
|
||||
}
|
||||
|
||||
public function testJsonTypeMatchesWithJsonPath()
|
||||
{
|
||||
$this->setStubResponse('{"users": [{ "name": "davert"}, {"id": 1}]}');
|
||||
$this->module->seeResponseMatchesJsonType(['name' => 'string'], '$.users[0]');
|
||||
$this->module->seeResponseMatchesJsonType(['id' => 'integer'], '$.users[1]');
|
||||
$this->module->dontSeeResponseMatchesJsonType(['id' => 'integer'], '$.users[0]');
|
||||
}
|
||||
|
||||
public function testMatchJsonTypeFailsWithNiceMessage()
|
||||
{
|
||||
$this->setStubResponse('{"xxx": "yyy", "user_id": 1}');
|
||||
try {
|
||||
$this->module->seeResponseMatchesJsonType(['zzz' => 'string']);
|
||||
$this->fail('it had to throw exception');
|
||||
} catch (PHPUnit\Framework\AssertionFailedError $e) {
|
||||
$this->assertEquals('Key `zzz` doesn\'t exist in {"xxx":"yyy","user_id":1}', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testDontMatchJsonTypeFailsWithNiceMessage()
|
||||
{
|
||||
$this->setStubResponse('{"xxx": "yyy", "user_id": 1}');
|
||||
try {
|
||||
$this->module->dontSeeResponseMatchesJsonType(['xxx' => 'string']);
|
||||
$this->fail('it had to throw exception');
|
||||
} catch (PHPUnit\Framework\AssertionFailedError $e) {
|
||||
$this->assertEquals('Unexpectedly response matched: {"xxx":"yyy","user_id":1}', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeeResponseIsJsonFailsWhenResponseIsEmpty()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->setStubResponse('');
|
||||
$this->module->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function testSeeResponseIsJsonFailsWhenResponseIsInvalidJson()
|
||||
{
|
||||
$this->shouldFail();
|
||||
$this->setStubResponse('{');
|
||||
$this->module->seeResponseIsJson();
|
||||
}
|
||||
|
||||
public function testSeeResponseJsonMatchesXpathCanHandleResponseWithOneElement()
|
||||
{
|
||||
$this->setStubResponse('{"success": 1}');
|
||||
$this->module->seeResponseJsonMatchesXpath('//success');
|
||||
}
|
||||
|
||||
public function testSeeResponseJsonMatchesXpathCanHandleResponseWithTwoElements()
|
||||
{
|
||||
$this->setStubResponse('{"success": 1, "info": "test"}');
|
||||
$this->module->seeResponseJsonMatchesXpath('//success');
|
||||
}
|
||||
|
||||
public function testSeeResponseJsonMatchesXpathCanHandleResponseWithOneSubArray()
|
||||
{
|
||||
$this->setStubResponse('{"array": {"success": 1}}');
|
||||
$this->module->seeResponseJsonMatchesXpath('//array/success');
|
||||
}
|
||||
|
||||
public function testSeeBinaryResponseEquals()
|
||||
{
|
||||
$data = base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
|
||||
$this->setStubResponse($data);
|
||||
$this->module->seeBinaryResponseEquals(md5($data));
|
||||
}
|
||||
|
||||
public function testDontSeeBinaryResponseEquals()
|
||||
{
|
||||
$data = base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
|
||||
$this->setStubResponse($data);
|
||||
$this->module->dontSeeBinaryResponseEquals('024f615102cdb3c8c7cf75cdc5a83d15');
|
||||
}
|
||||
|
||||
public function testAmDigestAuthenticatedThrowsExceptionWithFunctionalModules()
|
||||
{
|
||||
$this->setExpectedException('\Codeception\Exception\ModuleException', 'Not supported by functional modules');
|
||||
$this->module->amDigestAuthenticated('username', 'password');
|
||||
}
|
||||
|
||||
protected function shouldFail()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit\Framework\AssertionFailedError');
|
||||
}
|
||||
}
|
||||
|
||||
class JsonSerializedItem implements JsonSerializable
|
||||
{
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return array("hello" => "world");
|
||||
}
|
||||
}
|
||||
113
vendor/codeception/base/tests/unit/Codeception/Module/SFTPTest.php
vendored
Normal file
113
vendor/codeception/base/tests/unit/Codeception/Module/SFTPTest.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
|
||||
/**
|
||||
* Module for testing remote ftp systems.
|
||||
*
|
||||
* ## Status
|
||||
*
|
||||
* Maintainer: **nathanmac**
|
||||
* Stability: **stable**
|
||||
* Contact: nathan.macnamara@outlook.com
|
||||
*
|
||||
*/
|
||||
class SFTPTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $config = array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 22,
|
||||
'tmp' => 'temp',
|
||||
'user' => 'user',
|
||||
'password' => 'password',
|
||||
'type' => 'sftp'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\FTP
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\FTP(make_container());
|
||||
$this->module->_setConfig($this->config);
|
||||
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled Test - for travis testing, requires testing server
|
||||
*/
|
||||
public function flow()
|
||||
{
|
||||
$this->assertEquals('/', $this->module->grabDirectory());
|
||||
|
||||
$this->module->makeDir('TESTING');
|
||||
$this->module->amInPath('TESTING');
|
||||
$this->assertEquals('/TESTING', $this->module->grabDirectory());
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
|
||||
$this->module->writeToFile('test_ftp_567.txt', 'some data added here');
|
||||
$this->module->writeToFile('test_ftp_678.txt', 'some data added here');
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
$this->assertContains('test_ftp_123.txt', $files);
|
||||
$this->assertContains('test_ftp_567.txt', $files);
|
||||
$this->assertContains('test_ftp_678.txt', $files);
|
||||
|
||||
$this->module->seeFileFound('test_ftp_123.txt');
|
||||
$this->module->dontSeeFileFound('test_ftp_321.txt');
|
||||
$this->module->seeFileFoundMatches('/^test_ftp_([0-9]{3}).txt$/');
|
||||
$this->module->dontSeeFileFoundMatches('/^test_([0-9]{3})_ftp.txt$/');
|
||||
|
||||
$this->assertGreaterThan(0, $this->module->grabFileCount());
|
||||
$this->assertGreaterThan(0, $this->module->grabFileSize('test_ftp_678.txt'));
|
||||
$this->assertGreaterThan(0, $this->module->grabFileModified('test_ftp_678.txt'));
|
||||
|
||||
$this->module->openFile('test_ftp_567.txt');
|
||||
$this->module->deleteThisFile();
|
||||
$this->module->dontSeeFileFound('test_ftp_567.txt');
|
||||
|
||||
$this->module->openFile('test_ftp_123.txt');
|
||||
$this->module->seeInThisFile('data');
|
||||
|
||||
$this->module->dontSeeInThisFile('banana');
|
||||
$this->module->seeFileContentsEqual('some data added here');
|
||||
|
||||
$this->module->renameFile('test_ftp_678.txt', 'test_ftp_987.txt');
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
$this->assertNotContains('test_ftp_678.txt', $files);
|
||||
$this->assertContains('test_ftp_987.txt', $files);
|
||||
|
||||
$this->module->deleteFile('test_ftp_123.txt');
|
||||
|
||||
$files = $this->module->grabFileList();
|
||||
$this->assertNotContains('test_ftp_123.txt', $files);
|
||||
|
||||
$this->module->amInPath('/');
|
||||
|
||||
$this->assertEquals('/', $this->module->grabDirectory());
|
||||
|
||||
$this->module->renameDir('TESTING', 'TESTING_NEW');
|
||||
|
||||
$this->module->deleteDir('TESTING_NEW');
|
||||
|
||||
// Test Clearing the Directory
|
||||
$this->module->makeDir('TESTING');
|
||||
$this->module->amInPath('TESTING');
|
||||
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
|
||||
$this->module->amInPath('/');
|
||||
$this->assertGreaterThan(0, $this->module->grabFileCount('TESTING'));
|
||||
$this->module->cleanDir('TESTING');
|
||||
$this->assertEquals(0, $this->module->grabFileCount('TESTING'));
|
||||
$this->module->deleteDir('TESTING');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->module->_after(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
}
|
||||
}
|
||||
29
vendor/codeception/base/tests/unit/Codeception/Module/SequenceTest.php
vendored
Normal file
29
vendor/codeception/base/tests/unit/Codeception/Module/SequenceTest.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class SequenceTest extends \Codeception\Test\Unit
|
||||
{
|
||||
// tests
|
||||
public function testSequences()
|
||||
{
|
||||
$module = new \Codeception\Module\Sequence(make_container());
|
||||
$this->assertNotEquals(sq(), sq());
|
||||
$this->assertNotEquals(sq(1), sq(2));
|
||||
$this->assertEquals(sq(1), sq(1));
|
||||
$old = sq(1);
|
||||
$module->_after($this);
|
||||
$this->assertNotEquals($old, sq(1));
|
||||
}
|
||||
|
||||
public function testSuiteSequences()
|
||||
{
|
||||
$module = new \Codeception\Module\Sequence(make_container());
|
||||
$this->assertNotEquals(sqs(), sqs());
|
||||
$this->assertNotEquals(sqs(1), sqs(2));
|
||||
$this->assertEquals(sqs(1), sqs(1));
|
||||
$old = sqs(1);
|
||||
$module->_after($this);
|
||||
$this->assertEquals($old, sqs(1));
|
||||
$module->_afterSuite();
|
||||
$this->assertNotEquals($old, sqs(1));
|
||||
}
|
||||
}
|
||||
143
vendor/codeception/base/tests/unit/Codeception/Module/SoapTest.php
vendored
Normal file
143
vendor/codeception/base/tests/unit/Codeception/Module/SoapTest.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use Codeception\Util\Soap as SoapUtil;
|
||||
|
||||
/**
|
||||
* Class SoapTest
|
||||
* @group appveyor
|
||||
*/
|
||||
class SoapTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Codeception\Module\Soap
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
protected $layout;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->module = new \Codeception\Module\SOAP(make_container());
|
||||
$this->module->_setConfig(array(
|
||||
'schema' => 'http://www.w3.org/2001/xml.xsd',
|
||||
'endpoint' => 'http://codeception.com/api/wsdl'
|
||||
));
|
||||
$this->layout = \Codeception\Configuration::dataDir().'/xml/layout.xml';
|
||||
$this->module->isFunctional = true;
|
||||
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
|
||||
$this->module->client = Stub::makeEmpty('\Codeception\Lib\Connector\Universal');
|
||||
}
|
||||
|
||||
public function testXmlIsBuilt()
|
||||
{
|
||||
$dom = new \DOMDocument();
|
||||
$dom->load($this->layout);
|
||||
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
|
||||
$this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML());
|
||||
}
|
||||
|
||||
public function testBuildHeaders()
|
||||
{
|
||||
$this->module->haveSoapHeader('AuthHeader', ['username' => 'davert', 'password' => '123456']);
|
||||
$dom = new \DOMDocument();
|
||||
$dom->load($this->layout);
|
||||
$header = $dom->createElement('AuthHeader');
|
||||
$header->appendChild($dom->createElement('username', 'davert'));
|
||||
$header->appendChild($dom->createElement('password', '123456'));
|
||||
$dom->documentElement->getElementsByTagName('Header')->item(0)->appendChild($header);
|
||||
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
|
||||
}
|
||||
|
||||
public function testBuildRequest()
|
||||
{
|
||||
$this->module->sendSoapRequest('KillHumans', "<item><id>1</id><subitem>2</subitem></item>");
|
||||
$this->assertNotNull($this->module->xmlRequest);
|
||||
$dom = new \DOMDocument();
|
||||
$dom->load($this->layout);
|
||||
$body = $dom->createElement('item');
|
||||
$body->appendChild($dom->createElement('id', 1));
|
||||
$body->appendChild($dom->createElement('subitem', 2));
|
||||
$request = $dom->createElement('ns:KillHumans');
|
||||
$request->appendChild($body);
|
||||
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
|
||||
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
|
||||
}
|
||||
|
||||
public function testBuildRequestWithDomNode()
|
||||
{
|
||||
$dom = new \DOMDocument();
|
||||
$dom->load($this->layout);
|
||||
$body = $dom->createElement('item');
|
||||
$body->appendChild($dom->createElement('id', 1));
|
||||
$body->appendChild($dom->createElement('subitem', 2));
|
||||
$request = $dom->createElement('ns:KillHumans');
|
||||
$request->appendChild($body);
|
||||
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
|
||||
|
||||
$this->module->sendSoapRequest('KillHumans', $body);
|
||||
$this->assertEqualXMLStructure($this->module->xmlRequest->documentElement, $dom->documentElement);
|
||||
}
|
||||
|
||||
public function testSeeXmlIncludes()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>');
|
||||
$this->module->seeSoapResponseIncludes('<a a2="2" a1="1" >123</a>');
|
||||
}
|
||||
|
||||
public function testSeeXmlContainsXPath()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>');
|
||||
$this->module->seeSoapResponseContainsXPath('//doc/a[@a2=2 and @a1=1]');
|
||||
}
|
||||
|
||||
public function testSeeXmlNotContainsXPath()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>');
|
||||
$this->module->dontSeeSoapResponseContainsXPath('//doc/a[@a2=2 and @a31]');
|
||||
}
|
||||
|
||||
|
||||
public function testSeeXmlEquals()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc>';
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->loadXML($xml);
|
||||
$this->module->seeSoapResponseEquals($xml);
|
||||
}
|
||||
|
||||
public function testSeeXmlIncludesWithBuilder()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?>'."\n".' <doc><a a2="2" a1="1" >123</a></doc>');
|
||||
$xml = SoapUtil::request()->doc->a
|
||||
->attr('a2', '2')
|
||||
->attr('a1', '1')
|
||||
->val('123');
|
||||
$this->module->seeSoapResponseIncludes($xml);
|
||||
}
|
||||
|
||||
public function testGrabTextFrom()
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$this->module->xmlResponse = $dom;
|
||||
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?><doc><node>123</node></doc>');
|
||||
$res = $this->module->grabTextContentFrom('doc node');
|
||||
$this->assertEquals('123', $res);
|
||||
$res = $this->module->grabTextContentFrom('descendant-or-self::doc/descendant::node');
|
||||
$this->assertEquals('123', $res);
|
||||
}
|
||||
}
|
||||
65
vendor/codeception/base/tests/unit/Codeception/Module/TestsForBrowsers.php
vendored
Normal file
65
vendor/codeception/base/tests/unit/Codeception/Module/TestsForBrowsers.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
require_once 'TestsForWeb.php';
|
||||
/**
|
||||
* Author: davert
|
||||
* Date: 13.01.12
|
||||
*
|
||||
* Class TestsForMink
|
||||
* Description:
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class TestsForBrowsers extends TestsForWeb
|
||||
{
|
||||
|
||||
public function testAmOnSubdomain()
|
||||
{
|
||||
$this->module->_reconfigure(array('url' => 'http://google.com'));
|
||||
$this->module->amOnSubdomain('user');
|
||||
$this->assertEquals('http://user.google.com', $this->module->_getUrl());
|
||||
|
||||
$this->module->_reconfigure(array('url' => 'http://www.google.com'));
|
||||
$this->module->amOnSubdomain('user');
|
||||
$this->assertEquals('http://user.google.com', $this->module->_getUrl());
|
||||
}
|
||||
|
||||
public function testOpenAbsoluteUrls()
|
||||
{
|
||||
$this->module->amOnUrl('http://localhost:8000/');
|
||||
$this->module->see('Welcome to test app!', 'h1');
|
||||
$this->module->amOnUrl('http://127.0.0.1:8000/info');
|
||||
$this->module->see('Information', 'h1');
|
||||
$this->module->amOnPage('/form/empty');
|
||||
$this->module->seeCurrentUrlEquals('/form/empty');
|
||||
$this->assertEquals('http://127.0.0.1:8000', $this->module->_getUrl(), 'Host has changed');
|
||||
}
|
||||
|
||||
public function testHeadersRedirect()
|
||||
{
|
||||
$this->module->amOnPage('/redirect');
|
||||
$this->module->seeInCurrentUrl('info');
|
||||
}
|
||||
|
||||
/*
|
||||
* https://github.com/Codeception/Codeception/issues/1510
|
||||
*/
|
||||
public function testSiteRootRelativePathsForBasePathWithSubdir()
|
||||
{
|
||||
$this->module->_reconfigure(array('url' => 'http://localhost:8000/form'));
|
||||
$this->module->amOnPage('/relative_siteroot');
|
||||
$this->module->seeInCurrentUrl('/form/relative_siteroot');
|
||||
$this->module->submitForm('form', array(
|
||||
'test' => 'value'
|
||||
));
|
||||
$this->module->dontSeeInCurrentUrl('form/form/');
|
||||
$this->module->amOnPage('relative_siteroot');
|
||||
$this->module->click('Click me');
|
||||
$this->module->dontSeeInCurrentUrl('form/form/');
|
||||
}
|
||||
|
||||
public function testOpenPageException()
|
||||
{
|
||||
$this->setExpectedException('Codeception\Exception\ModuleException');
|
||||
$this->module->see('Hello');
|
||||
}
|
||||
}
|
||||
1711
vendor/codeception/base/tests/unit/Codeception/Module/TestsForWeb.php
vendored
Normal file
1711
vendor/codeception/base/tests/unit/Codeception/Module/TestsForWeb.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user