‪TYPO3CMS  10.4
PagesXmlSitemapDataProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪PagesXmlSitemapDataProviderTest extends UnitTestCase
26 {
27  protected ‪$resetSingletonInstances = true;
28 
32  protected ‪$items;
33 
34  public function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->items = [
38  [
39  'loc' => 'https://yourdomain.com/page-1',
40  'lastMod' => 1535655601
41  ],
42  [
43  'loc' => 'https://yourdomain.com/page-2',
44  'lastMod' => 1530432000
45  ],
46  [
47  'loc' => 'https://yourdomain.com/page-3',
48  'lastMod' => 1535655756
49  ],
50  [
51  'loc' => 'https://yourdomain.com/page-4',
52  'lastMod' => 1530432001
53  ],
54  ];
55  }
56 
60  public function ‪checkIfCorrectKeyIsGivenAfterConstruct(): void
61  {
62  $key = 'dummyKey';
63  $cObj = $this->prophesize(ContentObjectRenderer::class);
64 
65  $subject = $this->getAccessibleMock(
66  PagesXmlSitemapDataProvider::class,
67  ['generateItems'],
68  [$this->prophesize(ServerRequestInterface::class)->reveal(), $key, [], $cObj->reveal()],
69  '',
70  true
71  );
72  self::assertEquals($key, $subject->getKey());
73  }
74 
79  public function ‪checkGetItemsReturnsDefinedItems($numberOfItemsPerPage): void
80  {
81  $key = 'dummyKey';
82  $cObj = $this->prophesize(ContentObjectRenderer::class);
83 
84  $subject = $this->getAccessibleMock(
85  PagesXmlSitemapDataProvider::class,
86  ['generateItems', 'defineUrl'],
87  [$this->prophesize(ServerRequestInterface::class)->reveal(), $key, [], $cObj->reveal()],
88  '',
89  false
90  );
91  $subject->_set('request', $this->prophesize(ServerRequestInterface::class)->reveal());
92  $subject->_set('items', $this->items);
93  $subject->_set('numberOfItemsPerPage', $numberOfItemsPerPage);
94 
95  $subject->expects(self::any())->method('defineUrl')->willReturnCallback(
96  function ($input) {
97  return $input;
98  }
99  );
100 
101  $returnedItems = $subject->getItems();
102  $expectedReturnedItems = array_slice($this->items, 0, $numberOfItemsPerPage);
103 
104  self::assertLessThanOrEqual($numberOfItemsPerPage, count($returnedItems));
105 
106  self::assertEquals($expectedReturnedItems, $returnedItems);
107  }
108 
112  public function ‪checkGetLastModReturnsRightDate(): void
113  {
114  $key = 'dummyKey';
115  $cObj = $this->prophesize(ContentObjectRenderer::class);
116 
117  $subject = $this->getAccessibleMock(
118  PagesXmlSitemapDataProvider::class,
119  ['generateItems'],
120  [$this->prophesize(ServerRequestInterface::class)->reveal(), $key, [], $cObj->reveal()],
121  '',
122  false
123  );
124 
125  $subject->_set('items', $this->items);
126 
127  self::assertEquals(1535655756, $subject->getLastModified());
128  }
129 
133  public function ‪numberOfItemsPerPageProvider(): array
134  {
135  return [
136  '1 items per page' => [1],
137  '3 items per page' => [3],
138  '100 items per page' => [100],
139  ];
140  }
141 }
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\checkGetItemsReturnsDefinedItems
‪checkGetItemsReturnsDefinedItems($numberOfItemsPerPage)
Definition: PagesXmlSitemapDataProviderTest.php:78
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider
Definition: PagesXmlSitemapDataProvider.php:34
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\checkGetLastModReturnsRightDate
‪checkGetLastModReturnsRightDate()
Definition: PagesXmlSitemapDataProviderTest.php:111
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: PagesXmlSitemapDataProviderTest.php:27
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest
Definition: PagesXmlSitemapDataProviderTest.php:26
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\$items
‪array $items
Definition: PagesXmlSitemapDataProviderTest.php:31
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\numberOfItemsPerPageProvider
‪array numberOfItemsPerPageProvider()
Definition: PagesXmlSitemapDataProviderTest.php:132
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\checkIfCorrectKeyIsGivenAfterConstruct
‪checkIfCorrectKeyIsGivenAfterConstruct()
Definition: PagesXmlSitemapDataProviderTest.php:59
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap
Definition: PagesXmlSitemapDataProviderTest.php:18
‪TYPO3\CMS\Seo\Tests\Unit\XmlSitemap\PagesXmlSitemapDataProviderTest\setUp
‪setUp()
Definition: PagesXmlSitemapDataProviderTest.php:33