PageRenderTime 55ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/test/testsuite/generator/behavior/AutoAddPkBehaviorTest.php

https://github.com/nextbigsound/propel-orm
PHP | 70 lines | 50 code | 5 blank | 15 comment | 0 complexity | 1c563ac5a300cb43ea44afbea04e8453 MD5 | raw file
  1. <?php
  2. /*
  3. * $Id$
  4. * This file is part of the Propel package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. require_once 'tools/helpers/bookstore/BookstoreTestBase.php';
  11. /**
  12. * Tests for AutoAddPkBehavior class
  13. *
  14. * @author François Zaninotto
  15. * @version $Revision$
  16. * @package generator.behavior
  17. */
  18. class AutoAddPkBehaviorTest extends BookstoreTestBase
  19. {
  20. public function testDefault()
  21. {
  22. $table6 = Table6Peer::getTableMap();
  23. $this->assertEquals(count($table6->getColumns()), 2, 'auto_add_pk adds one column by default');
  24. $pks = $table6->getPrimaryKeys();
  25. $this->assertEquals(count($pks), 1, 'auto_add_pk adds a simple primary key by default');
  26. $pk = array_pop($pks);
  27. $this->assertEquals($pk->getName(), 'ID', 'auto_add_pk adds an id column by default');
  28. $this->assertEquals($pk->getType(), 'INTEGER', 'auto_add_pk adds an integer column by default');
  29. $this->assertTrue($pk->isPrimaryKey(), 'auto_add_pk adds a primary key column by default');
  30. $this->assertTrue($table6->isUseIdGenerator(), 'auto_add_pk adds an autoIncrement column by default');
  31. }
  32. public function testNoTrigger()
  33. {
  34. $table7 = Table7Peer::getTableMap();
  35. $this->assertEquals(count($table7->getColumns()), 2, 'auto_add_pk does not add a column when the table already has a primary key');
  36. $this->assertFalse(method_exists('Table7', 'getId'), 'auto_add_pk does not add an id column when the table already has a primary key');
  37. $pks = $table7->getPrimaryKeys();
  38. $pk = array_pop($pks);
  39. $this->assertEquals($pk->getName(), 'FOO', 'auto_add_pk does not change an existing primary key');
  40. }
  41. public function testParameters()
  42. {
  43. $table8 = Table8Peer::getTableMap();
  44. $this->assertEquals(count($table8->getColumns()), 3, 'auto_add_pk adds one column with custom parameters');
  45. $pks = $table8->getPrimaryKeys();
  46. $pk = array_pop($pks);
  47. $this->assertEquals($pk->getName(), 'IDENTIFIER', 'auto_add_pk accepts customization of pk column name');
  48. $this->assertEquals($pk->getType(), 'BIGINT', 'auto_add_pk accepts customization of pk column type');
  49. $this->assertTrue($pk->isPrimaryKey(), 'auto_add_pk adds a primary key column with custom parameters');
  50. $this->assertFalse($table8->isUseIdGenerator(), 'auto_add_pk accepts customization of pk column autoIncrement');
  51. }
  52. public function testForeignKey()
  53. {
  54. $t6 = new Table6();
  55. $t6->setTitle('foo');
  56. $t6->save();
  57. $t8 = new Table8();
  58. $t8->setIdentifier(1);
  59. $t8->setTable6($t6);
  60. $t8->save();
  61. $this->assertEquals($t8->getFooId(), $t6->getId(), 'Auto added pkeys can be used in relations');
  62. $t8->delete();
  63. $t6->delete();
  64. }
  65. }