|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\IndexQueue; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This function is used to overwrite uniqid in the IndexQueue context to provide a fake request id. |
|
7
|
|
|
* We use this since this is a integration test and the unique id could not be injected from outside. |
|
8
|
|
|
* |
|
9
|
|
|
* @return string |
|
10
|
|
|
*/ |
|
11
|
|
|
function uniqid() |
|
12
|
|
|
{ |
|
13
|
|
|
return \ApacheSolrForTypo3\Solr\Tests\Integration\Task\IndexQueueDependencyFaker::getRequestId(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This function fakes the file_get_contents calls to provied a faked frontend indexing response. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $url |
|
20
|
|
|
* @param boolean $flags |
|
21
|
|
|
* @param resource $context |
|
22
|
|
|
* |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
function file_get_contents($url, $flags, $context) |
|
26
|
|
|
{ |
|
27
|
|
|
return \ApacheSolrForTypo3\Solr\Tests\Integration\Task\IndexQueueDependencyFaker::getHttpContent($url, $flags, |
|
28
|
|
|
$context); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
namespace ApacheSolrForTypo3\Solr\Tests\Integration\Task; |
|
32
|
|
|
|
|
33
|
|
|
/*************************************************************** |
|
34
|
|
|
* Copyright notice |
|
35
|
|
|
* |
|
36
|
|
|
* (c) 2015 Timo Schmidt <[email protected]> |
|
37
|
|
|
* All rights reserved |
|
38
|
|
|
* |
|
39
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
40
|
|
|
* free software; you can redistribute it and/or modify |
|
41
|
|
|
* it under the terms of the GNU General Public License as published by |
|
42
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
43
|
|
|
* (at your option) any later version. |
|
44
|
|
|
* |
|
45
|
|
|
* The GNU General Public License can be found at |
|
46
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
47
|
|
|
* |
|
48
|
|
|
* This script is distributed in the hope that it will be useful, |
|
49
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
50
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
51
|
|
|
* GNU General Public License for more details. |
|
52
|
|
|
* |
|
53
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
54
|
|
|
***************************************************************/ |
|
55
|
|
|
|
|
56
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
|
57
|
|
|
use ApacheSolrForTypo3\Solr\Site; |
|
58
|
|
|
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest; |
|
59
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\RecordMonitor; |
|
60
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
|
61
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* TestCase to check if we can indexer from a index queue worker task into a solr server |
|
65
|
|
|
* |
|
66
|
|
|
* @author Timo Schmidt |
|
67
|
|
|
* @package TYPO3 |
|
68
|
|
|
* @subpackage solr |
|
69
|
|
|
*/ |
|
70
|
|
|
class IndexQueueWorkerTest extends IntegrationTest |
|
71
|
|
|
{ |
|
72
|
|
|
/** |
|
73
|
|
|
* @var Queue |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $indexQueue; |
|
76
|
|
|
|
|
77
|
|
|
public function setUp() |
|
78
|
|
|
{ |
|
79
|
|
|
parent::setUp(); |
|
80
|
|
|
$this->indexQueue = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\IndexQueue\Queue'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @test |
|
85
|
|
|
*/ |
|
86
|
|
|
public function canTriggerFrontendIndexingAndMarkQueueEntryAsProcessed() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->importDataSetFromFixture('can_trigger_frontend_calls_for_page_index.xml'); |
|
89
|
|
|
|
|
90
|
|
|
// we expect that the index queue is empty before we start |
|
91
|
|
|
$this->assertFalse($this->indexQueue->containsIndexedItem('pages', 1)); |
|
92
|
|
|
|
|
93
|
|
|
/** @var $beUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */ |
|
94
|
|
|
$beUser = GeneralUtility::makeInstance('TYPO3\CMS\Core\Authentication\BackendUserAuthentication'); |
|
95
|
|
|
$GLOBALS['BE_USER'] = $beUser; |
|
96
|
|
|
|
|
97
|
|
|
/** @var $languageService \TYPO3\CMS\Lang\LanguageService */ |
|
98
|
|
|
$languageService = GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService'); |
|
99
|
|
|
$GLOBALS['LANG'] = $languageService; |
|
100
|
|
|
|
|
101
|
|
|
$charsetConverter = GeneralUtility::makeInstance('TYPO3\CMS\Core\Charset\CharsetConverter'); |
|
102
|
|
|
$GLOBALS['LANG']->csConvObj = $charsetConverter; |
|
103
|
|
|
|
|
104
|
|
|
$site = Site::getFirstAvailableSite(); |
|
105
|
|
|
/** @var $indexQueueQueueWorkerTask \ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask */ |
|
106
|
|
|
$indexQueueQueueWorkerTask = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask'); |
|
107
|
|
|
$indexQueueQueueWorkerTask->setDocumentsToIndexLimit(1); |
|
108
|
|
|
$indexQueueQueueWorkerTask->setSite($site); |
|
109
|
|
|
|
|
110
|
|
|
$progressBefore = $indexQueueQueueWorkerTask->getProgress(); |
|
111
|
|
|
$indexQueueQueueWorkerTask->execute(); |
|
112
|
|
|
$progressAfter = $indexQueueQueueWorkerTask->getProgress(); |
|
113
|
|
|
|
|
114
|
|
|
// we expect that the index queue is empty before we start |
|
115
|
|
|
$this->assertTrue($this->indexQueue->containsIndexedItem('pages', 1)); |
|
116
|
|
|
$this->assertEquals(0.0, $progressBefore, 'Wrong progress before'); |
|
117
|
|
|
$this->assertEquals(100.0, $progressAfter, 'Wrong progress after'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @test |
|
122
|
|
|
*/ |
|
123
|
|
|
public function canGetAdditionalInformationFromTask() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->importDataSetFromFixture('can_trigger_frontend_calls_for_page_index.xml'); |
|
126
|
|
|
$site = Site::getFirstAvailableSite(); |
|
127
|
|
|
/** @var $indexQueueQueueWorkerTask \ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask */ |
|
128
|
|
|
$indexQueueQueueWorkerTask = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask'); |
|
129
|
|
|
$indexQueueQueueWorkerTask->setDocumentsToIndexLimit(1); |
|
130
|
|
|
$indexQueueQueueWorkerTask->setSite($site); |
|
131
|
|
|
|
|
132
|
|
|
$additionalInformation = $indexQueueQueueWorkerTask->getAdditionalInformation(); |
|
133
|
|
|
|
|
134
|
|
|
$this->assertContains('Root Page ID: 1', $additionalInformation); |
|
135
|
|
|
$this->assertContains('Site: page for testing', $additionalInformation); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|