|
2 | 2 | namespace WebFiori\Tests\Database\MsSql; |
3 | 3 |
|
4 | 4 | use PHPUnit\Framework\TestCase; |
| 5 | +use WebFiori\Database\DataType; |
5 | 6 | use WebFiori\Database\Factory\ColumnFactory; |
6 | 7 | use WebFiori\Database\MsSql\MSSQLColumn; |
7 | 8 | use WebFiori\Database\MySql\MySQLColumn; |
@@ -581,4 +582,96 @@ public function testIdentity02() { |
581 | 582 | $col->setIsIdentity(true); |
582 | 583 | $this->assertEquals('[iden] [bigint] identity(1,1) not null',$col.''); |
583 | 584 | } |
| 585 | + /** |
| 586 | + * @test |
| 587 | + * Test that MySQL-only types are auto-mapped when creating MSSQL columns. |
| 588 | + */ |
| 589 | + public function testAutoMapMySQLTextToMSSQL() { |
| 590 | + $col = ColumnFactory::create('mssql', 'content', ['type' => DataType::TEXT]); |
| 591 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 592 | + $this->assertEquals('nvarchar', $col->getDatatype()); |
| 593 | + $this->assertEquals(4000, $col->getSize()); |
| 594 | + } |
| 595 | + /** |
| 596 | + * @test |
| 597 | + */ |
| 598 | + public function testAutoMapMySQLMediumTextToMSSQL() { |
| 599 | + $col = ColumnFactory::create('mssql', 'body', ['type' => DataType::TEXT_MEDIUM]); |
| 600 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 601 | + $this->assertEquals('nvarchar', $col->getDatatype()); |
| 602 | + $this->assertEquals(4000, $col->getSize()); |
| 603 | + } |
| 604 | + /** |
| 605 | + * @test |
| 606 | + */ |
| 607 | + public function testAutoMapMySQLBlobToMSSQL() { |
| 608 | + $col = ColumnFactory::create('mssql', 'data', ['type' => DataType::BLOB]); |
| 609 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 610 | + $this->assertEquals('binary', $col->getDatatype()); |
| 611 | + } |
| 612 | + /** |
| 613 | + * @test |
| 614 | + */ |
| 615 | + public function testAutoMapMySQLLongBlobToMSSQL() { |
| 616 | + $col = ColumnFactory::create('mssql', 'data', ['type' => DataType::BLOB_LONG]); |
| 617 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 618 | + $this->assertEquals('binary', $col->getDatatype()); |
| 619 | + } |
| 620 | + /** |
| 621 | + * @test |
| 622 | + */ |
| 623 | + public function testAutoMapMySQLMediumBlobToMSSQL() { |
| 624 | + $col = ColumnFactory::create('mssql', 'data', ['type' => DataType::BLOB_MEDIUM]); |
| 625 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 626 | + $this->assertEquals('binary', $col->getDatatype()); |
| 627 | + } |
| 628 | + /** |
| 629 | + * @test |
| 630 | + */ |
| 631 | + public function testAutoMapMySQLTinyBlobToMSSQL() { |
| 632 | + $col = ColumnFactory::create('mssql', 'data', ['type' => DataType::BLOB_TINY]); |
| 633 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 634 | + $this->assertEquals('binary', $col->getDatatype()); |
| 635 | + } |
| 636 | + /** |
| 637 | + * @test |
| 638 | + */ |
| 639 | + public function testAutoMapMySQLDoubleToMSSQL() { |
| 640 | + $col = ColumnFactory::create('mssql', 'price', ['type' => DataType::DOUBLE]); |
| 641 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 642 | + $this->assertEquals('float', $col->getDatatype()); |
| 643 | + } |
| 644 | + /** |
| 645 | + * @test |
| 646 | + */ |
| 647 | + public function testAutoMapMySQLTimestampToMSSQL() { |
| 648 | + $col = ColumnFactory::create('mssql', 'ts', ['type' => DataType::TIMESTAMP]); |
| 649 | + $this->assertInstanceOf(MSSQLColumn::class, $col); |
| 650 | + $this->assertEquals('datetime2', $col->getDatatype()); |
| 651 | + } |
| 652 | + /** |
| 653 | + * @test |
| 654 | + * Test that explicit size is preserved when type is auto-mapped. |
| 655 | + */ |
| 656 | + public function testAutoMapPreservesExplicitSize() { |
| 657 | + $col = ColumnFactory::create('mssql', 'summary', ['type' => DataType::TEXT, 'size' => 500]); |
| 658 | + $this->assertEquals('nvarchar', $col->getDatatype()); |
| 659 | + $this->assertEquals(500, $col->getSize()); |
| 660 | + } |
| 661 | + /** |
| 662 | + * @test |
| 663 | + * Test that native MSSQL types are not affected by auto-mapping. |
| 664 | + */ |
| 665 | + public function testNativeTypesUnaffected() { |
| 666 | + $col = ColumnFactory::create('mssql', 'name', ['type' => DataType::VARCHAR, 'size' => 100]); |
| 667 | + $this->assertEquals('varchar', $col->getDatatype()); |
| 668 | + $this->assertEquals(100, $col->getSize()); |
| 669 | + |
| 670 | + $col2 = ColumnFactory::create('mssql', 'num', ['type' => DataType::INT]); |
| 671 | + $this->assertEquals('int', $col2->getDatatype()); |
| 672 | + |
| 673 | + $col3 = ColumnFactory::create('mssql', 'uname', ['type' => DataType::NVARCHAR, 'size' => 200]); |
| 674 | + $this->assertEquals('nvarchar', $col3->getDatatype()); |
| 675 | + $this->assertEquals(200, $col3->getSize()); |
| 676 | + } |
584 | 677 | } |
0 commit comments