Completed
Push — master ( b1b8c7...b37043 )
by Timo
06:43
created

PageTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 107
rs 10
c 1
b 1
f 0
wmc 6
lcom 1
cbo 5
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Tests\Integration\IndexQueue\Initializer;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Timo Schmidt <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
28
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Page;
29
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
30
use ApacheSolrForTypo3\Solr\Site;
31
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest;
32
use ApacheSolrForTypo3\Solr\IndexQueue\RecordMonitor;
33
use TYPO3\CMS\Backend\Utility\BackendUtility;
34
use TYPO3\CMS\Core\Charset\CharsetConverter;
35
use TYPO3\CMS\Core\DataHandling\DataHandler;
36
use TYPO3\CMS\Core\Utility\GeneralUtility;
37
38
/**
39
 * Testcase to test the page queue initializer
40
 *
41
 * @author Timo Schmidt
42
 * @package TYPO3
43
 * @subpackage solr
44
 */
45
class PageTest extends IntegrationTest
46
{
47
    /**
48
     * @var Page
49
     */
50
    protected $pageInitializer;
51
52
    /**
53
     * @var Queue
54
     */
55
    protected $indexQueue;
56
57
    /**
58
     * @return void
59
     */
60
    public function setUp()
61
    {
62
        parent::setUp();
63
        $this->setUpBackendUserFromFixture(1);
64
        $this->pageInitializer = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Page');
65
        $this->indexQueue = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\IndexQueue\Queue');
66
    }
67
68
    /**
69
     * Custom assertion to expect a specific amount of items in the queue.
70
     *
71
     * @param integer $expectedAmount
72
     */
73
    protected function assertItemsInQueue($expectedAmount)
74
    {
75
        $itemCount = $this->indexQueue->getAllItemsCount();
76
        $this->assertSame($itemCount, $expectedAmount, 'Indexqueue contains unexpected amount of items. Expected amount: '.$expectedAmount);
77
    }
78
79
    /**
80
     * Custom assertion to expect an empty queue.
81
     * @return void
82
     */
83
    protected function assertEmptyQueue()
84
    {
85
        $this->assertItemsInQueue(0);
86
    }
87
88
    /**
89
     * Initialize page index queue
90
     *
91
     * @return void
92
     */
93
    protected function initializePageIndexQueue()
94
    {
95
        $this->pageInitializer->setIndexingConfigurationName('pages');
96
        $this->pageInitializer->setSite(Site::getFirstAvailableSite());
97
        $this->pageInitializer->setType('pages');
98
        $this->pageInitializer->initialize();
99
    }
100
101
    /**
102
     * In this testcase we check if the pages queue will be initialized as expected
103
     * when we have a page with mounted pages
104
     *
105
     *
106
     *      1
107
     *      |
108
     *      ------- 10 (Mounted)
109
     *                        |
110
     *                         ------------ 20 (Childpage of mountpoint)
111
     *
112
     * @test
113
     */
114
    public function initializerIsFillingQueueWithMountPages()
115
    {
116
        $this->importDataSetFromFixture('can_add_mount_pages.xml');
117
118
        $this->assertEmptyQueue();
119
        $this->initializePageIndexQueue();
120
121
        $this->assertItemsInQueue(4);
122
123
            // @todo: verify, is this really as expected? since mount_pid_ol is not set
124
            // in the case when mount_pid_ol is set 4 pages get added
125
        $this->assertTrue($this->indexQueue->containsItem('pages', 1));
126
        $this->assertTrue($this->indexQueue->containsItem('pages', 10));
127
        $this->assertTrue($this->indexQueue->containsItem('pages', 20));
128
129
        $this->assertFalse($this->indexQueue->containsItem('pages', 2));
130
    }
131
132
    /**
133
     * Check if invalid mount page is ignored and messages were added to the flash
134
     * message queue
135
     *
136
     * @test
137
     */
138
    public function initializerAddsInfoMessagesAboutInvalidMountPages()
139
    {
140
        $this->importDataSetFromFixture('can_add_mount_pages.xml');
141
142
        $this->assertEmptyQueue();
143
        $this->initializePageIndexQueue();
144
145
        $this->assertItemsInQueue(4);
146
147
        $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
148
        $flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier('solr.queue.initializer');
149
        $this->assertEquals(2, count($flashMessageQueue->getAllMessages()));
150
    }
151
}
152