66use Cake \ORM \TableRegistry ;
77use Cake \TestSuite \TestCase ;
88
9+ class TestBasePathBuilder extends BasePathBuilder {
10+
11+ /**
12+ *
13+ */
14+ public function randomPathTestMethod ($ string ) {
15+ return $ string . 'test ' ;
16+ }
17+ }
18+
919class BasePathBuilderTest extends TestCase {
1020
11- /**
12- * Fixtures
13- *
14- * @var array
15- */
21+ /**
22+ * Fixtures
23+ *
24+ * @var array
25+ */
1626 public $ fixtures = array (
1727 'plugin.Burzum\FileStorage.FileStorage '
1828 );
@@ -36,11 +46,11 @@ public function setUp() {
3646 $ this ->entity ->accessible ('id ' , true );
3747 }
3848
39- /**
40- * testPathbuilding
41- *
42- * @return void
43- */
49+ /**
50+ * testPathbuilding
51+ *
52+ * @return void
53+ */
4454 public function testPathbuilding () {
4555 $ builder = new BasePathBuilder ();
4656 $ config = $ builder ->config ();
@@ -73,30 +83,60 @@ public function testPathbuilding() {
7383 $ result = $ builder ->path ($ this ->entity );
7484 $ this ->assertEquals ($ result , '14 ' . DS . '83 ' . DS . '23 ' . DS . 'filestorage1 ' . DS . 'files ' . DS );
7585
86+ $ builder ->config ($ config );
87+ $ builder ->config ('pathPrefix ' , 'files ' );
88+ $ result = $ builder ->path ($ this ->entity );
89+ $ this ->assertEquals ($ result , 'files ' . DS . '14 ' . DS . '83 ' . DS . '23 ' . DS . 'filestorage1 ' . DS );
90+
91+ $ builder ->config ($ config );
7692 $ result = $ builder ->url ($ this ->entity );
77- $ expected = '14/83/23/filestorage1/files/ filestorage1.png ' ;
93+ $ expected = '14/83/23/filestorage1/filestorage1.png ' ;
7894 $ this ->assertEquals ($ result , $ expected );
7995 }
8096
81- /**
82- * testRandomPath
83- *
84- * @return void
85- */
97+ /**
98+ * testRandomPath
99+ *
100+ * @return void
101+ */
86102 public function testRandomPath () {
87- $ builder = new BasePathBuilder ();
103+ $ builder = new TestBasePathBuilder ();
88104 $ result = $ builder ->randomPath ('test ' , 5 , 'sha1 ' );
89105 $ this ->assertEquals ($ result , '4a ' . DS . '8f ' . DS . 'e5 ' . DS . 'cc ' . DS . 'b1 ' . DS );
90106
91107 $ result = $ builder ->randomPath ('test ' , 3 , 'sha1 ' );
92108 $ this ->assertEquals ($ result , '4a ' . DS . '8f ' . DS . 'e5 ' . DS );
109+
110+ if (PHP_INT_SIZE === 4 ) {
111+ $ result = $ builder ->randomPath ('test ' , 3 , 'crc32 ' );
112+ $ this ->assertEquals ($ result , '00 ' . DS . '33 ' . DS . '73 ' . DS );
113+ }
114+
115+ if (PHP_INT_SIZE === 8 ) {
116+ $ result = $ builder ->randomPath ('test ' , 3 , 'crc32 ' );
117+ $ this ->assertEquals ($ result , '96 ' . DS . '39 ' . DS . '23 ' . DS );
118+ }
119+
120+ $ result = $ builder ->randomPath ('test ' , 3 , 'randomPathTestMethod ' );
121+ $ this ->assertEquals ($ result , 'testtest ' );
122+ }
123+
124+ /**
125+ * testRandomPathInvalidArgumentException
126+ *
127+ * @expectedException \InvalidArgumentException
128+ * @return void
129+ */
130+ public function testRandomPathInvalidArgumentException () {
131+ $ builder = new BasePathBuilder ();
132+ $ result = $ builder ->randomPath ('test ' , 5 , 'does-not-exist ' );
93133 }
94134
95- /**
96- * testEnsureSlash
97- *
98- * @return void
99- */
135+ /**
136+ * testEnsureSlash
137+ *
138+ * @return void
139+ */
100140 public function testEnsureSlash () {
101141 $ string = 'foo/bar ' ;
102142 $ builder = new BasePathBuilder ();
@@ -107,22 +147,22 @@ public function testEnsureSlash() {
107147 $ this ->assertEquals ($ result , DS . $ string . DS );
108148 }
109149
110- /**
111- * testEnsureSlashInvalidArgumentException
112- *
113- * @expectedException \InvalidArgumentException
114- */
150+ /**
151+ * testEnsureSlashInvalidArgumentException
152+ *
153+ * @expectedException \InvalidArgumentException
154+ */
115155 public function testEnsureSlashInvalidArgumentException () {
116156 $ string = 'foo/bar ' ;
117157 $ builder = new BasePathBuilder ();
118158 $ builder ->ensureSlash ($ string , 'INVALID! ' );
119159 }
120160
121- /**
122- * testSplitFilename
123- *
124- * @return void
125- */
161+ /**
162+ * testSplitFilename
163+ *
164+ * @return void
165+ */
126166 public function testSplitFilename () {
127167 $ builder = new BasePathBuilder ();
128168 $ result = $ builder ->splitFilename ('some.fancy.name.jpg ' );
@@ -140,11 +180,11 @@ public function testSplitFilename() {
140180 $ this ->assertEquals ($ result , $ expected );
141181 }
142182
143- /**
144- * testStripDashes
145- *
146- * @return void
147- */
183+ /**
184+ * testStripDashes
185+ *
186+ * @return void
187+ */
148188 public function testStripDashes () {
149189 $ builder = new BasePathBuilder ();
150190 $ result = $ builder ->stripDashes ('with-dashes-! ' );
0 commit comments