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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abba162
EZP-24275: implemented Indexable definition for Image field type
pspanja ae3246b
EZP-24275: prepare base search test for testing modified fields
pspanja 7dd16bc
EZP-24275: make getServiceContainer() visible
pspanja 4675e02
EZP-24275: tested Indexable definition for Image field type
pspanja 713835e
EZP-24275: fixed: check generated field filter
pspanja File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
eZ/Publish/API/Repository/Tests/FieldType/FileSearchBaseIntegrationTest.php
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,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 ) ) ) | ||
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 ); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.