/** * @testdox An item can have a single file attached. * @test */ public function files() { $item = new Item(null, $this->testUser); // First version. $item->save([], null, null, 'Test file contents.'); $this->assertSame(1, $item->getId()); $this->assertSame('c4/ca/1/v1', $item->getFilePath()); $this->assertFileExists(__DIR__ . '/data/storage/c4/ca/1/v1'); $this->assertSame('Test file contents.', $item->getFileContents()); $this->assertSame(1, $item->getVersionCount()); // Second version. $item->save(['id' => 1], null, null, 'New file contents.'); $this->assertSame(1, $item->getId()); $this->assertSame(2, $item->getVersionCount()); $this->assertSame('c4/ca/1/v2', $item->getFilePath()); $this->assertFileExists(__DIR__ . '/data/storage/c4/ca/1/v1'); $this->assertFileExists(__DIR__ . '/data/storage/c4/ca/1/v2'); $this->assertSame('New file contents.', $item->getFileContents()); $this->assertSame('Test file contents.', $item->getFileContents(1)); // Upload a different file. $item2 = new Item(null, $this->testUser); $item2->save(['title' => 'Second test'], null, null, 'Second test.'); $this->assertSame(2, $item2->getId()); $this->assertSame('c8/1e/2/v1', $item2->getFilePath()); $this->assertTrue($item2->isText()); }