mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Merge pull request #1808 from bburnichon/improvement/search
Improvement/search
This commit is contained in:
@@ -314,7 +314,7 @@ class Manager
|
||||
break;
|
||||
case AttributeInterface::NAME_STATUS:
|
||||
/** @var StatusAttr $attribute */
|
||||
$element->set_binary_status(decbin(bindec($element->get_status()) | bindec($attribute->getValue())));
|
||||
$element->setStatus(decbin(bindec($element->getStatus()) | bindec($attribute->getValue())));
|
||||
|
||||
break;
|
||||
case AttributeInterface::NAME_STORY:
|
||||
|
@@ -84,7 +84,7 @@ class Step35 implements DatasUpgraderInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$record->set_binary_status($row['status']);
|
||||
$record->setStatus($row['status']);
|
||||
} catch (\Exception $e) {
|
||||
$this->app['monolog']->addError(sprintf("Error while upgrading status for record %d on databox %d : %s", $record->getRecordId(), $record->getDataboxId(), $e->getMessage()));
|
||||
}
|
||||
|
@@ -1545,7 +1545,7 @@ class V1Controller extends Controller
|
||||
|
||||
$status = $request->get('status');
|
||||
|
||||
$datas = strrev($record->get_status());
|
||||
$datas = strrev($record->getStatus());
|
||||
|
||||
if (!is_array($status)) {
|
||||
return $this->getBadRequestAction($request);
|
||||
@@ -1564,7 +1564,7 @@ class V1Controller extends Controller
|
||||
$datas = substr($datas, 0, ($n)) . $value . substr($datas, ($n + 2));
|
||||
}
|
||||
|
||||
$record->set_binary_status(strrev($datas));
|
||||
$record->setStatus(strrev($datas));
|
||||
|
||||
// @todo Move event dispatch inside record_adapter class (keeps things encapsulated)
|
||||
$this->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
|
||||
|
@@ -158,7 +158,7 @@ class EditController extends Controller
|
||||
if ($this->getAclForUser()->has_right_on_base($record->getBaseId(), 'chgstatus')) {
|
||||
$elements[$indice]['editableStatus'] = true;
|
||||
foreach ($status as $n => $s) {
|
||||
$tmp_val = substr(strrev($record->get_status()), $n, 1);
|
||||
$tmp_val = substr(strrev($record->getStatus()), $n, 1);
|
||||
$elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
|
||||
$elements[$indice]['statbits'][$n]['dirty'] = false;
|
||||
}
|
||||
@@ -347,7 +347,7 @@ class EditController extends Controller
|
||||
$this->getDispatcher()->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
|
||||
}
|
||||
|
||||
$newstat = $record->get_status();
|
||||
$newstat = $record->getStatus();
|
||||
$statbits = ltrim($statbits, 'x');
|
||||
if (!in_array($statbits, ['', 'null'])) {
|
||||
$mask_and = ltrim(str_replace(['x', '0', '1', 'z'], ['1', 'z', '0', '1'], $statbits), '0');
|
||||
@@ -361,7 +361,7 @@ class EditController extends Controller
|
||||
$newstat = \databox_status::operation_or($newstat, $mask_or);
|
||||
}
|
||||
|
||||
$record->set_binary_status($newstat);
|
||||
$record->setStatus($newstat);
|
||||
}
|
||||
|
||||
$record
|
||||
|
@@ -189,14 +189,14 @@ class PropertyController extends Controller
|
||||
|
||||
if (isset($postStatus[$sbasId]) && is_array($postStatus[$sbasId])) {
|
||||
$postStatus = $postStatus[$sbasId];
|
||||
$currentStatus = strrev($record->get_status());
|
||||
$currentStatus = strrev($record->getStatus());
|
||||
|
||||
$newStatus = '';
|
||||
foreach (range(0, 31) as $i) {
|
||||
$newStatus .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : $currentStatus[$i];
|
||||
}
|
||||
|
||||
$record->set_binary_status(strrev($newStatus));
|
||||
$record->setStatus(strrev($newStatus));
|
||||
|
||||
return [
|
||||
'current_status' => $currentStatus,
|
||||
|
@@ -125,7 +125,8 @@ class LegacyRecordRepository implements RecordRepository
|
||||
$connection->quoteIdentifier('type'),
|
||||
'originalname AS originalName',
|
||||
'sha256',
|
||||
'mime'
|
||||
'mime',
|
||||
'LPAD(BIN(status), 32, \'0\') as status'
|
||||
)
|
||||
->from('record', 'r');
|
||||
}
|
||||
|
@@ -194,7 +194,7 @@ class LazaretManipulator
|
||||
$value->appendChild($record);
|
||||
break;
|
||||
case AttributeInterface::NAME_STATUS:
|
||||
$record->set_binary_status($attribute->getValue());
|
||||
$record->setStatus($attribute->getValue());
|
||||
break;
|
||||
case AttributeInterface::NAME_METAFIELD:
|
||||
/** @var Border\Attribute\MetaField $attribute */
|
||||
|
@@ -50,7 +50,7 @@ class ESRecordSerializer extends AbstractSerializer
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach (preg_split('//', strrev($record->get_status()), -1, PREG_SPLIT_NO_EMPTY) as $val) {
|
||||
foreach (preg_split('//', strrev($record->getStatus()), -1, PREG_SPLIT_NO_EMPTY) as $val) {
|
||||
$status['status-'.$i] = (int) $val;
|
||||
$i++;
|
||||
}
|
||||
|
@@ -1011,7 +1011,7 @@ class ArchiveJob extends AbstractJob
|
||||
$story->set_metadatas($metaFields->toMetadataArray($metadatasStructure), true);
|
||||
}
|
||||
|
||||
$story->set_binary_status(\databox_status::operation_or($stat0, $stat1));
|
||||
$story->setStatus(\databox_status::operation_or($stat0, $stat1));
|
||||
$story->rebuild_subdefs();
|
||||
|
||||
unset($media);
|
||||
|
@@ -91,14 +91,14 @@ class RecordMoverJob extends AbstractJob
|
||||
|
||||
// change sb ?
|
||||
if (array_key_exists('sb', $row)) {
|
||||
$status = str_split($rec->get_status());
|
||||
$status = str_split($rec->getStatus());
|
||||
foreach (str_split(strrev($row['sb'])) as $bit => $val) {
|
||||
if ($val == '0' || $val == '1') {
|
||||
$status[31 - $bit] = $val;
|
||||
}
|
||||
}
|
||||
$status = implode('', $status);
|
||||
$rec->set_binary_status($status);
|
||||
$rec->setStatus($status);
|
||||
if ($logsql) {
|
||||
$this->log('debug', sprintf("on sbas %s set rid %s status to %s \n", $row['sbas_id'], $row['record_id'], $status));
|
||||
}
|
||||
|
2
lib/classes/cache/databox.php
vendored
2
lib/classes/cache/databox.php
vendored
@@ -75,8 +75,6 @@ class cache_databox
|
||||
$databox->delete_data_from_cache($key);
|
||||
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SHA256;
|
||||
$databox->delete_data_from_cache($key);
|
||||
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_STATUS;
|
||||
$databox->delete_data_from_cache($key);
|
||||
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_TECHNICAL_DATA;
|
||||
$databox->delete_data_from_cache($key);
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
@@ -39,7 +39,6 @@ use MediaVorus\MediaVorus;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
|
||||
|
||||
|
||||
class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
{
|
||||
const CACHE_ORIGINAL_NAME = 'originalname';
|
||||
@@ -49,7 +48,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
const CACHE_SHA256 = 'sha256';
|
||||
const CACHE_SUBDEFS = 'subdefs';
|
||||
const CACHE_GROUPING = 'grouping';
|
||||
const CACHE_STATUS = 'status';
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
@@ -79,6 +77,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
private $collection_id;
|
||||
private $mime;
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $status;
|
||||
private $subdefs;
|
||||
private $type;
|
||||
@@ -138,6 +140,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$this->created = $record->getCreated();
|
||||
$this->base_id = $record->getBaseId();
|
||||
$this->collection_id = $record->getCollectionId();
|
||||
$this->status = $record->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,51 +528,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->sha256;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_status()
|
||||
{
|
||||
if (!$this->status) {
|
||||
$this->status = $this->retrieve_status();
|
||||
}
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
protected function retrieve_status()
|
||||
{
|
||||
try {
|
||||
$data = $this->get_data_from_cache(self::CACHE_STATUS);
|
||||
} catch (Exception $e) {
|
||||
$data = false;
|
||||
}
|
||||
|
||||
if (false !== $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$status = $this->getDataboxConnection()->fetchColumn(
|
||||
'SELECT BIN(status) as status FROM record WHERE record_id = :record_id',
|
||||
[':record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
if (false === $status) {
|
||||
throw new Exception('status not found');
|
||||
}
|
||||
|
||||
$status = str_pad($status, 32, '0', STR_PAD_LEFT);
|
||||
|
||||
$this->set_data_to_cache($status, self::CACHE_STATUS);
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function has_subdef($name)
|
||||
{
|
||||
return in_array($name, $this->get_available_subdefs(), false);
|
||||
@@ -1108,26 +1066,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @return record_adapter
|
||||
*/
|
||||
public function set_binary_status($status)
|
||||
{
|
||||
$connection = $this->getDataboxConnection();
|
||||
|
||||
$connection->executeUpdate(
|
||||
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id= :record_id',
|
||||
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||
|
||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function dispatch($eventName, RecordEvent $event)
|
||||
{
|
||||
$this->app['dispatcher']->dispatch($eventName, $event);
|
||||
@@ -1511,9 +1449,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
{
|
||||
switch ($option)
|
||||
{
|
||||
case self::CACHE_STATUS:
|
||||
$this->status = null;
|
||||
break;
|
||||
case self::CACHE_SUBDEFS:
|
||||
$this->subdefs = null;
|
||||
break;
|
||||
@@ -1795,17 +1730,36 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->reference->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->set_binary_status($status);
|
||||
$this->getDataboxConnection()->executeUpdate(
|
||||
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id=:record_id',
|
||||
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||
$this->status = str_pad($status, 32, '0', STR_PAD_LEFT);
|
||||
// modification date is now unknown, delete from cache to reload on another record
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getStatusBitField()
|
||||
{
|
||||
return bindec($this->get_status());
|
||||
return bindec($this->getStatus());
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
@@ -1832,6 +1786,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
'created' => $this->created->format(DATE_ISO8601),
|
||||
'base_id' => $this->base_id,
|
||||
'collection_id' => $this->collection_id,
|
||||
'status' => $this->status,
|
||||
];
|
||||
|
||||
$this->set_data_to_cache($data);
|
||||
@@ -1857,6 +1812,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$this->original_name = $row['originalName'];
|
||||
$this->sha256 = $row['sha256'];
|
||||
$this->mime = $row['mime'];
|
||||
$this->status = str_pad($row['status'], 32, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -13,6 +13,7 @@ use Alchemy\Phrasea\Border\Attribute\MetaField;
|
||||
use Alchemy\Phrasea\Border\Attribute\Metadata;
|
||||
use Alchemy\Phrasea\Border\Attribute\Status;
|
||||
use Alchemy\Phrasea\Border\Attribute\Story;
|
||||
use Alchemy\Phrasea\Model\Entities\LazaretFile;
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
@@ -144,13 +145,15 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$records = [];
|
||||
|
||||
$postProcessRecord = function ($record) use (&$records) {
|
||||
$records[] = $record;
|
||||
};
|
||||
$records[] = $record;
|
||||
};
|
||||
|
||||
$file = File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']);
|
||||
$app = $this->getApplication();
|
||||
$collection = $this->getCollection();
|
||||
$file = File::buildFromPathfile(self::$file1, $collection, $app);
|
||||
$first = $odd = false;
|
||||
$tofetch = [];
|
||||
foreach (self::$DI['collection']->get_databox()->get_meta_structure() as $databox_field) {
|
||||
foreach ($collection->get_databox()->get_meta_structure() as $databox_field) {
|
||||
if ($databox_field->is_readonly()) {
|
||||
continue;
|
||||
}
|
||||
@@ -196,7 +199,7 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$odd = !$odd;
|
||||
}
|
||||
|
||||
$story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
|
||||
$story = \record_adapter::createStory($app, $collection);
|
||||
$file->addAttribute(new Story($story));
|
||||
|
||||
$status = '';
|
||||
@@ -208,17 +211,19 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
}
|
||||
}
|
||||
|
||||
$file->addAttribute(new Status(self::$DI['app'], strrev($status)));
|
||||
$file->addAttribute(new Status($app, strrev($status)));
|
||||
|
||||
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
|
||||
$app['phraseanet.SE'] = $this->createSearchEngineMock();
|
||||
$this->assertEquals(Manager::RECORD_CREATED, $this->object->process($this->session, $file, $postProcessRecord, Manager::FORCE_RECORD));
|
||||
|
||||
/** @var \record_adapter $record */
|
||||
$record = current($records);
|
||||
$this->assertInstanceOf(\record_adapter::class, $record);
|
||||
|
||||
$found = false;
|
||||
|
||||
foreach ($record->get_grouping_parents()->get_elements() as $parent_story) {
|
||||
if ($parent_story->get_serialize_key() === $story->getId()) {
|
||||
if ($parent_story->getId() === $story->getId()) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
@@ -227,18 +232,19 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->fail('Unable to find story in parents');
|
||||
}
|
||||
|
||||
$status = strrev($record->get_status());
|
||||
$status = strrev($record->getStatus());
|
||||
|
||||
$this->assertEquals(32, strlen($status));
|
||||
$this->assertEquals('1', substr($status, 4, 1));
|
||||
$this->assertEquals('1', substr($status, 8, 1));
|
||||
|
||||
foreach ($tofetch as $name => $values) {
|
||||
|
||||
$found = [];
|
||||
|
||||
foreach ($record->get_caption()->get_field($name)->get_values() as $value) {
|
||||
$found[] = $value->getValue();
|
||||
}
|
||||
|
||||
$this->assertEquals($values, $found);
|
||||
}
|
||||
|
||||
@@ -261,10 +267,12 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$lazaret = $element;
|
||||
};
|
||||
|
||||
$file = File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']);
|
||||
$app = $this->getApplication();
|
||||
$collection = $this->getCollection();
|
||||
$file = File::buildFromPathfile(self::$file1, $collection, $app);
|
||||
$odd = false;
|
||||
$tofetchMeta = $tofetchField = [];
|
||||
foreach (self::$DI['collection']->get_databox()->get_meta_structure() as $databox_field) {
|
||||
foreach ($collection->get_databox()->get_meta_structure() as $databox_field) {
|
||||
if ($databox_field->is_readonly()) {
|
||||
continue;
|
||||
}
|
||||
@@ -300,14 +308,16 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$odd = !$odd;
|
||||
}
|
||||
|
||||
$file->addAttribute(new Story(self::$DI['record_story_1']));
|
||||
$story = $this->getRecordStory1();
|
||||
$file->addAttribute(new Story($story));
|
||||
|
||||
$status = '1';
|
||||
|
||||
foreach (range(1, 31) as $i) {
|
||||
$status .= '0';
|
||||
}
|
||||
|
||||
$file->addAttribute(new Status(self::$DI['app'], $status));
|
||||
$file->addAttribute(new Status($app, $status));
|
||||
|
||||
$this->assertEquals(Manager::LAZARET_CREATED, $this->object->process($this->session, $file, $postProcessRecord, Manager::FORCE_LAZARET));
|
||||
|
||||
@@ -315,12 +325,13 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$foundMeta = $foundField = [];
|
||||
|
||||
/* @var $lazaret \Alchemy\Phrasea\Model\Entities\LazaretFile */
|
||||
/** @var LazaretFile $lazaret */
|
||||
foreach ($lazaret->getAttributes() as $attr) {
|
||||
$attribute = Factory::getFileAttribute(self::$DI['app'], $attr->getName(), $attr->getValue());
|
||||
$attribute = Factory::getFileAttribute($app, $attr->getName(), $attr->getValue());
|
||||
|
||||
if ($attribute->getName() == AttributeInterface::NAME_STORY) {
|
||||
if ($attribute->getValue()->get_serialize_key() == self::$DI['record_story_1']->get_serialize_key()) {
|
||||
/** @var Story $attribute */
|
||||
if ($attribute->getValue()->getId() == $story->getId()) {
|
||||
$story_found = true;
|
||||
}
|
||||
} elseif ($attribute->getName() == AttributeInterface::NAME_METADATA) {
|
||||
|
@@ -1234,13 +1234,15 @@ class ApiJsonTest extends ApiTestCase
|
||||
|
||||
public function testRecordsSetStatus()
|
||||
{
|
||||
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
|
||||
$app = $this->getApplication();
|
||||
$app['phraseanet.SE'] = $this->createSearchEngineMock();
|
||||
$this->setToken($this->userAccessToken);
|
||||
|
||||
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/setstatus/';
|
||||
$record1 = $this->getRecord1();
|
||||
$route = '/api/v1/records/' . $record1->getDataboxId() . '/' . $record1->getRecordId() . '/setstatus/';
|
||||
|
||||
$record_status = strrev(self::$DI['record_1']->get_status());
|
||||
$statusStructure = self::$DI['record_1']->getStatusStructure();
|
||||
$record_status = strrev($record1->getStatus());
|
||||
$statusStructure = $record1->getStatusStructure();
|
||||
|
||||
$tochange = [];
|
||||
foreach ($statusStructure as $n => $datas) {
|
||||
@@ -1248,20 +1250,18 @@ class ApiJsonTest extends ApiTestCase
|
||||
}
|
||||
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
|
||||
|
||||
self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
|
||||
$response = $this->request('POST', $route, $this->getParameters(['status' => $tochange]), ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
$content = $this->unserialize($response->getContent());
|
||||
|
||||
/**
|
||||
* Get fresh record_1
|
||||
*/
|
||||
$testRecord = new \record_adapter(self::$DI['app'], self::$DI['record_1']->get_sbas_id(), self::$DI['record_1']->get_record_id());
|
||||
// Get fresh record_1
|
||||
$testRecord = new \record_adapter($app, $record1->getDataboxId(), $record1->getRecordId());
|
||||
|
||||
$this->evaluateResponse200(self::$DI['client']->getResponse());
|
||||
$this->evaluateResponse200($response);
|
||||
$this->evaluateMeta200($content);
|
||||
|
||||
$this->evaluateRecordsStatusResponse($testRecord, $content);
|
||||
|
||||
$record_status = strrev($testRecord->get_status());
|
||||
$record_status = strrev($testRecord->getStatus());
|
||||
foreach ($statusStructure as $n => $datas) {
|
||||
$this->assertEquals(substr($record_status, ($n), 1), $tochange[$n]);
|
||||
}
|
||||
@@ -1270,25 +1270,23 @@ class ApiJsonTest extends ApiTestCase
|
||||
$tochange[$n] = $value == '0' ? '1' : '0';
|
||||
}
|
||||
|
||||
self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
|
||||
$response = $this->request('POST', $route, $this->getParameters(['status' => $tochange]), ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
$content = $this->unserialize($response->getContent());
|
||||
|
||||
/**
|
||||
* Get fresh record_1
|
||||
*/
|
||||
$testRecord = new \record_adapter(self::$DI['app'], $testRecord->getDataboxId(), $testRecord->getRecordId());
|
||||
// Get fresh record_1
|
||||
$testRecord = new \record_adapter($app, $testRecord->getDataboxId(), $testRecord->getRecordId());
|
||||
|
||||
$this->evaluateResponse200(self::$DI['client']->getResponse());
|
||||
$this->evaluateResponse200($response);
|
||||
$this->evaluateMeta200($content);
|
||||
|
||||
$this->evaluateRecordsStatusResponse($testRecord, $content);
|
||||
|
||||
$record_status = strrev($testRecord->get_status());
|
||||
$record_status = strrev($testRecord->getStatus());
|
||||
foreach ($statusStructure as $n => $datas) {
|
||||
$this->assertEquals(substr($record_status, ($n), 1), $tochange[$n]);
|
||||
}
|
||||
|
||||
self::$DI['record_1']->set_binary_status(str_repeat('0', 32));
|
||||
$record1->setStatus(str_repeat('0', 32));
|
||||
}
|
||||
|
||||
public function testMoveRecordToCollection()
|
||||
|
@@ -696,7 +696,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
$statusStructure = $record->getDatabox()->getStatusStructure();
|
||||
|
||||
$r_status = strrev($record->get_status());
|
||||
$r_status = strrev($record->getStatus());
|
||||
$this->assertArrayHasKey('status', $content['response']);
|
||||
$this->assertEquals(count((array) $content['response']['status']), count($statusStructure->toArray()));
|
||||
foreach ($content['response']['status'] as $status) {
|
||||
|
@@ -119,8 +119,8 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$record = new \record_adapter(self::$DI['app'], $record->getDataboxId(), $record->getRecordId());
|
||||
$story = new \record_adapter(self::$DI['app'], $story->getDataboxId(), $story->getRecordId());
|
||||
|
||||
$recordStatus = strrev($record->get_status());
|
||||
$storyStatus = strrev($story->get_status());
|
||||
$recordStatus = strrev($record->getStatus());
|
||||
$storyStatus = strrev($story->getStatus());
|
||||
|
||||
$this->assertEquals(1, substr($recordStatus, 6, 1));
|
||||
$this->assertEquals(1, substr($recordStatus, 8, 1));
|
||||
@@ -131,7 +131,7 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertEquals(1, substr($storyStatus, 11, 1));
|
||||
|
||||
foreach ($story->getChildren() as $child) {
|
||||
$childStatus = strrev($child->get_status());
|
||||
$childStatus = strrev($child->getStatus());
|
||||
$this->assertEquals(1, substr($childStatus, 6, 1));
|
||||
$this->assertEquals(1, substr($childStatus, 8, 1));
|
||||
$this->assertEquals(1, substr($childStatus, 11, 1));
|
||||
|
@@ -377,7 +377,7 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$id = explode('_', $datas['id']);
|
||||
$record = new \record_adapter(self::$DI['app'], $id[0], $id[1]);
|
||||
$this->assertFalse($record->isStory());
|
||||
$this->assertEquals(1, substr(strrev($record->get_status()), 4, 1));
|
||||
$this->assertEquals(1, substr(strrev($record->getStatus()), 4, 1));
|
||||
$this->assertEquals([], $datas['reasons']);
|
||||
}
|
||||
|
||||
|
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticSearchEngine;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer;
|
||||
|
||||
class ElasticSearchEngineTest extends SearchEngineAbstractTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
if (false === @file_get_contents('http://localhost:9200')) {
|
||||
$this->markTestSkipped('Unable to connect to elasticsearch.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
/** @var Indexer $indexer */
|
||||
$indexer = self::$DI['app']['elasticsearch.indexer'];
|
||||
|
||||
// Re-index everything
|
||||
ob_start();
|
||||
$indexer->deleteIndex();
|
||||
$indexer->createIndex();
|
||||
$indexer->populateIndex();
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
// Change the index name
|
||||
self::$DI['app']['conf']->set(['main', 'search-engine', 'options', 'index'], 'test');
|
||||
|
||||
self::$searchEngine = $es = new ElasticSearchEngine(
|
||||
self::$DI['app'],
|
||||
self::$DI['app']['elasticsearch.client'],
|
||||
self::$DI['app']['elasticsearch.options']['index']
|
||||
);
|
||||
|
||||
self::$searchEngineClass = 'Alchemy\Phrasea\SearchEngine\Elastic\ElasticSearchEngine';
|
||||
}
|
||||
|
||||
public function testAutocomplete()
|
||||
{
|
||||
$this->markTestSkipped("Not implemented yet.");
|
||||
}
|
||||
|
||||
protected function updateIndex(array $stemms = [])
|
||||
{
|
||||
$client = self::$searchEngine->getClient();
|
||||
$client->indices()->refresh();
|
||||
}
|
||||
}
|
@@ -1,719 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
||||
|
||||
abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
|
||||
{
|
||||
protected $options;
|
||||
/**
|
||||
* @var SearchEngineInterface
|
||||
*/
|
||||
protected static $searchEngine;
|
||||
protected static $searchEngineClass;
|
||||
private static $initialized = false;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!self::$initialized) {
|
||||
$found = false;
|
||||
foreach (self::$DI['record_2']->get_databox()->get_meta_structure()->get_elements() as $field) {
|
||||
if (!$field->isBusiness()) {
|
||||
continue;
|
||||
}
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$field = \databox_field::create(self::$DI['app'], self::$DI['record_2']->get_databox(), 'testBusiness' . mt_rand(), false);
|
||||
$field->set_business(true);
|
||||
$field->save();
|
||||
}
|
||||
|
||||
foreach (self::$DI['app']->getDataboxes() as $databox) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
|
||||
if (!self::$searchEngine instanceof SearchEngineInterface) {
|
||||
$this->markTestSkipped('Unable to initialize search Engine');
|
||||
}
|
||||
|
||||
$options = new SearchEngineOptions();
|
||||
$options->onCollections($databox->get_collections());
|
||||
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$searchEngine = self::$searchEngineClass = self::$initialized = null;
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SearchEngineOptions
|
||||
*/
|
||||
private function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function testQueryRecordId()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'recordid=' . $record->get_record_id();
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
|
||||
$result = $results->getResults()->first();
|
||||
|
||||
$this->assertEquals($record->get_record_id(), $result->get_record_id());
|
||||
$this->assertEquals($record->get_sbas_id(), $result->get_sbas_id());
|
||||
}
|
||||
|
||||
public function testQueryStoryId()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'storyid=' . $record->get_record_id();
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
|
||||
$result = $results->getResults()->first();
|
||||
|
||||
$this->assertEquals($record->get_record_id(), $result->get_record_id());
|
||||
$this->assertEquals($record->get_sbas_id(), $result->get_sbas_id());
|
||||
}
|
||||
|
||||
public function testQueryByDateMin()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'dateMin';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
||||
|
||||
if (!$date_field) {
|
||||
$this->markTestSkipped('unable to add a date to record');
|
||||
}
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options->setDateFields([$date_field]);
|
||||
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-23 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
private function editDateRecord($date, \record_adapter $record)
|
||||
{
|
||||
$date_field = null;
|
||||
|
||||
foreach ($record->getDatabox()->get_meta_structure() as $databox_field) {
|
||||
if ($databox_field->get_type() != \databox_field::TYPE_DATE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$date_field = $databox_field;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($date_field) {
|
||||
|
||||
$toupdate = [];
|
||||
|
||||
try {
|
||||
$values = $record->get_caption()->get_field($databox_field->get_name())->get_values();
|
||||
$value = array_pop($values);
|
||||
$meta_id = $value->getId();
|
||||
} catch (\Exception $e) {
|
||||
$meta_id = null;
|
||||
}
|
||||
|
||||
$toupdate[$databox_field->get_id()] = [
|
||||
'meta_id' => $meta_id
|
||||
, 'meta_struct_id' => $databox_field->get_id()
|
||||
, 'value' => $date
|
||||
];
|
||||
|
||||
$record->set_metadatas($toupdate);
|
||||
}
|
||||
|
||||
return $date_field;
|
||||
}
|
||||
|
||||
public function testQueryByDateMax()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'dateMax';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
||||
|
||||
if (!$date_field) {
|
||||
$this->markTestSkipped('unable to add a date to record');
|
||||
}
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options->setDateFields([$date_field]);
|
||||
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-23 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testQueryByDateRange()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'dateRange';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
||||
|
||||
if (!$date_field) {
|
||||
$this->markTestSkipped('unable to add a date to record');
|
||||
}
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options->setDateFields([$date_field]);
|
||||
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-18 01:01:00'));
|
||||
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-22 01:01:00'));
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
protected function editRecord($string2add, \record_adapter &$record, $indexable = true, $business = false)
|
||||
{
|
||||
$toupdate = [];
|
||||
$field = null;
|
||||
|
||||
foreach ($record->getDatabox()->get_meta_structure()->get_elements() as $field) {
|
||||
|
||||
if ($indexable !== $field->is_indexable() || $field->isBusiness() !== $business) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$values = $record->get_caption()->get_field($field->get_name())->get_values();
|
||||
$value = array_pop($values);
|
||||
$meta_id = $value->getId();
|
||||
} catch (\Exception $e) {
|
||||
$meta_id = null;
|
||||
}
|
||||
|
||||
$toupdate[$field->get_id()] = [
|
||||
'meta_id' => $meta_id
|
||||
, 'meta_struct_id' => $field->get_id()
|
||||
, 'value' => $string2add
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
$record->set_metadatas($toupdate);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function testRecordNotIndexed()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultNotIndexed';
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$this->updateIndex();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testAddRecord()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultAdd';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testUpdateRecord()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'updateRecord';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->updateRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
protected function getDefaultOptions()
|
||||
{
|
||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
break;
|
||||
}
|
||||
$options = new SearchEngineOptions();
|
||||
$options->onCollections($databox->get_collections());
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideStemmData
|
||||
*/
|
||||
public function testUpdateRecordWithStemm($language, $word, $stemm)
|
||||
{
|
||||
if (!self::$searchEngine->hasStemming()) {
|
||||
$this->markTestSkipped(sprintf(
|
||||
'%s does not support stemm, passing stemmatization for language %s',
|
||||
get_class(self::$searchEngine),
|
||||
$language
|
||||
));
|
||||
}
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setStemming(true);
|
||||
$options->setLocale($language);
|
||||
|
||||
$record = self::$DI['record_2'];
|
||||
$index_string = sprintf(
|
||||
'boomboklot%dstemmed%s %s',
|
||||
$record->get_record_id(),
|
||||
$language,
|
||||
$word
|
||||
);
|
||||
$query_string = sprintf(
|
||||
'boomboklot%dstemmed%s %s',
|
||||
$record->get_record_id(),
|
||||
$language,
|
||||
$stemm
|
||||
);
|
||||
|
||||
$this->editRecord($index_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex([$language]);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function provideStemmData()
|
||||
{
|
||||
$stemms = [];
|
||||
|
||||
$examples = [
|
||||
'fr' => ['word' => 'chevaux', 'stemm' => 'cheval'],
|
||||
'en' => ['word' => 'consistency', 'stemm' => 'consistent'],
|
||||
'de' => ['word' => 'aufeinanderfolgender', 'stemm' => 'aufeinanderfolg'],
|
||||
'nl' => ['word' => 'lichamelijk', 'stemm' => 'licham'],
|
||||
];
|
||||
|
||||
foreach (Application::getAvailableLanguages() as $languageCode => $name) {
|
||||
$data = explode('_', $languageCode);
|
||||
$code = $data[0];
|
||||
|
||||
if (!isset($examples[$code])) {
|
||||
$this->fail(sprintf('Missing stemm examples for language %s', $code));
|
||||
}
|
||||
|
||||
$stemms[] = [
|
||||
$code,
|
||||
$examples[$code]['word'],
|
||||
$examples[$code]['stemm'],
|
||||
];
|
||||
}
|
||||
|
||||
return $stemms;
|
||||
}
|
||||
|
||||
public function testUpdateQueryOnField()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$DI['record_2'];
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'onfield';
|
||||
|
||||
$field = $this->editRecord($query_string, $record);
|
||||
$options->setFields([$field]);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testBusinessFieldAvailable()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$DI['record_2'];
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'businessAvailable';
|
||||
|
||||
$this->editRecord($query_string, $record, true, true);
|
||||
$options->allowBusinessFieldsOn([$record->get_collection()]);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testBusinessFieldNotAvailable()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'businessNotAvailable';
|
||||
|
||||
$this->editRecord($query_string, $record, true, true);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testUpdateQueryOnEmptyField()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'anotherfield';
|
||||
|
||||
$selectedField = $this->editRecord($query_string, $record);
|
||||
|
||||
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
||||
if ($selectedField->get_id() != $field->get_id()) {
|
||||
$options->setFields([$field]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testUpdateNonIndexableRecord()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot_no_index_' . $record->get_record_id() . '_';
|
||||
|
||||
$field = $this->editRecord($query_string, $record, false);
|
||||
if (!$field) {
|
||||
$this->markTestSkipped('No non-indexable field found');
|
||||
}
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testDeleteRecord()
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'deleteRecord';
|
||||
|
||||
$field = $this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
self::$searchEngine->removeRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setFields([$field]);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideStemmData
|
||||
*/
|
||||
public function testDeleteRecordWithinStemmContext($language, $word, $stemm)
|
||||
{
|
||||
$record = self::$DI['record_2'];
|
||||
$index_string = 'boomboklot' . $record->get_record_id() . 'deleteRecordInStemmContext '.$word;
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'deleteRecordInStemmContext '.$stemm;
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setStemming(true);
|
||||
$options->setLocale($language);
|
||||
|
||||
$field = $this->editRecord($index_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
self::$searchEngine->removeRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$options->setFields([$field]);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testAvailableTypes()
|
||||
{
|
||||
$this->assertTrue(is_array(self::$searchEngine->getAvailableTypes()));
|
||||
foreach (self::$searchEngine->getAvailableTypes() as $type) {
|
||||
$this->assertTrue(in_array($type, [SearchEngineInterface::GEM_TYPE_ENTRY, SearchEngineInterface::GEM_TYPE_RECORD, SearchEngineInterface::GEM_TYPE_STORY]));
|
||||
}
|
||||
}
|
||||
|
||||
public function testStatus()
|
||||
{
|
||||
foreach (self::$searchEngine->getStatus() as $StatusKeyValue) {
|
||||
$this->assertTrue(is_array($StatusKeyValue));
|
||||
$this->assertTrue(is_scalar($StatusKeyValue[0]));
|
||||
$this->assertTrue(is_scalar($StatusKeyValue[1]));
|
||||
}
|
||||
}
|
||||
|
||||
public function testAddStory()
|
||||
{
|
||||
$story = self::$DI['record_story_1'];
|
||||
$query_string = 'story' . $story->get_record_id() . 'addStory';
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
|
||||
|
||||
$this->editRecord($query_string, $story);
|
||||
|
||||
self::$searchEngine->addStory($story);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testUpdateStory()
|
||||
{
|
||||
$story = self::$DI['record_story_1'];
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
|
||||
|
||||
self::$searchEngine->addStory($story);
|
||||
$this->updateIndex();
|
||||
|
||||
$query_string = 'story' . $story->get_record_id() . 'updateStory';
|
||||
$this->editRecord($query_string, $story);
|
||||
|
||||
self::$searchEngine->updateStory($story);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testStatusQueryOnOverOff()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$DI['record_2'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testStatusQueryOnOverOn()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$DI['record_2'];
|
||||
$record->set_binary_status('10000');
|
||||
|
||||
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOnOverOn';
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testStatusQueryOffOverOn()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$DI['record_2'];
|
||||
$record->set_binary_status('10000');
|
||||
|
||||
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testStatusQueryOffOverOff()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$DI['record_2'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
public function testStatusQueryUpdate()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$DI['record_2'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryUpdate';
|
||||
$this->editRecord($query_string, $record);
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
||||
$this->assertEquals(0, $results->getTotal());
|
||||
|
||||
$record->set_binary_status('10000');
|
||||
|
||||
self::$searchEngine->updateRecord($record);
|
||||
$this->updateIndex();
|
||||
|
||||
self::$searchEngine->resetCache();
|
||||
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
||||
$this->assertEquals(1, $results->getTotal());
|
||||
}
|
||||
|
||||
abstract public function initialize();
|
||||
|
||||
abstract public function testAutocomplete();
|
||||
|
||||
abstract protected function updateIndex(array $stemms = []);
|
||||
}
|
@@ -33,25 +33,25 @@ class ACLTest extends \PhraseanetTestCase
|
||||
{
|
||||
$record1 = $this->getRecord1();
|
||||
|
||||
$record1->set_binary_status(str_repeat('0', 32));
|
||||
$record1->setStatus(str_repeat('0', 32));
|
||||
$this->object->set_masks_on_base($record1->getBaseId(), '10000', '10000', '0', '0');
|
||||
|
||||
$record1->set_binary_status('10000');
|
||||
$record1->setStatus('10000');
|
||||
$this->assertFalse($this->object->has_status_access_to_record($record1));
|
||||
|
||||
$record1->set_binary_status('00000');
|
||||
$record1->setStatus('00000');
|
||||
$this->assertTrue($this->object->has_status_access_to_record($record1));
|
||||
|
||||
$this->object->set_masks_on_base($record1->getBaseId(), '10000', '10000', '10000', '10000');
|
||||
$this->assertFalse($this->object->has_status_access_to_record($record1));
|
||||
|
||||
$record1->set_binary_status('10000');
|
||||
$record1->setStatus('10000');
|
||||
$this->assertTrue($this->object->has_status_access_to_record($record1));
|
||||
|
||||
$this->object->set_masks_on_base($record1->getBaseId(), '0', '0', '0', '0');
|
||||
$this->assertTrue($this->object->has_status_access_to_record($record1));
|
||||
|
||||
$record1->set_binary_status(str_repeat('0', 32));
|
||||
$record1->setStatus(str_repeat('0', 32));
|
||||
$this->assertTrue($this->object->has_status_access_to_record($record1));
|
||||
}
|
||||
|
||||
|
@@ -232,7 +232,7 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
|
||||
|
||||
public function testGet_status()
|
||||
{
|
||||
$this->assertRegExp('/[01]{32}/', $this->getRecord1()->get_status());
|
||||
$this->assertRegExp('/[01]{32}/', $this->getRecord1()->getStatus());
|
||||
}
|
||||
|
||||
public function testGet_subdef()
|
||||
@@ -474,9 +474,9 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
|
||||
}
|
||||
|
||||
$record_1 = $this->getRecord1();
|
||||
$record_1->set_binary_status($status);
|
||||
$record_1->setStatus($status);
|
||||
|
||||
$this->assertEquals($status, $record_1->get_status());
|
||||
$this->assertEquals($status, $record_1->getStatus());
|
||||
}
|
||||
|
||||
public function testGet_record_by_sha()
|
||||
@@ -539,7 +539,7 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
|
||||
{
|
||||
$record_1 = $this->getRecord1();
|
||||
$record = new \record_adapter($this->getApplication(), $record_1->getDataboxId(), $record_1->getRecordId());
|
||||
$record->set_binary_status('1001001001010101');
|
||||
$this->assertSame('00000000000000001001001001010101', $record->get_status());
|
||||
$record->setStatus('1001001001010101');
|
||||
$this->assertSame('00000000000000001001001001010101', $record->getStatus());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user