Exemplo n.º 1
0
 public function testDeleteHooks()
 {
     $test = $this;
     $hooksRun = 0;
     /**
      * @param \OC\Files\Node\File $node
      */
     $preListener = function ($node) use(&$test, &$hooksRun) {
         $test->assertInstanceOf('\\OC\\Files\\Node\\Folder', $node);
         $test->assertEquals('foo', $node->getInternalPath());
         $test->assertEquals('/bar/foo', $node->getPath());
         $hooksRun++;
     };
     /**
      * @param \OC\Files\Node\File $node
      */
     $postListener = function ($node) use(&$test, &$hooksRun) {
         $test->assertInstanceOf('\\OC\\Files\\Node\\NonExistingFolder', $node);
         $test->assertEquals('foo', $node->getInternalPath());
         $test->assertEquals('/bar/foo', $node->getPath());
         $test->assertEquals(1, $node->getId());
         $hooksRun++;
     };
     /**
      * @var \OC\Files\Mount\Manager $manager
      */
     $manager = $this->getMock('\\OC\\Files\\Mount\\Manager');
     /**
      * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
      */
     $view = $this->getMock('\\OC\\Files\\View');
     $root = new \OC\Files\Node\Root($manager, $view, $this->user);
     $root->listen('\\OC\\Files', 'preDelete', $preListener);
     $root->listen('\\OC\\Files', 'postDelete', $postListener);
     $view->expects($this->any())->method('getFileInfo')->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
     $view->expects($this->once())->method('rmdir')->with('/bar/foo')->will($this->returnValue(true));
     $view->expects($this->any())->method('resolvePath')->with('/bar/foo')->will($this->returnValue(array(null, 'foo')));
     $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
     $node->delete();
     $this->assertEquals(2, $hooksRun);
 }
Exemplo n.º 2
0
Arquivo: file.php Projeto: evanjt/core
 public function testFOpenWrite()
 {
     $stream = fopen('php://memory', 'w+');
     /**
      * @var \OC\Files\Mount\Manager $manager
      */
     $manager = $this->getMock('\\OC\\Files\\Mount\\Manager');
     /**
      * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
      */
     $view = $this->getMock('\\OC\\Files\\View');
     $root = new \OC\Files\Node\Root($manager, new $view(), $this->user);
     $hooksCalled = 0;
     $hook = function ($file) use(&$hooksCalled) {
         $hooksCalled++;
     };
     $root->listen('\\OC\\Files', 'preWrite', $hook);
     $root->listen('\\OC\\Files', 'postWrite', $hook);
     $view->expects($this->once())->method('fopen')->with('/bar/foo', 'w')->will($this->returnValue($stream));
     $view->expects($this->once())->method('getFileInfo')->with('/bar/foo')->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
     $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
     $fh = $node->fopen('w');
     $this->assertEquals($stream, $fh);
     fwrite($fh, 'bar');
     rewind($fh);
     $this->assertEquals('bar', fread($stream, 3));
     $this->assertEquals(2, $hooksCalled);
 }
Exemplo n.º 3
0
 public function testTouchHooks()
 {
     $test = $this;
     $hooksRun = 0;
     /**
      * @param \OC\Files\Node\File $node
      */
     $preListener = function ($node) use(&$test, &$hooksRun) {
         $test->assertEquals('foo', $node->getInternalPath());
         $test->assertEquals('/bar/foo', $node->getPath());
         $hooksRun++;
     };
     /**
      * @param \OC\Files\Node\File $node
      */
     $postListener = function ($node) use(&$test, &$hooksRun) {
         $test->assertEquals('foo', $node->getInternalPath());
         $test->assertEquals('/bar/foo', $node->getPath());
         $hooksRun++;
     };
     /**
      * @var \OC\Files\Mount\Manager $manager
      */
     $manager = $this->getMock('\\OC\\Files\\Mount\\Manager');
     /**
      * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
      */
     $view = $this->getMock('\\OC\\Files\\View');
     $root = new \OC\Files\Node\Root($manager, $view, $this->user);
     $root->listen('\\OC\\Files', 'preTouch', $preListener);
     $root->listen('\\OC\\Files', 'postTouch', $postListener);
     $view->expects($this->once())->method('touch')->with('/bar/foo', 100)->will($this->returnValue(true));
     $view->expects($this->any())->method('resolvePath')->with('/bar/foo')->will($this->returnValue(array(null, 'foo')));
     $view->expects($this->any())->method('getFileInfo')->with('/bar/foo')->will($this->returnValue(array('permissions' => \OCP\PERMISSION_ALL)));
     $node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
     $node->touch(100);
     $this->assertEquals(2, $hooksRun);
 }