コード例 #1
0
ファイル: ItemTest.php プロジェクト: samwilson/swidau
 /**
  * @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());
 }
コード例 #2
0
ファイル: ItemController.php プロジェクト: samwilson/swidau
 public function save(Request $request, Response $response, array $args)
 {
     $_POST = array_filter($_POST, 'trim');
     $metadata = array('id' => filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT), 'title' => filter_input(INPUT_POST, 'title'), 'description' => filter_input(INPUT_POST, 'description'), 'date' => filter_input(INPUT_POST, 'date'), 'date_granularity' => filter_input(INPUT_POST, 'date_granularity', FILTER_SANITIZE_NUMBER_INT), 'edit_group' => filter_input(INPUT_POST, 'edit_group', FILTER_SANITIZE_NUMBER_INT), 'read_group' => filter_input(INPUT_POST, 'read_group', FILTER_SANITIZE_NUMBER_INT));
     $tags = filter_input(INPUT_POST, 'tags');
     $item = new Item(null, $this->user);
     $item->save($metadata, $tags, $_FILES['file']['tmp_name'], filter_input(INPUT_POST, 'file_contents'));
     $config = new Config();
     return new RedirectResponse($config->baseUrl() . '/' . $item->getId());
 }