PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/propel/test/testsuite/generator/platform/DefaultPlatformTest.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 104 lines | 78 code | 10 blank | 16 comment | 1 complexity | 7c6b65abf84e55731e2c0b43e5d39383 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once dirname(__FILE__) . '/../../../../generator/lib/platform/DefaultPlatform.php';
  10. require_once dirname(__FILE__) . '/../../../../generator/lib/model/Column.php';
  11. require_once dirname(__FILE__) . '/../../../../generator/lib/util/PropelQuickBuilder.php';
  12. require_once dirname(__FILE__) . '/../../../../runtime/lib/Propel.php';
  13. /**
  14. *
  15. * @package generator.platform
  16. */
  17. class DefaultPlatformTest extends PHPUnit_Framework_TestCase
  18. {
  19. protected $platform;
  20. /**
  21. * Get the Platform object for this class
  22. *
  23. * @return Platform
  24. */
  25. protected function getPlatform()
  26. {
  27. if (null === $this->platform) {
  28. $this->platform = new DefaultPlatform();
  29. }
  30. return $this->platform;
  31. }
  32. protected function tearDown()
  33. {
  34. $this->platform = null;
  35. }
  36. public function testQuote()
  37. {
  38. $p = $this->getPlatform();
  39. $unquoted = "Nice";
  40. $quoted = $p->quote($unquoted);
  41. $this->assertEquals("'$unquoted'", $quoted);
  42. $unquoted = "Naughty ' string";
  43. $quoted = $p->quote($unquoted);
  44. $expected = "'Naughty '' string'";
  45. $this->assertEquals($expected, $quoted);
  46. }
  47. protected function createColumn($type, $defaultValue)
  48. {
  49. $column = new Column();
  50. $column->setType($type);
  51. $column->setDefaultValue($defaultValue);
  52. return $column;
  53. }
  54. public function createEnumColumn($defaultValues, $defaultValue)
  55. {
  56. $column = new Column();
  57. $column->setType(PropelTypes::ENUM);
  58. $column->setValueSet($defaultValues);
  59. $column->setDefaultValue($defaultValue);
  60. return $column;
  61. }
  62. public function getColumnDefaultValueDDLDataProvider()
  63. {
  64. return array(
  65. array($this->createColumn(PropelTypes::INTEGER, 0), "DEFAULT 0"),
  66. array($this->createColumn(PropelTypes::INTEGER, '0'), "DEFAULT 0"),
  67. array($this->createColumn(PropelTypes::VARCHAR, 'foo'), "DEFAULT 'foo'"),
  68. array($this->createColumn(PropelTypes::VARCHAR, 0), "DEFAULT '0'"),
  69. array($this->createColumn(PropelTypes::BOOLEAN, true), "DEFAULT 1"),
  70. array($this->createColumn(PropelTypes::BOOLEAN, false), "DEFAULT 0"),
  71. array($this->createColumn(PropelTypes::BOOLEAN, 'true'), "DEFAULT 1"),
  72. array($this->createColumn(PropelTypes::BOOLEAN, 'false'), "DEFAULT 0"),
  73. array($this->createColumn(PropelTypes::BOOLEAN, 'TRUE'), "DEFAULT 1"),
  74. array($this->createColumn(PropelTypes::BOOLEAN, 'FALSE'), "DEFAULT 0"),
  75. array($this->createEnumColumn(array('foo', 'bar', 'baz'), 'foo'), "DEFAULT 0"),
  76. array($this->createEnumColumn(array('foo', 'bar', 'baz'), 'bar'), "DEFAULT 1"),
  77. array($this->createEnumColumn(array('foo', 'bar', 'baz'), 'baz'), "DEFAULT 2"),
  78. );
  79. }
  80. /**
  81. * @dataProvider getColumnDefaultValueDDLDataProvider
  82. */
  83. public function testGetColumnDefaultValueDDL($column, $default)
  84. {
  85. $this->assertEquals($default, $this->getPlatform()->getColumnDefaultValueDDL($column));
  86. }
  87. }