Skip to content

Commit

Permalink
Merge pull request #1 from FACT-Finder/development
Browse files Browse the repository at this point in the history
FIX: single-word-search + too long test file names
  • Loading branch information
Estigy committed May 6, 2016
2 parents 1ab3dbb + 53ef25c commit b45b225
Show file tree
Hide file tree
Showing 47 changed files with 405 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/FACTFinder/Adapter/Recommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function createRecord($recordData, $position)
$position
);
}
/**
* Get the recommendations from FACT-Finder as the string returned by the
* server.
Expand Down
16 changes: 8 additions & 8 deletions src/FACTFinder/Adapter/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,26 @@ private function createSingleWordSearch()
$jsonData = $this->getResponseContent();
if (!empty($jsonData['searchResult']['singleWordResults']))
{
foreach ($jsonData['searchResults']['singleWordResults'] as $swsData)
foreach ($jsonData['searchResult']['singleWordResults'] as $swsData)
{
$item = FF::getInstance(
'Data\SingleWordSearchItem',
$swsData['word'],
$this->convertServerQueryToClientUrl(
$swsData['searchParams']
),
$swsData['count']
$swsData['recordCount']
);

foreach ($swsData['previewRecords'] as $recordData)
{
$item->addPreviewRecord(FF::getInstance(
'Data\Record',
$item->addPreviewRecord(FF::getInstance('Data\Record',
(string)$recordData['id'],
$recordData['record']
// TODO: Which are other fields are returned for preview
// records?
// TODO: Add a test for this.
$recordData['record'],
$recordData['searchSimilarity'],
$recordData['position'],
'',
$recordData['keywords']
));
}

Expand Down
54 changes: 39 additions & 15 deletions src/FACTFinder/Core/Server/FileSystemDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ public function loadResponse($id)
$connectionData->setNullResponse();
return;
}
$fileNamePrefix = $this->getFileNamePrefix($connectionData);

$fileName = $this->getFileName($connectionData);
$fileExtension = $this->getFileExtension($connectionData);
$queryString = $this->getQueryString($connectionData);
$fileName = $this->getFileName($fileNamePrefix, md5($queryString), $fileExtension);

if (!$this->hasFileNameChanged($id, $fileName))
return;

$this->log->info("Trying to load file: $fileName");

$fileContent = null;
if(!$fileContent = @file_get_contents($fileName))
{
throw new \Exception('File "'.$fileName.' (original: ' . $fileNamePrefix . $queryString . $fileExtension . '" not found');
}

$response = FF::getInstance(
'Core\Server\Response',
file_get_contents($fileName),
$fileContent,
200,
0,
''
Expand All @@ -76,39 +85,54 @@ public function loadResponse($id)
$connectionData->setResponse($response, $fileName);
}

private function getFileName($connectionData)
private function getFileNamePrefix($connectionData)
{
$action = $connectionData->getAction();

// Replace the .ff file extension with an underscore.
$fileName = preg_replace('/[.]ff$/i', '_', $action);

$parameters = clone $connectionData->getParameters();
// Replace the .ff file extension with a dot.
$prefix = preg_replace('/[.]ff$/i', '.', $action);

return $prefix;
}

private function getFileExtension($connectionData)
{
$parameters = $connectionData->getParameters();

$fileExtension = null;
if (isset($parameters['format']))
$fileExtension = '.' . $parameters['format'];
else
$fileExtension = '.raw';


return $fileExtension;
}

private function getQueryString($connectionData)
{
$parameters = clone $connectionData->getParameters();

unset($parameters['format']);
unset($parameters['user']);
unset($parameters['pw']);
unset($parameters['timestamp']);
unset($parameters['channel']);

$rawParameters = &$parameters->getArray();

// We received that array by reference, so we can sort it to sort the
// Parameters object internally, too.
ksort($rawParameters, SORT_STRING);

$queryString = $parameters->toJavaQueryString();
$fileName .= str_replace('&', '_', $queryString);
$fileName .= $fileExtension;

return $this->fileLocation . $fileName;

return $queryString;
}

private function getFileName($prefix, $queryString, $extension)
{
return $this->fileLocation . $prefix . $queryString . $extension;
}

private function hasFileNameChanged($id, $newFileName)
{
$connectionData = $this->connectionData[$id];
Expand Down
3 changes: 0 additions & 3 deletions src/FACTFinder/Data/FilterStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class FilterStyle
static private $slider;
static private $tree;
static private $multiSelect;
static private $color;

// This ID is never used, but it ensures that an equality test between two
// different instances will return false (since '==' object comparison is
Expand Down Expand Up @@ -45,7 +44,6 @@ static public function initialize()
self::$slider = new FilterStyle();
self::$tree = new FilterStyle();
self::$multiSelect = new FilterStyle();
self::$color = new FilterStyle();

self::$initialized = true;
}
Expand All @@ -56,7 +54,6 @@ static public function Regular() { return self::$regular; }
static public function Slider() { return self::$slider; }
static public function Tree() { return self::$tree; }
static public function MultiSelect() { return self::$multiSelect; }
static public function Color() { return self::$color; }
}

// And finally we call the class initializer.
Expand Down
96 changes: 48 additions & 48 deletions src/FACTFinder/Util/Log4PhpLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,67 @@

class Log4PhpLogger implements LoggerInterface
{
protected $log;
protected $log;

/**
* Configures the static Logger class supplied by log4php.
*
* @param string $fileName Name of the configuration file
*/
public static function configure($fileName)
{
\Logger::configure($fileName);
}
public static function configure($fileName)
{
\Logger::configure($fileName);
}

