-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,034 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version = '1.0' encoding = 'utf-8'?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="./tests/bootstrap.php" | ||
processIsolation="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
colors="true"> | ||
<php> | ||
<env name="setupFactory" value="EzSystems\EzPlatformXmlTextFieldType\Tests\SetupFactory\LegacyEmptyDBSetupFactory" /> | ||
<env name="backendVersion" value="5" /> | ||
<env name="fixtureDir" value="Legacy" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Command Gateway"> | ||
<directory suffix="Test.php">./tests/bundle/Command/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory>./bundle</directory> | ||
<directory>./lib</directory> | ||
<directory>./vendor</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ Platform XmlText Field Type package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* | ||
* @version //autogentag// | ||
*/ | ||
namespace EzSystems\EzPlatformXmlTextFieldTypeBundle\Tests\Command; | ||
|
||
use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; | ||
|
||
abstract class BaseTest extends APIBaseTest | ||
{ | ||
/** | ||
* Taken from ezpublish-kernel/eZ/Publish/Core/Persistence/Legacy/Tests/TestCase.php | ||
* | ||
* @param $file | ||
* @throws \Exception | ||
*/ | ||
protected function insertDatabaseFixture($file) | ||
{ | ||
$data = require $file; | ||
$db = $this->getSetupFactory()->getDatabaseHandler(); | ||
|
||
foreach ($data as $table => $rows) { | ||
// Check that at least one row exists | ||
if (!isset($rows[0])) { | ||
continue; | ||
} | ||
|
||
$q = $db->createInsertQuery(); | ||
$q->insertInto($db->quoteIdentifier($table)); | ||
|
||
// Contains the bound parameters | ||
$values = array(); | ||
|
||
// Binding the parameters | ||
foreach ($rows[0] as $col => $val) { | ||
$q->set( | ||
$db->quoteIdentifier($col), | ||
$q->bindParam($values[$col]) | ||
); | ||
} | ||
|
||
$stmt = $q->prepare(); | ||
|
||
foreach ($rows as $row) { | ||
try { | ||
// This CANNOT be replaced by: | ||
// $values = $row | ||
// each $values[$col] is a PHP reference which should be | ||
// kept for parameters binding to work | ||
foreach ($row as $col => $val) { | ||
$values[$col] = $val; | ||
} | ||
|
||
$stmt->execute(); | ||
} catch (Exception $e) { | ||
echo "$table ( ", implode(', ', $row), " )\n"; | ||
throw $e; | ||
} | ||
} | ||
} | ||
|
||
$this->resetSequences(); | ||
} | ||
|
||
public function resetSequences() | ||
{ | ||
switch ($this->getDB()) { | ||
case 'pgsql': | ||
// Update PostgreSQL sequences | ||
$handler = $this->getSetupFactory()->getDatabaseHandler(); | ||
|
||
$queries = array_filter(preg_split('(;\\s*$)m', | ||
file_get_contents(__DIR__ . '/_fixtures/setval.pgsql.sql'))); | ||
foreach ($queries as $query) { | ||
$handler->exec($query); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.