| 1 | <?php |
| 2 | /************************************************************* |
| 3 | # 076 License |
| 4 | |
| 5 | Copyright (c) テクニカル諏訪子 |
| 6 | |
| 7 | Permission is hereby granted to any person obtaining a copy of the software |
| 8 | Little Beast (the "Software") to use, modify, merge, copy, publish, distribute, |
| 9 | sublicense, and/or sell copies of the Software, subject to the following conditions: |
| 10 | |
| 11 | 1. **Origin Attribution**: |
| 12 | - You must not misrepresent the origin of the Software; you must not claim |
| 13 | you created the original Software. |
| 14 | - If the Software is used in a product, you must either: |
| 15 | a. Provide clear attribution in the product's documentation, user interface, |
| 16 | or other visible areas, **OR** |
| 17 | b. Pay the original developers a fee they specify in writing. |
| 18 | 2. **Usage Restriction**: |
| 19 | - The Software, or any derivative works, dependencies, or libraries |
| 20 | incorporating it, must not be used for censorship or to suppress freedom of |
| 21 | speech, expression, or creativity. Prohibited uses include, but are not |
| 22 | limited to: |
| 23 | - Censorship of so-called "hate speech", visuals, non-mainstream opinions, |
| 24 | ideas, or objective reality. |
| 25 | - Tools or systems designed to restrict access to information or |
| 26 | artistic works. |
| 27 | 3. **Notice Preservation**: |
| 28 | - This license and the above copyright notice must remain intact in all copies |
| 29 | of the source code. |
| 30 | |
| 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 32 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 33 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 34 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 35 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 36 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 37 | */ |
| 38 | namespace Std\Test; |
| 39 | |
| 40 | require_once __DIR__.'/../../../autoload.php'; |
| 41 | |
| 42 | use Std\Lib\Tester; |
| 43 | |
| 44 | $test = new Tester([ |
| 45 | 'colorOutput' => true, |
| 46 | 'verboseOutput' => true |
| 47 | ]); |
| 48 | |
| 49 | $test->describe('静的ファイルの場所(ASS_DOMAIN)', function($test): void { |
| 50 | $test->it('パスならこのサイトのURLとpublic/の下のディレクトリのはず', function($test): void { |
| 51 | $test->assertEquals('/static/article/a.png', ass_url('article/a.png', '', '/static')); |
| 52 | $test->assertEquals('/static/article/a.png', ass_url('/article/a.png', '', '/static/')); |
| 53 | $test->assertEquals('/static', ass_url('', '', '/static')); |
| 54 | $test->assertEquals('https://076.moe/static/logo.png', ass_url('logo.png', 'https://076.moe/', '/static')); |
| 55 | $test->assertEquals('/assets/style.css', ass_url('style.css', '', '/assets')); |
| 56 | $test->assertEquals('/public/static/article/a.png', ass_path('article/a.png', '/static')); |
| 57 | $test->assertEquals('/public/assets', ass_path('', '/assets/')); |
| 58 | }); |
| 59 | |
| 60 | $test->it('URLならそのサーバーで、ファイルはpublic/の下の同じパスのはず', function($test): void { |
| 61 | $ass = 'https://ass.technicalsuwako.moe/static'; |
| 62 | $test->assertEquals('https://ass.technicalsuwako.moe/static/article/a.png', ass_url('article/a.png', '', $ass)); |
| 63 | $test->assertEquals('https://ass.technicalsuwako.moe/static/logo.png', ass_url('logo.png', 'https://technicalsuwako.moe', $ass), 'サイトのURLは付けない'); |
| 64 | $test->assertEquals('https://ass.technicalsuwako.moe/static', ass_url('', '', $ass.'/')); |
| 65 | $test->assertEquals('/public/static/user/noicon.png', ass_path('user/noicon.png', $ass)); |
| 66 | $test->assertEquals('/public/user/noicon.png', ass_path('user/noicon.png', 'https://ass.example.com'), 'パスが無いURL'); |
| 67 | }); |
| 68 | |
| 69 | $test->it('設定が無ければ「/static」のはず', function($test): void { |
| 70 | if (defined('ASS_DOMAIN')) { |
| 71 | $test->assertEquals(rtrim(ASS_DOMAIN, '/').'/a.png', ass_url('a.png')); |
| 72 | return; |
| 73 | } |
| 74 | $test->assertEquals('/static/a.png', ass_url('a.png')); |
| 75 | $test->assertEquals('/public/static/a.png', ass_path('a.png')); |
| 76 | }); |
| 77 | }); |
| 78 | |
| 79 | $test->printSummary(); |