/**
* Returns a new logger with the given name.
* @param string $name Name of the logger. This should be the fully
* qualified name of the class using this instance,
* so that different sub-namespaces can be configured
* differently. Note that in the configuration file, the
* loggers need to be qualified with periods instead of
* backslashes.
* @return Log4PhpLogger
*/
public static function getLogger($name)
{
$name = str_replace('\\', '.', $name);
return new Log4PhpLogger($name);
}
/**
* Returns a new logger with the given name.
* @param string $name Name of the logger. This should be the fully
* qualified name of the class using this instance,
* so that different sub-namespaces can be configured
* differently. Note that in the configuration file, the
* loggers need to be qualified with periods instead of
* backslashes.
* @return Log4PhpLogger
*/
public static function getLogger($name)
{
$name = str_replace('\\', '.', $name);
return new Log4PhpLogger($name);
}

protected function __construct($name)
{
$this->log = \Logger::getLogger($name);
}
protected function __construct($name)
{
$this->log = \Logger::getLogger($name);
}

public function trace($message)
{
$this->log->trace($message);
}
public function trace($message)
{
$this->log->trace($message);
}

public function debug($message)
{
$this->log->debug($message);
}
public function debug($message)
{
$this->log->debug($message);
}

public function info($message)
{
$this->log->info($message);
}
public function info($message)
{
$this->log->info($message);
}

public function warn($message)
{
$this->log->warn($message);
}
public function warn($message)
{
$this->log->warn($message);
}

public function error($message)
{
$this->log->error($message);
}
public function error($message)
{
$this->log->error($message);
}

public function fatal($message)
{
$this->log->fatal($message);
}
public function fatal($message)
{
$this->log->fatal($message);
}

}
2 changes: 1 addition & 1 deletion src/FACTFinder/Util/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function offsetExists($name)
*
* @throws InvalidArgumentException if the name has no values set.
*/
public function offsetGet($name)
public function offsetGet($name)
{
if (!isset($this->parameters[$name]))
throw new \InvalidArgumentException('Requested parameter has no value set.');
Expand Down
19 changes: 19 additions & 0 deletions tests/Adapter/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,23 @@ public function testNoArticleNumberSearchStatus()
$articleNumberSearchStatusEnum = FF::getClassName('Data\ArticleNumberSearchStatus');
$this->assertEquals($articleNumberSearchStatusEnum::IsNoArticleNumberSearch(), $this->adapter->getArticleNumberStatus());
}

