1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8/**
9 * @group unit
10 *
11 */
12
13use Tiki\FileGallery\File;
14use Tiki\FileGallery\Manipulator\Validator;
15
16class Tiki_FileGallery_Manipulator_ValidatorTest extends TikiTestCase
17{
18  function setUp() {
19    global $prefs;
20    $this->oldPrefs = $prefs;
21    parent::setUp();
22  }
23
24  function tearDown() {
25    global $prefs;
26    $prefs = $this->oldPrefs;
27  }
28
29  function testFilenameValidByDefault()
30  {
31    $file = new File(['filename' => 'test.zip']);
32    $this->assertTrue((new Validator($file))->run());
33  }
34
35  function testFilenameInvalidByRegexp()
36  {
37    global $prefs;
38
39    $prefs['fgal_match_regex'] = ".*\.png$";
40
41    $file = new File(['filename' => 'test.zip']);
42    $this->assertFalse((new Validator($file))->run());
43  }
44
45  function testFilenameValidByRegexp()
46  {
47    global $prefs;
48
49    $prefs['fgal_match_regex'] = ".*\.zip$";
50
51    $file = new File(['filename' => 'test.zip']);
52    $this->assertTrue((new Validator($file))->run());
53  }
54
55  function testDuplicateChecksum()
56  {
57    global $prefs;
58
59    $prefs['fgal_allow_duplicates'] = 'n';
60    $filesTable = TikiLib::lib('filegal')->table('tiki_files');
61    $filesTable->insert(['hash' => '123456789']);
62
63    $file = new File(['filename' => 'test.zip', 'hash' => '123456789']);
64    $this->assertFalse((new Validator($file))->run());
65  }
66}
67