Skip to content

Commit

Permalink
[test] several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Dec 19, 2023
1 parent affce32 commit 98f0801
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion tests/helper/AssetHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AssetHelperTest extends TestCase

public function testTodoMigrate()
{
$context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'myResponse', 'controller' => 'myController2'));
$context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'myResponse', 'controller' => 'myController2'), true);

// _compute_public_path()
$this->diag('_compute_public_path');
Expand Down
2 changes: 1 addition & 1 deletion tests/helper/DateHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DateHelperTest extends TestCase

public function testTodoMigrate()
{
sfConfig::set('sf_charset', 'utf-8');
sfConfig::set('sf_charset', 'UTF-8');

$context = sfContext::getInstance(array('user' => 'mySfUser'), true);

Expand Down
33 changes: 11 additions & 22 deletions tests/storage/sfMySQLiStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,15 @@ public function testTodoMigrate()
ob_start();

// Configure your database with the settings below in order to run the test

$mysqli_config = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'host' => getenv('MYSQL_HOST') ?? 'localhost',
'username' => getenv('MYSQL_USER') ?? 'root',
'password' => getenv('MYSQL_PASSWORD') ?? '',
);

if (!isset($mysqli_config)) {
$this->skip('Mysql credentials needed to run these tests', $plan);

return;
}

try {
// Creating mysql database connection
$database = new sfMySQLiDatabase($mysqli_config);
$connection = $database->getResource();
} catch (sfDatabaseException $e) {
$this->diag($e->getMessage());
$this->skip('Unable to connect to MySQL database, skipping', $plan);

return;
}
$database = new sfMySQLiDatabase($mysqli_config);
$connection = $database->getResource();

// Creates test database
mysqli_query($connection, 'DROP DATABASE IF EXISTS sf_mysqli_storage_unit_test');
Expand All @@ -66,8 +53,8 @@ public function testTodoMigrate()
$storage = new sfMySQLiSessionStorage(array(
'db_table' => 'session',
'session_id' => $session_id,
'database' => $database)
);
'database' => $database
));

$this->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage');
$this->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage');
Expand Down Expand Up @@ -128,7 +115,7 @@ public function testTodoMigrate()
$result = mysqli_query($connection, sprintf('SELECT COUNT(sess_id) FROM session WHERE sess_id = "%s"', $session_id));

list($count) = mysqli_fetch_row($result);
$this->is($count, 0, 'session is removed from the database');
$this->is($count, '0', 'session is removed from the database');

mysqli_free_result($result);
unset($count, $result);
Expand All @@ -142,5 +129,7 @@ public function testTodoMigrate()
$database->shutdown();

unset($mysqli_config);

ob_end_clean();
}
}
8 changes: 4 additions & 4 deletions tests/widget/sfWidgetFormDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testTodoMigrate()
$this->diag('->render()');

foreach (array(
$year.'-10-15' => array('year' => $year, 'month' => 10, 'day' => 15),
$year.'-10-15' => array('year' => $year, 'month' => '10', 'day' => '15'),
time() => array('year' => date('Y'), 'month' => date('m'), 'day' => date('d')),
'tomorrow' => array('year' => date('Y', time() + 86400), 'month' => date('m', time() + 86400), 'day' => date('d', time() + 86400)),
) as $date => $values) {
Expand All @@ -60,7 +60,7 @@ public function testTodoMigrate()

// date as an array
$this->diag('date as an array');
$values = array('year' => $year, 'month' => 10, 'day' => 15);
$values = array('year' => $year, 'month' => '10', 'day' => '15');
$dom->loadHTML($w->render('foo', $values));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_year option[value="'.$values['year'].'"][selected="selected"]')->getValue(), $values['year'], '->render() renders a select tag for the year');
Expand All @@ -69,10 +69,10 @@ public function testTodoMigrate()

// invalid date
$this->diag('invalid date');
$dom->loadHTML($w->render('foo', array('year' => null, 'month' => 10)));
$dom->loadHTML($w->render('foo', array('year' => null, 'month' => '10')));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_year option[selected="selected"]')->getValue(), '', '->render() renders a select tag for the year');
$this->is($css->matchSingle('#foo_month option[selected="selected"]')->getValue(), 10, '->render() renders a select tag for the month');
$this->is($css->matchSingle('#foo_month option[selected="selected"]')->getValue(), '10', '->render() renders a select tag for the month');
$this->is($css->matchSingle('#foo_day option[selected="selected"]')->getValue(), '', '->render() renders a select tag for the day');

$dom->loadHTML($w->render('foo', 'invaliddate'));
Expand Down
8 changes: 4 additions & 4 deletions tests/widget/sfWidgetFormDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function testTodoMigrate()
$this->diag('->render()');

foreach (array(
$year.'-10-15 12:30:35' => array('year' => $year, 'month' => 10, 'day' => 15, 'hour' => 12, 'minute' => 30, 'second' => 35),
$year.'-10-15 12:30:35' => array('year' => $year, 'month' => '10', 'day' => '15', 'hour' => '12', 'minute' => '30', 'second' => '35'),
time() => array('year' => date('Y'), 'month' => date('m'), 'day' => date('d'), 'hour' => date('G'), 'minute' => date('i'), 'second' => date('s')),
'tomorrow 12:30:35' => array('year' => date('Y', time() + 86400), 'month' => date('m', time() + 86400), 'day' => date('d', time() + 86400), 'hour' => 12, 'minute' => 30, 'second' => 35),
'tomorrow 12:30:35' => array('year' => date('Y', time() + 86400), 'month' => date('m', time() + 86400), 'day' => date('d', time() + 86400), 'hour' => '12', 'minute' => '30', 'second' => '35'),
) as $date => $values) {
$dom->loadHTML($w->render('foo', $date));
$css = new sfDomCssSelector($dom);
Expand All @@ -52,7 +52,7 @@ public function testTodoMigrate()

// selected date / time
$this->diag('selected date / time');
$values = array('year' => $year, 'month' => 10, 'day' => 15, 'hour' => 12, 'minute' => 30, 'second' => 35);
$values = array('year' => $year, 'month' => '10', 'day' => '15', 'hour' => '12', 'minute' => '30', 'second' => '35');
$dom->loadHTML($w->render('foo', $values));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_year option[value="'.$values['year'].'"][selected="selected"]')->getValue(), $values['year'], '->render() renders a select tag for the year');
Expand All @@ -64,7 +64,7 @@ public function testTodoMigrate()

// invalid date / time
$this->diag('invalid date / time');
$values = array('year' => null, 'month' => 10, 'hour' => null, 'minute' => 30);
$values = array('year' => null, 'month' => '10', 'hour' => null, 'minute' => '30');
$dom->loadHTML($w->render('foo', $values));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_year option[selected="selected"]')->getValue(), '', '->render() renders a select tag for the year');
Expand Down
3 changes: 3 additions & 0 deletions tests/widget/sfWidgetFormSchemaFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,8 @@ function ___my($s, $p, $c)
$f->setTranslationCallable('___my');
$f->setTranslationCatalogue('bar');
$this->is($f->translate('foo', array()), 'bar', 'translate() passes back the catalogue to the translation callable');

// reset callable
MyFormatter::dropTranslationCallable();
}
}
16 changes: 8 additions & 8 deletions tests/widget/sfWidgetFormTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public function testTodoMigrate()
$css = new sfDomCssSelector($dom);

