Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EZP-24275: Indexable Image field type #1240

Merged
merged 5 commits into from Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,205 @@
<?php
/**
* This file is part of the eZ Publish Kernel 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 eZ\Publish\API\Repository\Tests\FieldType;

use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use FileSystemIterator;
use UnexpectedValueException;

/**
* Integration test for use field type
*
* @group integration
* @group field-type
*/
abstract class FileSearchBaseIntegrationTest extends SearchBaseIntegrationTest
{
/**
* Base install dir
*
* @var string
*/
protected static $installDir;

/**
* Root directory for IO files
*
* @var string
*/
protected static $ioRootDir;

/**
* Storage directory used by the IOHandler
* @var string
*/
protected static $storageDir;

/**
* Storage dir settings key
*/
protected static $storageDirConfigKey = 'storage_dir';

/**
* If storage data should not be cleaned up
*
* @var boolean
*/
protected static $leaveStorageData = false;

/**
* List of path in config:storage_dir that must not be deleted, and must be ignored in these tests
* Workaround for FieldType vs. Repository tests. The repository tests require those files since they
* match the ones referenced in the database fixtures used by Services tests.
* @var array
*/
protected static $ignoredPathList;

/**
* Returns the install dir used by the test
*
* @return string
*/
protected function getInstallDir()
{
return self::$installDir;
}

/**
* Returns the storage dir used by the test
*
* @return string
*/
protected function getStorageDir()
{
return self::$storageDir;
}

/**
* Perform storage directory setup on first execution
*
* @return void
*/
public function setUp()
{
parent::setUp();

if ( !isset( self::$installDir ) )
{
self::$installDir = $this->getConfigValue( 'ezpublish.kernel.root_dir' );
self::$storageDir = $this->getConfigValue( static::$storageDirConfigKey );
self::$ioRootDir = $this->getConfigValue( 'io_root_dir' );

self::setUpIgnoredPath( $this->getConfigValue( 'ignored_storage_files' ) );
}
}

/**
* Tears down the test.
*
* Cleans up the storage directory, if it was used
*
* @return void
*/
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
self::cleanupStorageDir();
}

/**
* Returns an iterator over the full storage dir.
*
* @return Iterator
*/
protected static function getStorageDirIterator()
{
return new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
self::$installDir . '/' . self::$storageDir,
FileSystemIterator::KEY_AS_PATHNAME | FileSystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO
),
RecursiveIteratorIterator::CHILD_FIRST
);
}

/**
* Removes the given directory path recursively
*
* @param string $dir
*
* @return void
*/
protected static function cleanupStorageDir()
{
if ( self::$installDir == null || self::$storageDir == null || self::$leaveStorageData )
{
// Nothing to do
return;
}

try
{
$iterator = self::getStorageDirIterator();

foreach ( $iterator as $path => $fileInfo )
{
if ( $fileInfo->isDir() )
{
if ( !self::isIgnoredPath( dirname( $path ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't these two if be combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this part was actually copied from FileSearchBaseIntegrationTest, it is here temporarily until we implement search tests for all field types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

rmdir( $path );
}
else if ( !self::isIgnoredPath( $path ) )
{
unlink( $path );
}
}
}
catch ( UnexpectedValueException $e )
{
// The directory to cleanup just doesn't exist
}
}

protected static function setUpIgnoredPath( $ignoredFiles )
{
foreach ( $ignoredFiles as $ignoredFile )
{
$pathPartsArray = explode( DIRECTORY_SEPARATOR, $ignoredFile );
foreach ( $pathPartsArray as $index => $directoryPart )
{
if ( $directoryPart == '' )
continue;
$partPath = implode(
DIRECTORY_SEPARATOR,
array_slice( $pathPartsArray, 0, $index + 1 )
);
self::$ignoredPathList[realpath( $partPath )] = true;
}
}
}

/**
* Checks if $path must be excluded from filesystem cleanup
* @param string $path
* @return bool
*/
protected static function isIgnoredPath( $path )
{
return isset( self::$ignoredPathList[realpath( $path )] );
}

protected function uriExistsOnIO( $uri )
{
$spiId = str_replace( self::$storageDir, '', ltrim( $uri, '/' ) );
$path = self::$ioRootDir . '/' . $spiId;
return file_exists( $path );
}
}