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