Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 26, 2018
1 parent eb749b4 commit c3acd86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
7 changes: 2 additions & 5 deletions src/Database/DatabaseUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ public function doBulkInsert(
}

foreach ($fields as $n => $strField) {
if (!isset($varData[$strField])) {
continue;
}
$varValue = $varData[$strField] ?: 'DEFAULT';
$varValue = isset($varData[$strField]) ? $varData[$strField] : 'DEFAULT';

if (in_array($strField, array_keys($fixedValues), true)) {
$varValue = $fixedValues[$strField];
Expand All @@ -231,7 +228,7 @@ public function doBulkInsert(
}

foreach ($fields as $n => $strField) {
$varValue = $varCallback[$strField] ?: 'DEFAULT';
$varValue = isset($varCallback[$strField]) ? $varCallback[$strField] : 'DEFAULT';

// replace SQL Keyword DEFAULT within wildcards ?
if ('DEFAULT' == $varValue) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testDoBulkInsert()
{
$databaseAdapter = $this->mockAdapter(['tableExists', 'getFieldNames', 'execute', 'prepare']);
$databaseAdapter->method('tableExists')->willReturn(true);
$databaseAdapter->method('getFieldNames')->willReturn(['id', 'name', 'date']);
$databaseAdapter->method('getFieldNames')->willReturn(['id', 'name', 'date', 'test']);
$databaseAdapter->method('prepare')->willReturnSelf();

// return null
Expand All @@ -147,7 +147,7 @@ public function testDoBulkInsert()
$model = $this->createMock(Model::class);
$model->method('row')->willReturn(['name' => 'max', 'date' => time()]);

$data = [['name' => 'DEFAULT', 'date' => time()], ['name' => 'max', 'date' => time()], $model];
$data = [['name' => 'DEFAULT', 'date' => time(), 'test' => 'DEFAULT'], ['name' => 'max', 'date' => time()], $model];

$result = $databaseUtil->doBulkInsert('table', $data, ['name' => 'Max'], 'UPDATE', 'is_array', function ($return, $fields, $varData) { return null; }, 2);
$this->assertNull($result);
Expand Down
2 changes: 1 addition & 1 deletion tests/Dca/DcaUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function testGenerateAlias()
$util->generateAlias('existing-alias', 5, 'tl_table', 'Existing Alias');
}

public function testAddAuthorFiledAndCallback()
public function testAddAuthorFieldAndCallback()
{
$array['TL_DCA']['testTable']['config']['oncreate_callback']['setAuthorIDOnCreate'] = ['huh.utils.dca', 'setAuthorIDOnCreate'];
$array['TL_DCA']['testTable']['config']['onload_callback']['modifyAuthorPaletteOnLoad'] = ['huh.utils.dca', 'modifyAuthorPaletteOnLoad', true];
Expand Down
7 changes: 2 additions & 5 deletions tests/File/FileUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public function testGetUniqueFileNameWithinTarget()
$framework = $this->mockContaoFramework();
$fileUtil = new FileUtil($framework);

// $fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir() . '/files/test');
// $this->assertSame(ltrim($this->getTempDir() . '/files/test', '/'), $fileName);
//
// $fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir() . '/files/test', 'te');
// $this->assertSame(ltrim($this->getTempDir() . '/files/_1.', '/'), $fileName);
$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/test', 'te');
$this->assertSame(ltrim($this->getTempDir().'/files/_1.', '/'), $fileName);

$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/test/test/test');
$this->assertFalse($fileName);
Expand Down
7 changes: 7 additions & 0 deletions tests/Form/FormUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ public function testPrepareSpecialValueForOutputMultiColumnEditor()

$result = $this->formUtil->prepareSpecialValueForOutput('myField', $value, $this->dc);
$this->assertSame('[Firstname: John1, Lastname: Doe1, Language: Deutsch], [Firstname: John2, Lastname: Doe2, Language: Englisch]', $result);

$adapter = $this->mockAdapter(['getConfigByArrayOrCallbackOrFunction']);
$adapter->method('getConfigByArrayOrCallbackOrFunction')->willThrowException(new \ErrorException('This is an error exception'));

$this->container->set('huh.utils.dca', $adapter);
$result = $this->formUtil->prepareSpecialValueForOutput('myField', $value, $this->dc);
$this->assertSame('[Firstname: John1, Lastname: Doe1, Language: Deutsch], [Firstname: John2, Lastname: Doe2, Language: Englisch]', $result);
}

public function testEscapeAllHtmlEntities()
Expand Down

0 comments on commit c3acd86

Please sign in to comment.