mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
[SearchEngine] Add configuration panel unit tests
This commit is contained in:
@@ -4,14 +4,12 @@ namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
abstract class AbstractConfigurationPanel implements ConfigurationPanelInterface
|
||||
{
|
||||
abstract public function getName();
|
||||
|
||||
public function getConfigPathFile()
|
||||
{
|
||||
return __DIR__ . '/../../../../config/'.$this->getName().'.json';
|
||||
}
|
||||
|
||||
public function getAvailableDateFields($databoxes)
|
||||
public function getAvailableDateFields(array $databoxes)
|
||||
{
|
||||
$date_fields = array();
|
||||
|
||||
|
@@ -10,4 +10,12 @@ interface ConfigurationPanelInterface
|
||||
public function get(Application $app, Request $request);
|
||||
|
||||
public function post(Application $app, Request $request);
|
||||
|
||||
public function getName();
|
||||
|
||||
public function getConfiguration();
|
||||
|
||||
public function saveConfiguration(array $configuration);
|
||||
|
||||
public function getAvailableDateFields(array $databoxes);
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
|
||||
public function getConfiguration()
|
||||
{
|
||||
$configuration = @json_decode(file_get_contents(__DIR__ . '/../../../../../config/phrasea-engine.json'), true);
|
||||
$configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true);
|
||||
|
||||
if (!is_array($configuration)) {
|
||||
$configuration = array();
|
||||
@@ -69,4 +69,10 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
public function saveConfiguration(array $configuration)
|
||||
{
|
||||
file_put_contents($this->getConfigPathFile(), json_encode($configuration));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
use Alchemy\Phrasea\SearchEngine\AbstractConfigurationPanel;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
{
|
||||
@@ -30,7 +31,7 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
$params = array(
|
||||
'configuration' => $configuration,
|
||||
'configfile' => $this->generateSphinxConf($app['phraseanet.appbox']->get_databoxes(), $configuration),
|
||||
'charsets' => $this->get_available_charsets(),
|
||||
'charsets' => $this->getAvailableCharsets(),
|
||||
'date_fields' => $this->getAvailableDateFields($app['phraseanet.appbox']->get_databoxes()),
|
||||
);
|
||||
|
||||
@@ -95,14 +96,14 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
public function saveConfiguration($configuration)
|
||||
public function saveConfiguration(array $configuration)
|
||||
{
|
||||
file_put_contents($this->getConfigPathFile(), json_encode($configuration));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_available_charsets()
|
||||
public function getAvailableCharsets()
|
||||
{
|
||||
if (null !== $this->charsets) {
|
||||
return $this->charsets;
|
||||
@@ -110,7 +111,7 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
|
||||
$this->charsets = array();
|
||||
|
||||
$finder = new \Symfony\Component\Finder\Finder();
|
||||
$finder = new Finder();
|
||||
$finder->in(__DIR__ . '/Charset/')->files()->name('*.php');
|
||||
|
||||
foreach ($finder as $file) {
|
||||
|
@@ -1,26 +0,0 @@
|
||||
{% if app['request'].query.get('success') == '1' %}
|
||||
<div class="alert alert-success">
|
||||
<a class="close" data-dismiss="alert" href="#">×</a>
|
||||
{% trans 'Successful update' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form class="well form-inline" method='post' action='/admin/sphinx/configuration/'>
|
||||
<select name="charset_tables[]" multiple="multiple">
|
||||
{% for charset, charset_obj in configuration.get_available_charsets() %}
|
||||
<option value='{{ charset }}' {{ charset in options['charset_tables'] ? "selected='selected'" : "" }}>{{ charset_obj.get_name() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<select name="libstemmer[]" multiple="multiple">
|
||||
{% for stemme in configuration.get_available_libstemmer() %}
|
||||
<option value='{{ stemme }}' {{ stemme in options['libstemmer'] ? "selected='selected'" : "" }}>{{ stemme }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<button class='btn btn-primary'>{% trans 'boutton::valider' %}</button>
|
||||
</form>
|
||||
|
||||
<textarea style="width:100%;height:70%">
|
||||
{{ configuration.get_configuration(options) }}
|
||||
</textarea>
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
|
||||
|
||||
abstract class ConfigurationPanelAbstractTest extends \PhraseanetPHPUnitAuthenticatedAbstract
|
||||
{
|
||||
|
||||
abstract public function getPanel();
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertInternalType('string', $this->getPanel()->getName());
|
||||
}
|
||||
|
||||
public function testGetConfiguration()
|
||||
{
|
||||
$this->assertInternalType('array', $this->getPanel()->getConfiguration());
|
||||
}
|
||||
|
||||
public function testSaveConfiguration()
|
||||
{
|
||||
$config = $this->getPanel()->getConfiguration();
|
||||
$data = 'Yodelali' . mt_rand();
|
||||
$config['test'] = $data;
|
||||
$this->getPanel()->saveConfiguration($config);
|
||||
|
||||
$config = $this->getPanel()->getConfiguration();
|
||||
$this->assertEquals($data, $config['test']);
|
||||
}
|
||||
|
||||
public function testGetAvailableDateFields()
|
||||
{
|
||||
$dateFields = $this->getPanel()->getAvailableDateFields(self::$DI['app']['phraseanet.appbox']->get_databoxes());
|
||||
$this->assertInternalType('array', $dateFields);
|
||||
|
||||
foreach ($dateFields as $dateField) {
|
||||
$this->assertInternalType('string', $dateField);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine;
|
||||
use Alchemy\Phrasea\SearchEngine\Phrasea\ConfigurationPanel;
|
||||
|
||||
require_once __DIR__ . '/ConfigurationPanelAbstractTest.php';
|
||||
|
||||
class PhraseaConfigurationPanelTest extends ConfigurationPanelAbstractTest
|
||||
{
|
||||
public function getPanel()
|
||||
{
|
||||
return new ConfigurationPanel(new PhraseaEngine(self::$DI['app']));
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine;
|
||||
use Alchemy\Phrasea\SearchEngine\SphinxSearch\ConfigurationPanel;
|
||||
|
||||
require_once __DIR__ . '/ConfigurationPanelAbstractTest.php';
|
||||
|
||||
class SphinxSearchConfigurationPanelTest extends ConfigurationPanelAbstractTest
|
||||
{
|
||||
|
||||
public function getPanel()
|
||||
{
|
||||
return new ConfigurationPanel(new SphinxSearchEngine(self::$DI['app'], 'localhost', 9306, 'localhost', 9308));
|
||||
}
|
||||
|
||||
public function testGetAVailableCharsets()
|
||||
{
|
||||
$charsets = $this->getPanel()->getAvailableCharsets();
|
||||
|
||||
$this->assertInternalType('array', $charsets);
|
||||
foreach ($charsets as $name => $charset) {
|
||||
$this->assertInternalType('string', $name);
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\SearchEngine\SphinxSearch\AbstractCharset', $charset);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGenerateSphinxConf()
|
||||
{
|
||||
$conf = $this->getPanel()->generateSphinxConf();
|
||||
$this->assertInternalType('string', $conf);
|
||||
}
|
||||
|
||||
}
|
@@ -32,8 +32,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||
}
|
||||
self::$updated = true;
|
||||
}
|
||||
|
||||
self::$initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user