// selected date
$this->is($css->matchSingle('#foo_hour option[value="12"][selected="selected"]')->getValue(), 12, '->render() renders a select tag for the hour');
$this->is($css->matchSingle('#foo_minute option[value="30"][selected="selected"]')->getValue(), 30, '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_second option[value="35"][selected="selected"]')->getValue(), 35, '->render() renders a select tag for the second');
$this->is($css->matchSingle('#foo_hour option[value="12"][selected="selected"]')->getValue(), '12', '->render() renders a select tag for the hour');
$this->is($css->matchSingle('#foo_minute option[value="30"][selected="selected"]')->getValue(), '30', '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_second option[value="35"][selected="selected"]')->getValue(), '35', '->render() renders a select tag for the second');
}

// time as an array
$this->diag('time as an array');
$dom->loadHTML($w->render('foo', array('hour' => 12, 'minute' => '30', 'second' => 35)));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_hour option[value="12"][selected="selected"]')->getValue(), 12, '->render() renders a select tag for the hour');
$this->is($css->matchSingle('#foo_minute option[value="30"][selected="selected"]')->getValue(), 30, '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_second option[value="35"][selected="selected"]')->getValue(), 35, '->render() renders a select tag for the second');
$this->is($css->matchSingle('#foo_hour option[value="12"][selected="selected"]')->getValue(), '12', '->render() renders a select tag for the hour');
$this->is($css->matchSingle('#foo_minute option[value="30"][selected="selected"]')->getValue(), '30', '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_second option[value="35"][selected="selected"]')->getValue(), '35', '->render() renders a select tag for the second');

// time as an array - single digits
$this->diag('time as an array - single digits');
Expand All @@ -62,10 +62,10 @@ public function testTodoMigrate()

// invalid time
$this->diag('time as an array');
$dom->loadHTML($w->render('foo', array('hour' => null, 'minute' => 30)));
$dom->loadHTML($w->render('foo', array('hour' => null, 'minute' => '30')));
$css = new sfDomCssSelector($dom);
$this->is($css->matchSingle('#foo_hour option[selected="selected"]')->getValue(), '', '->render() renders a select tag for the hour');
$this->is($css->matchSingle('#foo_minute option[selected="selected"]')->getValue(), 30, '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_minute option[selected="selected"]')->getValue(), '30', '->render() renders a select tag for the minute');
$this->is($css->matchSingle('#foo_second option[selected="selected"]')->getValue(), '', '->render() renders a select tag for the second');

$dom->loadHTML($w->render('foo', 'invalidtime'));
Expand Down
1 change: 1 addition & 0 deletions tests/widget/sfWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function testTodoMigrate()

// ::getCharset() ::setCharset()
$this->diag('::getCharset() ::setCharset()');
sfWidget::setCharset('UTF-8');
$this->is(sfWidget::getCharset(), 'UTF-8', '::getCharset() returns the charset to use for widgets');
sfWidget::setCharset('ISO-8859-1');
$this->is(sfWidget::getCharset(), 'ISO-8859-1', '::setCharset() changes the charset to use for widgets');
Expand Down

0 comments on commit 98f0801

Please sign in to comment.