Skip to content

Commit 4b15923

Browse files
committed
Add unit test for RewriteMap
1 parent e3a2b49 commit 4b15923

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

tests/unit/ExampleTest.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/unit/RewriteMapTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace IntegerNet\RewriteMap;
4+
5+
use IntegerNet\RewriteMap\Model\RewriteMap;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class RewriteMapTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
* @dataProvider data_rewrite_map_arguments
13+
* @param $storeId
14+
* @param $redirectType
15+
*/
16+
public function filename_contains_store_id_and_redirect_type(int $storeId, int $redirectType): void
17+
{
18+
$rewriteMap = new RewriteMap($storeId, $redirectType);
19+
$this->assertEquals(
20+
"rewrite-map-$redirectType-store-$storeId.txt",
21+
$rewriteMap->getFilename(),
22+
'file name should contain store id and redirect type'
23+
);
24+
}
25+
26+
/**
27+
* @test
28+
*/
29+
public function content_after_adding_redirects(): void
30+
{
31+
$rewriteMap = new RewriteMap(1, 301);
32+
$rewriteMap->addRewrite('shiny-new-url', 'old-boring-cms-page.html');
33+
$rewriteMap->addRewrite('another-shiny-url', 'category/product.html');
34+
$this->assertEquals(
35+
<<<'TXT'
36+
/shiny-new-url /old-boring-cms-page.html
37+
/another-shiny-url /category/product.html
38+
39+
TXT,
40+
$rewriteMap->getContent(),
41+
'content should have one line per rewrite, paths starting with /'
42+
);
43+
}
44+
45+
public static function data_rewrite_map_arguments(): array
46+
{
47+
return [
48+
[
49+
'store_id' => 1,
50+
'redirect_type' => 301,
51+
],
52+
[
53+
'store_id' => 1,
54+
'redirect_type' => 302,
55+
],
56+
[
57+
'store_id' => 2,
58+
'redirect_type' => 301,
59+
],
60+
[
61+
'store_id' => 0,
62+
'redirect_type' => 302,
63+
],
64+
];
65+
}
66+
}

0 commit comments

Comments
 (0)