[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Database / PreparedStatementTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Database;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\DatabaseConnection;
18
19 /**
20 * Test case for \TYPO3\CMS\Core\Database\PreparedStatement
21 */
22 class PreparedStatementTest extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
23 {
24 /**
25 * @var DatabaseConnection
26 */
27 protected $subject = null;
28
29 /**
30 * @var string
31 */
32 protected $testTable = 'test_database_connection';
33
34 /**
35 * @var string
36 */
37 protected $testField = 'test_field';
38
39 /**
40 * @var string
41 */
42 protected $anotherTestField = 'another_test_field';
43
44 /**
45 * Set the test up
46 *
47 * @return void
48 */
49 protected function setUp()
50 {
51 parent::setUp();
52 $this->subject = $GLOBALS['TYPO3_DB'];
53 $this->subject->sql_query(
54 "CREATE TABLE {$this->testTable} (" .
55 ' id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,' .
56 " {$this->testField} MEDIUMBLOB," .
57 " {$this->anotherTestField} MEDIUMBLOB," .
58 ' PRIMARY KEY (id)' .
59 ') ENGINE=MyISAM DEFAULT CHARSET=utf8;'
60 );
61 }
62
63 /**
64 * Tear the test down
65 *
66 * @return void
67 */
68 protected function tearDown()
69 {
70 $this->subject->sql_query("DROP TABLE {$this->testTable};");
71 unset($this->subject);
72 }
73
74 /**
75 * @test
76 *
77 * @return void
78 */
79 public function prepareSelectQueryCreateValidQuery()
80 {
81 $this->assertTrue(
82 $this->subject->admin_query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ('aTestValue')")
83 );
84 $preparedQuery = $this->subject->prepare_SELECTquery(
85 "{$this->testField},{$this->anotherTestField}",
86 $this->testTable,
87 'id=:id',
88 '',
89 '',
90 '',
91 [':id' => 1]
92 );
93 $preparedQuery->execute();
94 $result = $preparedQuery->fetch();
95 $expectedResult = [
96 $this->testField => 'aTestValue',
97 $this->anotherTestField => null,
98 ];
99 $this->assertSame($expectedResult, $result);
100 }
101 }