Skip to content

Commit

Permalink
Merge pull request #704 from teiling88/misc/tests-tests-tests
Browse files Browse the repository at this point in the history
Misc/tests tests tests
  • Loading branch information
teiling88 committed Nov 24, 2017
2 parents 4264c98 + 22f1f63 commit f93eb80
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 181 deletions.
171 changes: 0 additions & 171 deletions htdocs/src/Oc/Util/StyleCleanUp.php

This file was deleted.

17 changes: 7 additions & 10 deletions htdocs/src/OcLegacy/Util/SiteMapXml.php
Expand Up @@ -35,9 +35,6 @@ public function open($sPath, $sDomain)
$this->sDomain = $sDomain;

$this->oIndexFile = fopen($sPath . 'sitemap.xml', 'wb');
if ($this->oIndexFile === false) {
return false;
}

fwrite($this->oIndexFile, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
fwrite($this->oIndexFile, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
Expand All @@ -53,17 +50,17 @@ public function open($sPath, $sDomain)
* @param string $sChangeFreq
* @param float $nPriority
*/
public function write($sFile, $dLastMod, $sChangeFreq, $nPriority = 0.5)
public function write($sFile, $dLastMod, $sChangeFreq = null, $nPriority = 0.5)
{
if (!$sChangeFreq) {
$sChangeFreq = $this->sDefaultChangeFreq;
}

$sXML = '<url>';
$sXML .= '<loc>' . xmlentities($this->sDomain . $sFile) . '</loc>';
$sXML .= '<lastmod>' . xmlentities(date('c', $dLastMod)) . '</lastmod>';
$sXML .= '<changefreq>' . xmlentities($sChangeFreq) . '</changefreq>';
$sXML .= '<priority>' . xmlentities($nPriority) . '</priority>';
$sXML .= '<loc>' . \xmlentities($this->sDomain . $sFile) . '</loc>';
$sXML .= '<lastmod>' . \xmlentities(date('c', $dLastMod)) . '</lastmod>';
$sXML .= '<changefreq>' . \xmlentities($sChangeFreq) . '</changefreq>';
$sXML .= '<priority>' . \xmlentities($nPriority) . '</priority>';
$sXML .= '</url>' . "\n";

$this->writeInternal($sXML);
Expand All @@ -89,8 +86,8 @@ public function writeInternal($str)

fwrite(
$this->oIndexFile,
'<sitemap><loc>' . xmlentities($this->sDomain . $sFilename) . '</loc>' .
'<lastmod>' . xmlentities(date('c')) . '</lastmod></sitemap>'
'<sitemap><loc>' . \xmlentities($this->sDomain . $sFilename) . '</loc>' .
'<lastmod>' . \xmlentities(date('c')) . '</lastmod></sitemap>'
);

gzwrite($this->oSiteMapFile, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
Expand Down
56 changes: 56 additions & 0 deletions tests/Modules/OcLegacy/Util/SiteMapXmlTest.php
@@ -0,0 +1,56 @@
<?php

namespace OcTest\Modules\OcLegacy\Util;

use OcLegacy\Util\SiteMapXml;
use OcTest\Modules\AbstractModuleTest;

require_once __DIR__ . '/../../../../htdocs/lib2/util.inc.php';

class SiteMapXmlTest extends AbstractModuleTest
{
private $siteMapFile = __DIR__ . '/../../../../htdocs/var/cache2/sitemap.xml';

private $siteMapFileGz = __DIR__ . '/../../../../htdocs/var/cache2/sitemap-1.xml.gz';

private $domain = 'local.team-opencaching.de';

public function setUp()
{
$this->deleteSiteMap();
}

public function tearDown()
{
$this->deleteSiteMap();
}

private function deleteSiteMap()
{
if (file_exists($this->siteMapFile)) {
unlink($this->siteMapFile);
}
if (file_exists($this->siteMapFileGz)) {
unlink($this->siteMapFileGz);
}
}

public function test_open_creates_sitemapxml_file()
{
$siteMap = new SiteMapXml();
$siteMap->nMaxUrlCount = 8;
$siteMap->open(__DIR__ . '/../../../../htdocs/var/cache2', $this->domain);

for ($i = 1; $i <= 10; $i++) {
$siteMap->write('unittests.php', time());
}

$siteMap->close();

self::assertFileExists($this->siteMapFile);
$siteMapContent = file_get_contents($this->siteMapFile);

self::assertFileExists($this->siteMapFileGz);
self::assertContains(basename($this->siteMapFileGz), $siteMapContent);
}
}

0 comments on commit f93eb80

Please sign in to comment.