public function testSingleWordSearchLoading()
{
$this->adapter->setQuery('helm && fahrrad && bekleidung && schuhe');

$singleWordSearchItems = $this->adapter->getSingleWordSearch();
$this->assertEquals(4, count($singleWordSearchItems));
$this->assertInstanceOf("FACTFinder\Data\SingleWordSearchItem", $singleWordSearchItems[0]);
$this->assertEquals('helm', $singleWordSearchItems[0]->getLabel());
$this->assertEquals('1350', $singleWordSearchItems[0]->getHitCount());
$this->assertEquals('/index.php?searchField=%2A&productsPerPage=10&keywords=helm', $singleWordSearchItems[0]->getUrl());
$previewRecords = $singleWordSearchItems[0]->getPreviewRecords();
$this->assertEquals(2, count($previewRecords));
$this->assertInstanceOf("FACTFinder\Data\Record", $previewRecords[0]);
$this->assertEquals(19451, $previewRecords[0]->getId());
$this->assertEquals(96.97, $previewRecords[0]->getSimilarity());
$this->assertEquals(1, $previewRecords[0]->getPosition());
$this->assertEquals('1', $previewRecords[0]->getField('__ORIG_POSITION__'));
}
}
2 changes: 1 addition & 1 deletion tests/Core/Server/FileSystemDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testLoadResponse()
$response = $connectionData->getResponse();
$expectedContent = file_get_contents(RESOURCES_DIR . DS
. 'responses' . DS
. 'TagCloud_do=getTagCloud.json');
. 'TagCloud.86b6b33590e092674009abfe3d7fc170.json');
$this->assertEquals(0, $response->getConnectionErrorCode());
$this->assertEquals('', $response->getConnectionError());
$this->assertEquals(200, $response->getHttpCode());
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Server/FileSystemRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testGetWorkingRequest()
$response = $request->getResponse();
$expectedContent = file_get_contents(RESOURCES_DIR . DS
. 'responses' . DS
. 'TagCloud_do=getTagCloud.json');
. 'TagCloud.86b6b33590e092674009abfe3d7fc170.json');
$this->assertEquals(0, $response->getConnectionErrorCode());
$this->assertEquals('', $response->getConnectionError());
$this->assertEquals(200, $response->getHttpCode());
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Server/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testGetResponse()
$response = $this->request->getResponse();
$expectedContent = file_get_contents(RESOURCES_DIR . DS
. 'responses' . DS
. 'TagCloud_do=getTagCloud.json');
. 'TagCloud.86b6b33590e092674009abfe3d7fc170.json');
$this->assertEquals(0, $response->getConnectionErrorCode());
$this->assertEquals('', $response->getConnectionError());
$this->assertEquals(200, $response->getHttpCode());
Expand All @@ -81,7 +81,7 @@ public function testResetLoaded()
$response = $this->request->getResponse();
$expectedContent = file_get_contents(RESOURCES_DIR . DS
. 'responses' . DS
. 'TagCloud_do=getTagCloud.json');
. 'TagCloud.86b6b33590e092674009abfe3d7fc170.json');
$this->assertEquals($expectedContent, $response->getContent());

//setup second request without changing parameters
Expand Down
44 changes: 44 additions & 0 deletions tests/Data/FilterSelectionTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace FACTFinder\Test\Data;

use FACTFinder\Loader as FF;

class FilterSelectionType extends \FACTFinder\Test\BaseTestCase
{
/**
* @var \FACTFinder\Util\LoggerInterface
*/
private $log;

/**
* @var string
*/
protected $selectionTypeClass;

public function setUp()
{
parent::setUp();

$this->selectionTypeClass = FF::getClassName('Data\FilterSelectionType');
$loggerClass = self::$dic['loggerClass'];
$this->log = $loggerClass::getLogger(__CLASS__);
}

public function testTypeSafety()
{
$selectionTypeClass = $this->selectionTypeClass;
$this->assertInstanceOf($selectionTypeClass, $selectionTypeClass::SingleHideUnselected());
$this->assertInstanceOf($selectionTypeClass, $selectionTypeClass::SingleShowUnselected());
$this->assertInstanceOf($selectionTypeClass, $selectionTypeClass::MultiSelectOr());
$this->assertInstanceOf($selectionTypeClass, $selectionTypeClass::MultiSelectAnd());
}

public function testEquality()
{
$selectionTypeClass = $this->selectionTypeClass;
$this->assertTrue($selectionTypeClass::SingleHideUnselected() == $selectionTypeClass::SingleHideUnselected());
$this->assertTrue($selectionTypeClass::SingleShowUnselected() == $selectionTypeClass::SingleShowUnselected());
$this->assertTrue($selectionTypeClass::MultiSelectOr() == $selectionTypeClass::MultiSelectOr());
$this->assertTrue($selectionTypeClass::MultiSelectAnd() == $selectionTypeClass::MultiSelectAnd());
}
}
Loading

0 comments on commit b45b225

Please sign in to comment.