/** * Set up * * @return void */ protected function setUp() { $this->database = $this->getMock(DatabaseConnection::class, array('exec_SELECTgetSingleRow')); $this->database->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(array('uid' => 0, 'parent' => ''))); $this->treeData = new TreeNode(); $GLOBALS['TYPO3_DB'] = $this->database; }
/** * @test */ public function databaseResultIsUsedWhenNoCachedResultIsPresent() { $fakeConfiguration = array('select.' => array('checkRootPageId' => true, 'checkLanguage' => true, 'SELECT' => '', 'FROM' => '', 'ADD_WHERE' => '', 'GROUP_BY' => '', 'ORDER_BY' => ''), 'limit'); $this->configurationMock->expects($this->once())->method('getSearchFrequentSearchesConfiguration')->will($this->returnValue($fakeConfiguration)); $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('search_term' => 'my search', 'hits' => 22)))); //we fake that we have no frequent searches in the cache and therefore expect that the database will be queried $this->fakeIdentifierNotInCache(); $frequentTerms = $this->frequentSearchesService->getFrequentSearchTerms(); $this->assertSame($frequentTerms, array('my search' => 22), 'Could not retrieve frequent search terms'); }
/** * Checking if parameters bound to the statement by bindValues() * are properly replaced in the query. * * @test * @dataProvider parametersAndQueriesDataProvider * @param string $query Query with unreplaced markers * @param array $parameters Array of parameters to be replaced in the query * @param string $expectedResult Query with all markers replaced * @return void */ public function parametersAreReplacedInQueryWhenBoundWithBindValues($query, $parameters, $expectedResult) { $statement = $this->createPreparedStatement($query); $this->databaseStub->expects($this->any())->method('prepare_PREPAREDquery')->with($this->equalTo($expectedResult)); $statement->bindValues($parameters); $statement->execute(); }
/** * @test */ public function deleteMethodCallsExpectedDatabaseMethodWithRecord() { $table = 'test'; $uid = 123; $record = array('uid' => 123); $mock = $this->getMockServiceInstance(array(), array('exec_DELETEquery')); self::$connectionMock->expects($this->once())->method('exec_DELETEquery')->with($table, "uid = '" . $uid . "'"); $mock->delete($table, $record); }
/** * @test * * @return void */ public function updateQueryCreateValidQuery() { $this->subject = $this->getAccessibleMock(DatabaseConnection::class, ['fullQuoteStr'], [], '', false); $this->subject->expects($this->any())->method('fullQuoteStr')->will($this->returnCallback(function ($data) { return '\'' . (string) $data . '\''; })); $fieldsValues = [$this->testField => 'aTestValue']; $queryExpected = "UPDATE {$this->testTable} SET {$this->testField}='aTestValue' WHERE id=1"; $queryGenerated = $this->subject->UPDATEquery($this->testTable, 'id=1', $fieldsValues); $this->assertSame($queryExpected, $queryGenerated); }
/** * @test */ public function doesFindByTypeAndTableNameReturnObjects() { $testUid = rand(1, 1000); $testTable = uniqid('sys_collection_'); $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static; $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback'))); $this->getRowsCallbackReturnValue = array(array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName), array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)); $objects = $this->fixture->findByTypeAndTableName($type, $testTable); $this->assertEquals(2, count($objects)); $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]); $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]); }
/** * @test * @param array $tcaFieldConf * @dataProvider inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFieldsDataProvider */ public function inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFields($tcaFieldConf) { $this->mockDatabaseConnection->expects($this->never())->method('getDateTimeFormats'); $this->subject->checkValue_input(array(), '', $tcaFieldConf, array()); }
/** * @return void */ protected function assertDatabaseWillNeverBeQueried() { $this->databaseMock->expects($this->never())->method('exec_SELECTgetRows'); }
/** * @test */ public function truncate_multiple_tables_when_configured() { $configuration = ['truncate' => ['test', 'test2', 'test3']]; $processor = $this->getMockBuilder(Configuration::class)->disableOriginalConstructor()->getMock(); $this->connection->expects($this->exactly(3))->method('exec_TRUNCATEquery')->withConsecutive(['test'], ['test2'], ['test3']); $this->fixture->execute($processor, $configuration); }