miniflux-legacy/vendor/fguillot/simple-validator/tests/UniqueValidatorTest.php

36 lines
1.0 KiB
PHP
Raw Normal View History

<?php
use SimpleValidator\Validators\Unique;
class UniqueValidatorTest extends PHPUnit_Framework_TestCase
{
public function testValidator()
{
$pdo = new PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE mytable (id INTEGER, toto TEXT)');
$message = 'field must be unique';
$v = new Unique('toto', $message, $pdo, 'mytable');
$this->assertEquals($message, $v->getErrorMessage());
$this->assertTrue($v->execute(array('toto' => '')));
$this->assertTrue($v->execute(array('toto' => null)));
$this->assertTrue($v->execute(array('toto' => 'titi')));
$pdo->exec("INSERT INTO mytable VALUES ('1', 'truc')");
$this->assertTrue($v->execute(array('toto' => 'titi')));
$pdo->exec("INSERT INTO mytable VALUES ('2', 'titi')");
$this->assertFalse($v->execute(array('toto' => 'titi')));
2015-03-01 19:56:11 +01:00
$this->assertTrue($v->execute(array('toto' => 'titi', 'id' => '2')));
$this->assertFalse($v->execute(array('toto' => 'truc', 'id' => '2')));
}
2015-04-11 02:34:48 +02:00
}