1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/tests/ConfigurableTestCase.php

218 lines
9.4 KiB
PHP
Raw Normal View History

2006-04-14 00:37:28 +04:00
<?php
require_once("UnitTestCase.php");
2006-04-14 00:37:28 +04:00
2006-11-22 02:34:12 +03:00
class Doctrine_Configurable_TestCase extends Doctrine_UnitTestCase {
public function prepareTables() { }
public function prepareData() { }
2006-11-22 02:34:12 +03:00
public function testGetIndexNameFormatAttribute() {
// default index name format is %_idx
2006-12-28 00:20:26 +03:00
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), '%s_idx');
2006-11-22 02:34:12 +03:00
}
public function testGetSequenceNameFormatAttribute() {
// default sequence name format is %_seq
2006-12-28 00:20:26 +03:00
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT), '%s_seq');
2006-11-22 02:34:12 +03:00
}
public function testSetIndexNameFormatAttribute() {
$this->manager->setAttribute(Doctrine::ATTR_IDXNAME_FORMAT, '%_index');
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), '%_index');
}
public function testSetSequenceNameFormatAttribute() {
$this->manager->setAttribute(Doctrine::ATTR_SEQNAME_FORMAT, '%_sequence');
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT), '%_sequence');
}
public function testExceptionIsThrownWhenSettingIndexNameFormatAttributeAtTableLevel() {
try {
2006-12-28 00:20:26 +03:00
$this->connection->getTable('Entity')->setAttribute(Doctrine::ATTR_IDXNAME_FORMAT, '%s_idx');
2006-11-22 02:34:12 +03:00
$this->fail();
} catch(Doctrine_Exception $e) {
$this->pass();
}
}
public function testExceptionIsThrownWhenSettingSequenceNameFormatAttributeAtTableLevel() {
try {
2006-12-28 00:20:26 +03:00
$this->connection->getTable('Entity')->setAttribute(Doctrine::ATTR_SEQNAME_FORMAT, '%s_seq');
2006-11-22 02:34:12 +03:00
$this->fail();
} catch(Doctrine_Exception $e) {
$this->pass();
}
}
public function testSettingFieldCaseIsSuccesfulWithZero() {
try {
$this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, 0);
$this->pass();
} catch(Doctrine_Exception $e) {
$this->fail();
}
}
public function testSettingFieldCaseIsSuccesfulWithCaseConstants() {
try {
$this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, CASE_LOWER);
$this->pass();
} catch(Doctrine_Exception $e) {
$this->fail();
}
}
public function testSettingFieldCaseIsSuccesfulWithCaseConstants2() {
try {
$this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, CASE_UPPER);
$this->pass();
} catch(Doctrine_Exception $e) {
$this->fail();
}
}
public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo() {
try {
$this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, -1);
$this->fail();
} catch(Doctrine_Exception $e) {
$this->pass();
}
}
public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo2() {
try {
$this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, 5);
$this->fail();
} catch(Doctrine_Exception $e) {
$this->pass();
}
}
public function testDefaultQuoteIdentifierAttributeValueIsFalse() {
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER), false);
}
public function testQuoteIdentifierAttributeAcceptsBooleans() {
$this->manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER), true);
2006-12-28 00:20:26 +03:00
$this->manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, false);
2006-11-22 02:34:12 +03:00
}
public function testDefaultSequenceColumnNameAttributeValueIsId() {
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQCOL_NAME), 'id');
}
public function testSequenceColumnNameAttributeAcceptsStrings() {
$this->manager->setAttribute(Doctrine::ATTR_SEQCOL_NAME, 'sequence');
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQCOL_NAME), 'sequence');
}
public function testValidatorAttributeAcceptsBooleans() {
$this->manager->setAttribute(Doctrine::ATTR_VLD, true);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_VLD), true);
}
public function testAutoLengthValidationAttributeAcceptsBooleans() {
$this->manager->setAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD, true);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD), true);
}
public function testAutoTypeValidationAttributeAcceptsBooleans() {
$this->manager->setAttribute(Doctrine::ATTR_AUTO_TYPE_VLD, true);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD), true);
}
public function testDefaultPortabilityAttributeValueIsAll() {
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PORTABILITY), Doctrine::PORTABILITY_ALL);
}
public function testPortabilityAttributeAcceptsPortabilityConstants() {
$this->manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_RTRIM | Doctrine::PORTABILITY_FIX_CASE);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PORTABILITY),
Doctrine::PORTABILITY_RTRIM | Doctrine::PORTABILITY_FIX_CASE);
}
public function testDefaultListenerIsDoctrineEventListener() {
$this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_EventListener);
}
public function testListenerAttributeAcceptsEventListenerObjects() {
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_Debugger());
$this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_EventListener_Debugger);
}
public function testCollectionKeyAttributeAcceptsValidColumnName() {
try {
$this->connection->getTable('User')->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
$this->pass();
} catch(Exception $e) {
$this->fail();
}
}
public function testSettingInvalidColumnNameToCollectionKeyAttributeThrowsException() {
try {
$this->connection->getTable('User')->setAttribute(Doctrine::ATTR_COLL_KEY, 'unknown');
$this->fail();
} catch(Exception $e) {
$this->pass();
}
}
public function testSettingCollectionKeyAttributeOnOtherThanTableLevelThrowsException() {
try {
$this->connection->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
$this->fail();
} catch(Exception $e) {
$this->pass();
}
}
2006-04-14 00:37:28 +04:00
public function testSetAttribute() {
2006-08-22 03:20:33 +04:00
$table = $this->connection->getTable("User");
/**
2006-04-14 00:37:28 +04:00
$this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,100);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_TTL),100);
2006-04-14 00:37:28 +04:00
$this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,1);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_SIZE),1);
$this->manager->setAttribute(Doctrine::ATTR_CACHE_DIR,"%ROOT%".DIRECTORY_SEPARATOR."cache");
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_DIR),$this->manager->getRoot().DIRECTORY_SEPARATOR."cache");
*/
2006-04-14 00:37:28 +04:00
$this->manager->setAttribute(Doctrine::ATTR_FETCHMODE,Doctrine::FETCH_LAZY);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_FETCHMODE),Doctrine::FETCH_LAZY);
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 5);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_BATCH_SIZE),5);
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC);
// test invalid arguments
/**
2006-04-14 00:37:28 +04:00
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
*/
2006-04-14 00:37:28 +04:00
try {
2006-08-22 03:20:33 +04:00
$this->connection->beginTransaction();
2006-04-14 00:37:28 +04:00
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
2006-08-22 03:20:33 +04:00
$this->connection->commit();
2006-04-14 00:37:28 +04:00
}
2006-04-17 00:38:17 +04:00
2006-04-14 00:37:28 +04:00
try {
2006-08-22 03:20:33 +04:00
$this->connection->beginTransaction();
$this->connection->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
2006-04-14 00:37:28 +04:00
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
2006-08-22 03:20:33 +04:00
$this->connection->commit();
2006-04-14 00:37:28 +04:00
}
2006-09-21 01:18:41 +04:00
2006-04-14 00:37:28 +04:00
}
public function testGetAttributes() {
$this->assertTrue(is_array($this->manager->getAttributes()));
}
}