PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Webdav/tests/backend_file_test.php

https://github.com/Yannix/zetacomponents
PHP | 2619 lines | 2082 code | 430 blank | 107 comment | 18 complexity | e2ce78c45c1476fe3f449fe2a076ab6b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Basic test cases for the file backend.
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Webdav
  23. * @subpackage Tests
  24. * @version //autogentag//
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. /**
  28. * Reqiuire base test
  29. */
  30. /**
  31. * Tests for ezcWebdavFileBackend class.
  32. *
  33. * @package Webdav
  34. * @subpackage Tests
  35. */
  36. class ezcWebdavFileBackendTest extends ezcTestCase
  37. {
  38. const KEEP_TEMP_DIR = false;
  39. protected $tempDir;
  40. protected $oldTimezone;
  41. public static function suite()
  42. {
  43. return new PHPUnit_Framework_TestSuite( 'ezcWebdavFileBackendTest' );
  44. }
  45. protected function recursiveTouch( $source, $time )
  46. {
  47. $dh = opendir( $source );
  48. while( $file = readdir( $dh ) )
  49. {
  50. if ( ( $file === '.' ) ||
  51. ( $file === '..' ) )
  52. {
  53. continue;
  54. }
  55. if ( is_dir( $path = $source . '/' . $file ) )
  56. {
  57. touch( $path, $time, $time );
  58. $this->recursiveTouch( $path, $time );
  59. }
  60. else
  61. {
  62. touch( $path, $time, $time );
  63. }
  64. }
  65. }
  66. /**
  67. * Recursively copy a file or directory.
  68. *
  69. * Recursively copy a file or directory in $source to the given
  70. * destination. If a depth is given, the operation will stop, if the given
  71. * recursion depth is reached. A depth of -1 means no limit, while a depth
  72. * of 0 means, that only the current file or directory will be copied,
  73. * without any recursion.
  74. *
  75. * You may optionally define modes used to create files and directories.
  76. *
  77. * @throws ezcBaseFileNotFoundException
  78. * If the $sourceDir directory is not a directory or does not exist.
  79. * @throws ezcBaseFilePermissionException
  80. * If the $sourceDir directory could not be opened for reading, or the
  81. * destination is not writeable.
  82. *
  83. * @param string $source
  84. * @param string $destination
  85. * @param int $depth
  86. * @param int $dirMode
  87. * @param int $fileMode
  88. * @return void
  89. */
  90. static protected function copyRecursive( $source, $destination, $depth = -1, $dirMode = 0775, $fileMode = 0664 )
  91. {
  92. // Check if source file exists at all.
  93. if ( !is_file( $source ) && !is_dir( $source ) )
  94. {
  95. throw new ezcBaseFileNotFoundException( $source );
  96. }
  97. // Destination file should NOT exist
  98. if ( is_file( $destination ) || is_dir( $destination ) )
  99. {
  100. throw new ezcBaseFilePermissionException( $destination, ezcBaseFileException::WRITE );
  101. }
  102. // Skip non readable files in source directory
  103. if ( !is_readable( $source ) )
  104. {
  105. return;
  106. }
  107. // Copy
  108. if ( is_dir( $source ) )
  109. {
  110. mkdir( $destination );
  111. // To ignore umask, umask() should not be changed with
  112. // multithreaded servers...
  113. chmod( $destination, $dirMode );
  114. }
  115. elseif ( is_file( $source ) )
  116. {
  117. copy( $source, $destination );
  118. chmod( $destination, $fileMode );
  119. }
  120. if ( ( $depth === 0 ) ||
  121. ( !is_dir( $source ) ) )
  122. {
  123. // Do not recurse (any more)
  124. return;
  125. }
  126. // Recurse
  127. //
  128. // Read directory using glob(), to get a pre-sorted result.
  129. $files = glob( $source . '/*' );
  130. foreach ( $files as $fullName )
  131. {
  132. $file = basename( $fullName );
  133. if ( empty( $file ) )
  134. {
  135. continue;
  136. }
  137. self::copyRecursive(
  138. $source . '/' . $file,
  139. $destination . '/' . $file,
  140. $depth - 1, $dirMode, $fileMode
  141. );
  142. }
  143. }
  144. protected function compareResponse( $test, ezcWebdavResponse $response )
  145. {
  146. $dataDir = dirname( __FILE__ ) . '/data/responses/file';
  147. if ( !is_file( $file = $dataDir . '/' . $test . '.ser' ) )
  148. {
  149. file_put_contents( $file, serialize( $response ) );
  150. return $this->markTestSkipped( 'Reponse serialized. Please check generated response.' );
  151. }
  152. $this->assertEquals(
  153. $response,
  154. unserialize( file_get_contents( $file ) ),
  155. 'Response does not equal serialzed response.',
  156. 20
  157. );
  158. }
  159. public function setUp()
  160. {
  161. parent::setUp();
  162. static $i = 0;
  163. $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d', ++$i ) ) . '/';
  164. self::copyRecursive(
  165. dirname( __FILE__ ) . '/data/backend_file',
  166. $this->tempDir . 'backend/'
  167. );
  168. // Remove SVN directories from temporary backend
  169. $svnDirs = ezcFile::findRecursive(
  170. $this->tempDir . 'backend/',
  171. array( '(/\.svn/entries$)' )
  172. );
  173. foreach ( $svnDirs as $dir )
  174. {
  175. ezcFile::removeRecursive( dirname( $dir ) );
  176. }
  177. // Explicitely set mtime and ctime
  178. $this->recursiveTouch(
  179. $this->tempDir . 'backend/',
  180. // Change this once 64bit systems are common, or we reached year 2038
  181. 2147483647
  182. );
  183. // Store current timezone and switch to UTC for test
  184. $this->oldTimezone = date_default_timezone_get();
  185. date_default_timezone_set( 'UTC' );
  186. }
  187. public function tearDown()
  188. {
  189. // Reset old timezone
  190. date_default_timezone_set( $this->oldTimezone );
  191. if ( !$this->hasFailed() || self::KEEP_TEMP_DIR === false )
  192. {
  193. $this->removeTempDir();
  194. }
  195. parent::tearDown();
  196. }
  197. public function testFileBackendOptionsInFileBackend()
  198. {
  199. $server = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  200. $this->assertEquals(
  201. $server->options,
  202. new ezcWebdavFileBackendOptions(),
  203. 'Expected initially unmodified backend options class.'
  204. );
  205. $this->assertSame(
  206. $server->options->noLock,
  207. false,
  208. 'Expected successfull access on option.'
  209. );
  210. try
  211. {
  212. // Read access
  213. $server->unknownProperty;
  214. }
  215. catch ( ezcBasePropertyNotFoundException $e )
  216. {
  217. return true;
  218. }
  219. $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
  220. }
  221. public function testFileBackendOptionsSetInFileBackend()
  222. {
  223. $server = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  224. $options = new ezcWebdavFileBackendOptions();
  225. $options->noLock = true;
  226. $this->assertSame(
  227. $server->options->noLock,
  228. false,
  229. 'Wrong initial value before changed option class.'
  230. );
  231. $server->options = $options;
  232. $this->assertSame(
  233. $server->options->noLock,
  234. true,
  235. 'Expected modified value, because of changed option class.'
  236. );
  237. try
  238. {
  239. $server->unknownProperty = $options;
  240. }
  241. catch ( ezcBasePropertyNotFoundException $e )
  242. {
  243. return true;
  244. }
  245. $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
  246. }
  247. public function testResourceHead()
  248. {
  249. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  250. $request = new ezcWebdavHeadRequest( '/resource' );
  251. $request->validateHeaders();
  252. $response = $backend->head( $request );
  253. $expectedResponse = new ezcWebdavHeadResponse(
  254. new ezcWebdavResource(
  255. '/resource',
  256. $backend->getAllProperties( '/resource' )
  257. )
  258. );
  259. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
  260. $this->assertEquals(
  261. $expectedResponse,
  262. $response,
  263. 'Expected response does not match real response.',
  264. 0,
  265. 20
  266. );
  267. }
  268. public function testCollectionHead()
  269. {
  270. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  271. $request = new ezcWebdavHeadRequest( '/collection' );
  272. $request->validateHeaders();
  273. $response = $backend->head( $request );
  274. $expectedResponse = new ezcWebdavHeadResponse(
  275. new ezcWebdavCollection(
  276. '/collection',
  277. $backend->getAllProperties( '/collection' )
  278. )
  279. );
  280. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection', 'getetag' )->etag );
  281. $this->assertEquals(
  282. $expectedResponse,
  283. $response,
  284. 'Expected response does not match real response.',
  285. 0,
  286. 20
  287. );
  288. }
  289. public function testResourceHeadError()
  290. {
  291. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  292. $request = new ezcWebdavHeadRequest( '/unknown' );
  293. $request->validateHeaders();
  294. $response = $backend->head( $request );
  295. $this->assertEquals(
  296. $response,
  297. new ezcWebdavErrorResponse(
  298. ezcWebdavResponse::STATUS_404,
  299. '/unknown'
  300. ),
  301. 'Expected response does not match real response.',
  302. 0,
  303. 20
  304. );
  305. }
  306. public function testResourceGet()
  307. {
  308. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  309. $request = new ezcWebdavGetRequest( '/resource' );
  310. $request->validateHeaders();
  311. $response = $backend->get( $request );
  312. $expectedResponse = new ezcWebdavGetResourceResponse(
  313. new ezcWebdavResource(
  314. '/resource',
  315. $backend->getAllProperties( '/resource' ),
  316. "Some webdav contents.\n"
  317. )
  318. );
  319. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
  320. $this->assertEquals(
  321. $expectedResponse,
  322. $response,
  323. 'Expected response does not match real response.',
  324. 0,
  325. 20
  326. );
  327. }
  328. public function testResourceGetError()
  329. {
  330. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  331. $request = new ezcWebdavGetRequest( '/unknown' );
  332. $request->validateHeaders();
  333. $response = $backend->get( $request );
  334. $this->assertEquals(
  335. $response,
  336. new ezcWebdavErrorResponse(
  337. ezcWebdavResponse::STATUS_404,
  338. '/unknown'
  339. ),
  340. 'Expected response does not match real response.',
  341. 0,
  342. 20
  343. );
  344. }
  345. public function testCollectionGet()
  346. {
  347. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  348. $request = new ezcWebdavGetRequest( '/collection' );
  349. $request->validateHeaders();
  350. $response = $backend->get( $request );
  351. $expectedResponse = new ezcWebdavGetCollectionResponse(
  352. new ezcWebdavCollection(
  353. '/collection',
  354. $backend->getAllProperties( '/collection' ),
  355. array(
  356. new ezcWebdavCollection(
  357. '/collection/deep_collection'
  358. ),
  359. new ezcWebdavResource(
  360. '/collection/test.txt'
  361. ),
  362. )
  363. )
  364. );
  365. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection', 'getetag' )->etag );
  366. $this->assertEquals(
  367. $expectedResponse,
  368. $response,
  369. 'Expected response does not match real response.',
  370. 0,
  371. 20
  372. );
  373. }
  374. public function testResourceDeepGet()
  375. {
  376. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  377. $request = new ezcWebdavGetRequest( '/collection/deep_collection/deep_test.txt' );
  378. $request->validateHeaders();
  379. $response = $backend->get( $request );
  380. $expectedResponse = new ezcWebdavGetResourceResponse(
  381. new ezcWebdavResource(
  382. '/collection/deep_collection/deep_test.txt',
  383. $backend->getAllProperties( '/collection/deep_collection/deep_test.txt' ),
  384. "=========\nTest file\n=========\n\nAnd again some randome contents...\n"
  385. )
  386. );
  387. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection/deep_collection/deep_test.txt', 'getetag' )->etag );
  388. $this->assertEquals(
  389. $expectedResponse,
  390. $response,
  391. 'Expected response does not match real response.',
  392. 0,
  393. 20
  394. );
  395. }
  396. public function testResourceCopy()
  397. {
  398. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  399. $request = new ezcWebdavCopyRequest( '/resource', '/new_resource' );
  400. $request->validateHeaders();
  401. $response = $backend->copy( $request );
  402. $this->assertEquals(
  403. $response,
  404. new ezcWebdavCopyResponse(
  405. false
  406. ),
  407. 'Expected response does not match real response.',
  408. 0,
  409. 20
  410. );
  411. }
  412. public function testResourceCopyProperties()
  413. {
  414. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  415. $backend->options->useMimeExts = false;
  416. $newProperties = new ezcWebdavFlaggedPropertyStorage();
  417. $newProperties->attach(
  418. $p1 = new ezcWebdavGetContentTypeProperty( 'text/xml' ),
  419. ezcWebdavPropPatchRequest::SET
  420. );
  421. $newProperties->attach(
  422. $p2 = new ezcWebdavDeadProperty( 'foo:', 'bar', "<?xml version=\"1.0\"?>\n<bar xmlns=\"foo:\">some content</bar>\n" ),
  423. ezcWebdavPropPatchRequest::SET
  424. );
  425. $request = new ezcWebdavPropPatchRequest( '/resource' );
  426. $request->updates = $newProperties;
  427. $request->validateHeaders();
  428. $response = $backend->proppatch( $request );
  429. $request = new ezcWebdavCopyRequest( '/resource', '/new_resource' );
  430. $request->validateHeaders();
  431. $response = $backend->copy( $request );
  432. $this->assertEquals(
  433. $response,
  434. new ezcWebdavCopyResponse(
  435. false
  436. ),
  437. 'Expected response does not match real response.',
  438. 0,
  439. 20
  440. );
  441. $this->assertTrue(
  442. is_file( $this->tempDir . 'backend/.ezc/new_resource.xml' ),
  443. 'Expected creation of property storage.'
  444. );
  445. $request = new ezcWebdavPropFindRequest( '/new_resource' );
  446. $request->prop = $newProperties;
  447. $request->validateHeaders();
  448. $response = $backend->propfind( $request );
  449. $responseProperty = new ezcWebdavBasicPropertyStorage();
  450. $responseProperty->attach( $p1 );
  451. $responseProperty->attach( $p2 );
  452. $responseProperty->rewind();
  453. $expectedResponse = new ezcWebdavMultistatusResponse(
  454. new ezcWebdavPropFindResponse(
  455. new ezcWebdavResource( '/new_resource' ),
  456. new ezcWebdavPropStatResponse(
  457. $responseProperty
  458. )
  459. )
  460. );
  461. $this->assertEquals(
  462. $expectedResponse,
  463. $response,
  464. 'Expected response does not match real response.',
  465. 0,
  466. 20
  467. );
  468. }
  469. public function testResourceCopyError()
  470. {
  471. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  472. $request = new ezcWebdavCopyRequest( '/unknown', '/irrelevant' );
  473. $request->validateHeaders();
  474. $response = $backend->copy( $request );
  475. $this->assertEquals(
  476. $response,
  477. new ezcWebdavErrorResponse(
  478. ezcWebdavResponse::STATUS_404,
  479. '/unknown'
  480. ),
  481. 'Expected response does not match real response.',
  482. 0,
  483. 20
  484. );
  485. }
  486. public function testResourceCopyF()
  487. {
  488. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  489. $request = new ezcWebdavCopyRequest( '/resource', '/collection/resource' );
  490. $request->setHeader( 'Overwrite', 'F' );
  491. $request->validateHeaders();
  492. $response = $backend->copy( $request );
  493. $this->assertEquals(
  494. $response,
  495. new ezcWebdavCopyResponse(
  496. false
  497. ),
  498. 'Expected response does not match real response.',
  499. 0,
  500. 20
  501. );
  502. }
  503. public function testResourceCopyOverwrite()
  504. {
  505. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  506. $request = new ezcWebdavCopyRequest( '/resource', '/collection/test.txt' );
  507. $request->validateHeaders();
  508. $response = $backend->copy( $request );
  509. $this->assertEquals(
  510. $response,
  511. new ezcWebdavCopyResponse(
  512. true
  513. ),
  514. 'Expected response does not match real response.',
  515. 0,
  516. 20
  517. );
  518. }
  519. public function testResourceCopyOverwriteFailed()
  520. {
  521. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  522. $request = new ezcWebdavCopyRequest( '/resource', '/collection/test.txt' );
  523. $request->setHeader( 'Overwrite', 'F' );
  524. $request->validateHeaders();
  525. $response = $backend->copy( $request );
  526. $this->assertEquals(
  527. $response,
  528. new ezcWebdavErrorResponse(
  529. ezcWebdavResponse::STATUS_412,
  530. '/collection/test.txt'
  531. ),
  532. 'Expected response does not match real response.',
  533. 0,
  534. 20
  535. );
  536. }
  537. public function testResourceCopyDestinationNotExisting()
  538. {
  539. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  540. $request = new ezcWebdavCopyRequest( '/resource', '/dum/di' );
  541. $request->validateHeaders();
  542. $response = $backend->copy( $request );
  543. $this->assertEquals(
  544. $response,
  545. new ezcWebdavErrorResponse(
  546. ezcWebdavResponse::STATUS_409,
  547. '/dum/di'
  548. ),
  549. 'Expected response does not match real response.',
  550. 0,
  551. 20
  552. );
  553. }
  554. public function testResourceCopySourceEqualsDest()
  555. {
  556. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  557. $request = new ezcWebdavCopyRequest( '/resource', '/resource' );
  558. $request->validateHeaders();
  559. $response = $backend->copy( $request );
  560. $this->assertEquals(
  561. $response,
  562. new ezcWebdavErrorResponse(
  563. ezcWebdavResponse::STATUS_403,
  564. '/resource'
  565. ),
  566. 'Expected response does not match real response.',
  567. 0,
  568. 20
  569. );
  570. }
  571. public function testResourceCopyDepthZero()
  572. {
  573. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  574. $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
  575. $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_ZERO );
  576. $request->validateHeaders();
  577. $response = $backend->copy( $request );
  578. $this->assertEquals(
  579. $response,
  580. new ezcWebdavCopyResponse(
  581. false
  582. ),
  583. 'Expected response does not match real response.',
  584. 0,
  585. 20
  586. );
  587. $this->assertTrue(
  588. is_dir( $this->tempDir . 'backend/new_collection' ),
  589. 'Expected created collection.'
  590. );
  591. }
  592. public function testResourceCopyDepthInfinity()
  593. {
  594. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  595. $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
  596. $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
  597. $request->validateHeaders();
  598. $response = $backend->copy( $request );
  599. $this->assertEquals(
  600. $response,
  601. new ezcWebdavCopyResponse(
  602. false
  603. ),
  604. 'Expected response does not match real response.',
  605. 0,
  606. 20
  607. );
  608. $this->assertTrue(
  609. is_dir( $this->tempDir . 'backend/new_collection' ),
  610. 'Expected created collection.'
  611. );
  612. $this->assertTrue(
  613. is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
  614. 'Expected created file in collection.'
  615. );
  616. $this->assertTrue(
  617. is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
  618. 'Expected created deep file in collection.'
  619. );
  620. }
  621. public function testResourceCopyDepthInfinityErrors()
  622. {
  623. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  624. // Cause error by making file not readable
  625. chmod ( $this->tempDir . 'backend/collection/test.txt', 0 );
  626. $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
  627. $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
  628. $request->validateHeaders();
  629. $response = $backend->copy( $request );
  630. $this->assertEquals(
  631. $response,
  632. new ezcWebdavMultistatusResponse(
  633. new ezcWebdavErrorResponse(
  634. ezcWebdavResponse::STATUS_423,
  635. '/collection/test.txt'
  636. )
  637. ),
  638. 'Expected response does not match real response.',
  639. 0,
  640. 20
  641. );
  642. $this->assertTrue(
  643. is_dir( $this->tempDir . 'backend/new_collection' ),
  644. 'Expected created collection.'
  645. );
  646. $this->assertFalse(
  647. is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
  648. 'Expected file in collection not to be created.'
  649. );
  650. $this->assertTrue(
  651. is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
  652. 'Expected created deep file in collection.'
  653. );
  654. chmod ( $this->tempDir . 'backend/collection/test.txt', 0777 );
  655. }
  656. public function testResourceMove()
  657. {
  658. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  659. $request = new ezcWebdavMoveRequest( '/resource', '/dest' );
  660. $request->validateHeaders();
  661. $response = $backend->move( $request );
  662. $this->assertEquals(
  663. $response,
  664. new ezcWebdavMoveResponse(
  665. false
  666. ),
  667. 'Expected response does not match real response.',
  668. 0,
  669. 20
  670. );
  671. }
  672. public function testResourceMoveError()
  673. {
  674. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  675. $request = new ezcWebdavMoveRequest( '/unknown', '/irrelevant' );
  676. $request->validateHeaders();
  677. $response = $backend->move( $request );
  678. $this->assertEquals(
  679. $response,
  680. new ezcWebdavErrorResponse(
  681. ezcWebdavResponse::STATUS_404,
  682. '/unknown'
  683. ),
  684. 'Expected response does not match real response.',
  685. 0,
  686. 20
  687. );
  688. }
  689. public function testResourceMoveF()
  690. {
  691. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  692. $request = new ezcWebdavMoveRequest( '/resource', '/dest' );
  693. $request->setHeader( 'Overwrite', 'F' );
  694. $request->validateHeaders();
  695. $response = $backend->move( $request );
  696. $this->assertEquals(
  697. $response,
  698. new ezcWebdavMoveResponse(
  699. false
  700. ),
  701. 'Expected response does not match real response.',
  702. 0,
  703. 20
  704. );
  705. }
  706. public function testResourceMoveOverwrite()
  707. {
  708. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  709. $request = new ezcWebdavMoveRequest( '/resource', '/collection/test.txt' );
  710. $request->validateHeaders();
  711. $response = $backend->move( $request );
  712. $this->assertEquals(
  713. $response,
  714. new ezcWebdavMoveResponse(
  715. true
  716. ),
  717. 'Expected response does not match real response.',
  718. 0,
  719. 20
  720. );
  721. }
  722. public function testResourceMoveOverwriteFailed()
  723. {
  724. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  725. $request = new ezcWebdavMoveRequest( '/resource', '/collection/test.txt' );
  726. $request->setHeader( 'Overwrite', 'F' );
  727. $request->validateHeaders();
  728. $response = $backend->move( $request );
  729. $this->assertEquals(
  730. $response,
  731. new ezcWebdavErrorResponse(
  732. ezcWebdavResponse::STATUS_412,
  733. '/collection/test.txt'
  734. ),
  735. 'Expected response does not match real response.',
  736. 0,
  737. 20
  738. );
  739. }
  740. public function testResourceMoveDestinationNotExisting()
  741. {
  742. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  743. $request = new ezcWebdavMoveRequest( '/resource', '/dum/di' );
  744. $request->validateHeaders();
  745. $response = $backend->move( $request );
  746. $this->assertEquals(
  747. $response,
  748. new ezcWebdavErrorResponse(
  749. ezcWebdavResponse::STATUS_409,
  750. '/dum/di'
  751. ),
  752. 'Expected response does not match real response.',
  753. 0,
  754. 20
  755. );
  756. }
  757. public function testResourceMoveSourceEqualsDest()
  758. {
  759. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  760. $request = new ezcWebdavMoveRequest( '/resource', '/resource' );
  761. $request->validateHeaders();
  762. $response = $backend->move( $request );
  763. $this->assertEquals(
  764. $response,
  765. new ezcWebdavErrorResponse(
  766. ezcWebdavResponse::STATUS_403,
  767. '/resource'
  768. ),
  769. 'Expected response does not match real response.',
  770. 0,
  771. 20
  772. );
  773. }
  774. public function testResourceMoveDepthInfinity()
  775. {
  776. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  777. $this->assertTrue(
  778. is_dir( $this->tempDir . 'backend/collection' ),
  779. 'Expected existing collection before request.'
  780. );
  781. $request = new ezcWebdavMoveRequest( '/collection', '/new_collection' );
  782. $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
  783. $request->validateHeaders();
  784. $response = $backend->move( $request );
  785. $this->assertEquals(
  786. $response,
  787. new ezcWebdavMoveResponse(
  788. false
  789. ),
  790. 'Expected response does not match real response.',
  791. 0,
  792. 20
  793. );
  794. $this->assertFalse(
  795. is_dir( $this->tempDir . 'backend/collection' ),
  796. 'Expected removed collection.'
  797. );
  798. $this->assertTrue(
  799. is_dir( $this->tempDir . 'backend/new_collection' ),
  800. 'Expected created collection.'
  801. );
  802. $this->assertTrue(
  803. is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
  804. 'Expected created file in collection.'
  805. );
  806. $this->assertTrue(
  807. is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
  808. 'Expected created deep file in collection.'
  809. );
  810. }
  811. public function testResourceMoveDepthInfinityErrors()
  812. {
  813. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  814. // Cause error by making file not readable
  815. chmod ( $this->tempDir . 'backend/collection/test.txt', 0 );
  816. $this->assertTrue(
  817. is_dir( $this->tempDir . 'backend/collection' ),
  818. 'Expected existing collection before request.'
  819. );
  820. $request = new ezcWebdavMoveRequest( '/collection', '/new_collection' );
  821. $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
  822. $request->validateHeaders();
  823. $response = $backend->move( $request );
  824. $this->assertEquals(
  825. $response,
  826. new ezcWebdavMultistatusResponse(
  827. new ezcWebdavErrorResponse(
  828. ezcWebdavResponse::STATUS_423,
  829. '/collection/test.txt'
  830. )
  831. ),
  832. 'Expected response does not match real response.',
  833. 0,
  834. 20
  835. );
  836. $this->assertTrue(
  837. is_dir( $this->tempDir . 'backend/collection' ),
  838. 'Expected collection not to be removed.'
  839. );
  840. $this->assertTrue(
  841. is_dir( $this->tempDir . 'backend/new_collection' ),
  842. 'Expected created collection.'
  843. );
  844. $this->assertFalse(
  845. is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
  846. 'Expected file in collection not to be created.'
  847. );
  848. $this->assertTrue(
  849. is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
  850. 'Expected created deep file in collection.'
  851. );
  852. chmod ( $this->tempDir . 'backend/collection/test.txt', 0777 );
  853. }
  854. public function testResourceDelete()
  855. {
  856. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  857. $this->assertTrue(
  858. is_file( $this->tempDir . 'backend/resource' ),
  859. 'Expected existing file.'
  860. );
  861. $request = new ezcWebdavDeleteRequest( '/resource' );
  862. $request->validateHeaders();
  863. $response = $backend->delete( $request );
  864. $this->assertEquals(
  865. $response,
  866. new ezcWebdavDeleteResponse(
  867. '/resource'
  868. ),
  869. 'Expected response does not match real response.',
  870. 0,
  871. 20
  872. );
  873. $this->assertFalse(
  874. is_file( $this->tempDir . 'backend/resource' ),
  875. 'Expected file to be removed.'
  876. );
  877. }
  878. public function testCollectionDelete()
  879. {
  880. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  881. $this->assertTrue(
  882. is_dir( $this->tempDir . 'backend/collection' ),
  883. 'Expected existing directory.'
  884. );
  885. $request = new ezcWebdavDeleteRequest( '/collection' );
  886. $request->validateHeaders();
  887. $response = $backend->delete( $request );
  888. $this->assertEquals(
  889. $response,
  890. new ezcWebdavDeleteResponse(
  891. '/collection'
  892. ),
  893. 'Expected response does not match real response.',
  894. 0,
  895. 20
  896. );
  897. $this->assertFalse(
  898. is_dir( $this->tempDir . 'backend/collection' ),
  899. 'Expected directory to be removed.'
  900. );
  901. }
  902. public function testResourceDeleteError404()
  903. {
  904. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  905. $request = new ezcWebdavDeleteRequest( '/unknown' );
  906. $request->validateHeaders();
  907. $response = $backend->delete( $request );
  908. $this->assertEquals(
  909. $response,
  910. new ezcWebdavErrorResponse(
  911. ezcWebdavResponse::STATUS_404,
  912. '/unknown'
  913. ),
  914. 'Expected response does not match real response.',
  915. 0,
  916. 20
  917. );
  918. }
  919. public function testResourceDeleteCausedError()
  920. {
  921. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  922. $this->assertTrue(
  923. is_file( $this->tempDir . 'backend/collection/test.txt' ),
  924. 'Expected existing file.'
  925. );
  926. chmod ( $this->tempDir . 'backend/collection', 0 );
  927. // @TODO: This can be removed with the latest PHPUnit release, but for
  928. // now we need it, or the is_file() call on backend/collection/test.txt
  929. // will return a wrong cached result.
  930. clearstatcache();
  931. $request = new ezcWebdavDeleteRequest( '/collection/test.txt' );
  932. $request->validateHeaders();
  933. $response = $backend->delete( $request );
  934. $this->assertEquals(
  935. $response,
  936. new ezcWebdavErrorResponse(
  937. ezcWebdavResponse::STATUS_404,
  938. '/collection/test.txt'
  939. ),
  940. 'Expected response does not match real response.',
  941. 0,
  942. 20
  943. );
  944. $this->assertTrue(
  945. is_file( $this->tempDir . 'backend/resource' ),
  946. 'Expected still existing file.'
  947. );
  948. chmod ( $this->tempDir . 'backend/collection', 0777 );
  949. }
  950. public function testResourceDeleteFailure()
  951. {
  952. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  953. $this->assertTrue(
  954. is_file( $this->tempDir . 'backend/collection/test.txt' ),
  955. 'Expected existing file.'
  956. );
  957. chmod ( $this->tempDir . 'backend/collection', 0555 );
  958. // @TODO: This can be removed with the latest PHPUnit release, but for
  959. // now we need it, or the is_file() call on backend/collection/test.txt
  960. // will return a wrong cached result.
  961. clearstatcache();
  962. $request = new ezcWebdavDeleteRequest( '/collection/test.txt' );
  963. $request->validateHeaders();
  964. $response = $backend->delete( $request );
  965. $this->assertEquals(
  966. $response,
  967. new ezcWebdavMultistatusResponse(
  968. new ezcWebdavErrorResponse(
  969. ezcWebdavResponse::STATUS_403,
  970. '/collection/test.txt'
  971. )
  972. ),
  973. 'Expected response does not match real response.',
  974. 0,
  975. 20
  976. );
  977. $this->assertTrue(
  978. is_file( $this->tempDir . 'backend/resource' ),
  979. 'Expected still existing file.'
  980. );
  981. chmod ( $this->tempDir . 'backend/collection', 0777 );
  982. }
  983. public function testMakeCollectionOnExistingCollection()
  984. {
  985. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  986. $request = new ezcWebdavMakeCollectionRequest( '/collection' );
  987. $request->validateHeaders();
  988. $response = $backend->makeCollection( $request );
  989. $this->assertEquals(
  990. $response,
  991. new ezcWebdavErrorResponse(
  992. ezcWebdavResponse::STATUS_405,
  993. '/collection'
  994. ),
  995. 'Expected response does not match real response.',
  996. 0,
  997. 20
  998. );
  999. }
  1000. public function testMakeCollectionOnExistingRessource()
  1001. {
  1002. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1003. $request = new ezcWebdavMakeCollectionRequest( '/resource' );
  1004. $request->validateHeaders();
  1005. $response = $backend->makeCollection( $request );
  1006. $this->assertEquals(
  1007. $response,
  1008. new ezcWebdavErrorResponse(
  1009. ezcWebdavResponse::STATUS_405,
  1010. '/resource'
  1011. ),
  1012. 'Expected response does not match real response.',
  1013. 0,
  1014. 20
  1015. );
  1016. }
  1017. public function testMakeCollectionMissingParent()
  1018. {
  1019. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1020. $request = new ezcWebdavMakeCollectionRequest( '/dum/di' );
  1021. $request->validateHeaders();
  1022. $response = $backend->makeCollection( $request );
  1023. $this->assertEquals(
  1024. $response,
  1025. new ezcWebdavErrorResponse(
  1026. ezcWebdavResponse::STATUS_409,
  1027. '/dum/di'
  1028. ),
  1029. 'Expected response does not match real response.',
  1030. 0,
  1031. 20
  1032. );
  1033. }
  1034. public function testMakeCollectionInRessource()
  1035. {
  1036. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1037. $request = new ezcWebdavMakeCollectionRequest( '/resource/collection' );
  1038. $request->validateHeaders();
  1039. $response = $backend->makeCollection( $request );
  1040. $this->assertEquals(
  1041. $response,
  1042. new ezcWebdavErrorResponse(
  1043. ezcWebdavResponse::STATUS_403,
  1044. '/resource/collection'
  1045. ),
  1046. 'Expected response does not match real response.',
  1047. 0,
  1048. 20
  1049. );
  1050. }
  1051. public function testMakeCollectionWithRequestBody()
  1052. {
  1053. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1054. $request = new ezcWebdavMakeCollectionRequest( '/collection/new_collection', 'with request body' );
  1055. $request->validateHeaders();
  1056. $response = $backend->makeCollection( $request );
  1057. $this->assertEquals(
  1058. $response,
  1059. new ezcWebdavErrorResponse(
  1060. ezcWebdavResponse::STATUS_415,
  1061. '/collection/new_collection'
  1062. ),
  1063. 'Expected response does not match real response.',
  1064. 0,
  1065. 20
  1066. );
  1067. }
  1068. public function testMakeCollection()
  1069. {
  1070. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1071. $this->assertFalse(
  1072. is_dir( $this->tempDir . 'backend/collection/new_collection' ),
  1073. 'Expected collection not existing yet.'
  1074. );
  1075. $request = new ezcWebdavMakeCollectionRequest( '/collection/new_collection' );
  1076. $request->validateHeaders();
  1077. $response = $backend->makeCollection( $request );
  1078. $this->assertEquals(
  1079. $response,
  1080. new ezcWebdavMakeCollectionResponse(
  1081. '/bar/foo'
  1082. ),
  1083. 'Expected response does not match real response.',
  1084. 0,
  1085. 20
  1086. );
  1087. $this->assertTrue(
  1088. is_dir( $this->tempDir . 'backend/collection/new_collection' ),
  1089. 'Expected created collection.'
  1090. );
  1091. $this->assertTrue(
  1092. is_dir( $this->tempDir . 'backend/collection/new_collection/.ezc' ),
  1093. 'Expected property storage in directory.'
  1094. );
  1095. }
  1096. public function testMakeCollectionWithSpaces()
  1097. {
  1098. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1099. $this->assertFalse(
  1100. is_dir( $this->tempDir . 'backend/collection/new_collection' ),
  1101. 'Collection to create exists.'
  1102. );
  1103. $request = new ezcWebdavMakeCollectionRequest( '/collection/collection%20with%20spaces' );
  1104. $request->validateHeaders();
  1105. $response = $backend->makeCollection( $request );
  1106. $this->assertEquals(
  1107. $response,
  1108. new ezcWebdavMakeCollectionResponse(
  1109. '/collection/collection%20with%20spaces'
  1110. ),
  1111. 'Expected response does not match real response.'
  1112. );
  1113. $this->assertTrue(
  1114. is_dir( $this->tempDir . 'backend/collection/collection%20with%20spaces' ),
  1115. 'Expected created collection.'
  1116. );
  1117. $this->assertTrue(
  1118. is_dir( $this->tempDir . 'backend/collection/collection%20with%20spaces/.ezc' ),
  1119. 'Expected property storage in directory.'
  1120. );
  1121. $this->assertEquals(
  1122. 'collection with spaces',
  1123. $backend->getAllProperties( '/collection/collection%20with%20spaces' )->get( 'displayname', 'DAV:' )->displayName
  1124. );
  1125. }
  1126. public function testPutOnExistingCollection()
  1127. {
  1128. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1129. $request = new ezcWebdavPutRequest( '/collection', 'some content' );
  1130. $request->setHeader( 'Content-Length', 23 );
  1131. $request->validateHeaders();
  1132. $response = $backend->put( $request );
  1133. $this->assertEquals(
  1134. $response,
  1135. new ezcWebdavErrorResponse(
  1136. ezcWebdavResponse::STATUS_409,
  1137. '/collection'
  1138. ),
  1139. 'Expected response does not match real response.',
  1140. 0,
  1141. 20
  1142. );
  1143. }
  1144. public function testPutMissingParent()
  1145. {
  1146. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1147. $request = new ezcWebdavPutRequest( '/dum/di', 'some content' );
  1148. $request->setHeader( 'Content-Length', 23 );
  1149. $request->validateHeaders();
  1150. $response = $backend->put( $request );
  1151. $this->assertEquals(
  1152. $response,
  1153. new ezcWebdavErrorResponse(
  1154. ezcWebdavResponse::STATUS_409,
  1155. '/dum/di'
  1156. ),
  1157. 'Expected response does not match real response.',
  1158. 0,
  1159. 20
  1160. );
  1161. }
  1162. public function testPutInRessource()
  1163. {
  1164. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1165. $request = new ezcWebdavPutRequest( '/resource/new_resource', 'some content' );
  1166. $request->setHeader( 'Content-Length', 23 );
  1167. $request->validateHeaders();
  1168. $response = $backend->put( $request );
  1169. $this->assertEquals(
  1170. $response,
  1171. new ezcWebdavErrorResponse(
  1172. ezcWebdavResponse::STATUS_409,
  1173. '/resource/new_resource'
  1174. ),
  1175. 'Expected response does not match real response.',
  1176. 0,
  1177. 20
  1178. );
  1179. }
  1180. public function testPut()
  1181. {
  1182. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1183. $this->assertFalse(
  1184. is_file( $this->tempDir . 'backend/collection/new_resource' ),
  1185. 'Expected resource not existing yet.'
  1186. );
  1187. $request = new ezcWebdavPutRequest( '/collection/new_resource', 'some content' );
  1188. $request->setHeader( 'Content-Length', 23 );
  1189. $request->validateHeaders();
  1190. $response = $backend->put( $request );
  1191. $expectedResponse = new ezcWebdavPutResponse(
  1192. '/collection/new_resource'
  1193. );
  1194. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection/new_resource', 'getetag' )->etag );
  1195. $this->assertEquals(
  1196. $expectedResponse,
  1197. $response,
  1198. 'Expected response does not match real response.',
  1199. 0,
  1200. 20
  1201. );
  1202. $this->assertTrue(
  1203. is_file( $this->tempDir . 'backend/collection/new_resource' ),
  1204. 'Expected created resource.'
  1205. );
  1206. $this->assertEquals(
  1207. 'some content',
  1208. file_get_contents( $this->tempDir . 'backend/collection/new_resource' )
  1209. );
  1210. $this->assertTrue(
  1211. is_dir( $this->tempDir . 'backend/collection/.ezc' ),
  1212. 'Expected property storage in directory.'
  1213. );
  1214. }
  1215. public function testPutOnExistingRessource()
  1216. {
  1217. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1218. $this->assertTrue(
  1219. is_file( $this->tempDir . 'backend/resource' ),
  1220. 'Expected created resource.'
  1221. );
  1222. $this->assertEquals(
  1223. "Some webdav contents.\n",
  1224. file_get_contents( $this->tempDir . 'backend/resource' )
  1225. );
  1226. $request = new ezcWebdavPutRequest( '/resource', 'some content' );
  1227. $request->setHeader( 'Content-Length', strlen( $request->body ) );
  1228. $request->validateHeaders();
  1229. $response = $backend->put( $request );
  1230. $expectedResponse = new ezcWebdavPutResponse(
  1231. '/resource'
  1232. );
  1233. $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
  1234. $this->assertEquals(
  1235. $expectedResponse,
  1236. $response,
  1237. 'Expected response does not match real response.',
  1238. 0,
  1239. 20
  1240. );
  1241. $this->assertTrue(
  1242. is_file( $this->tempDir . 'backend/resource' ),
  1243. 'Expected created resource.'
  1244. );
  1245. $this->assertEquals(
  1246. 'some content',
  1247. file_get_contents( $this->tempDir . 'backend/resource' )
  1248. );
  1249. }
  1250. public function testPropFindOnResource()
  1251. {
  1252. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1253. $requestedProperties = new ezcWebdavBasicPropertyStorage();
  1254. $requestedProperties->attach(
  1255. $prop1 = new ezcWebdavGetContentLengthProperty()
  1256. );
  1257. $requestedProperties->attach(
  1258. $prop2 = new ezcWebdavGetLastModifiedProperty()
  1259. );
  1260. $requestedProperties->attach(
  1261. $prop3 = new ezcWebdavDeadProperty( 'http://apache.org/dav/props/', 'executable' )
  1262. );
  1263. $request = new ezcWebdavPropFindRequest( '/resource' );
  1264. $request->prop = $requestedProperties;
  1265. $request->validateHeaders();
  1266. $response = $backend->propfind( $request );
  1267. $this->compareResponse( __FUNCTION__, $response );
  1268. }
  1269. public function testPropMimeTypeOnResourceNoExt()
  1270. {
  1271. if ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) ||
  1272. ezcBaseFeatures::hasExtensionSupport( 'mime_magic' ) )
  1273. {
  1274. $this->markTestSkipped( 'Test is run only, when no mime type detection is available.' );
  1275. }
  1276. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1277. $newProperties = new ezcWebdavFlaggedPropertyStorage();
  1278. $newProperties->attach(
  1279. new ezcWebdavGetContentTypeProperty( 'text/xml' ),
  1280. ezcWebdavPropPatchRequest::SET
  1281. );
  1282. $request = new ezcWebdavPropPatchRequest( '/resource' );
  1283. $request->updates = $newProperties;
  1284. $request->validateHeaders();
  1285. $response = $backend->proppatch( $request );
  1286. $requestedProperties = new ezcWebdavBasicPropertyStorage();
  1287. $requestedProperties->attach(
  1288. new ezcWebdavGetContentTypeProperty()
  1289. );
  1290. $request = new ezcWebdavPropFindRequest( '/resource' );
  1291. $request->prop = $requestedProperties;
  1292. $request->validateHeaders();
  1293. $response = $backend->propfind( $request );
  1294. $responseProperty = new ezcWebdavBasicPropertyStorage();
  1295. $responseProperty->attach(
  1296. new ezcWebdavGetContentTypeProperty( 'text/xml' )
  1297. );
  1298. $responseProperty->rewind();
  1299. $expectedResponse = new ezcWebdavMultistatusResponse(
  1300. new ezcWebdavPropFindResponse(
  1301. new ezcWebdavResource( '/resource' ),
  1302. new ezcWebdavPropStatResponse(
  1303. $responseProperty
  1304. )
  1305. )
  1306. );
  1307. $this->assertEquals(
  1308. $expectedResponse,
  1309. $response,
  1310. 'Expected response does not match real response.',
  1311. 0,
  1312. 20
  1313. );
  1314. }
  1315. public function testPropMimeTypeOnResourceMimeMagicExt()
  1316. {
  1317. if ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) ||
  1318. !ezcBaseFeatures::hasExtensionSupport( 'mime_magic' ) )
  1319. {
  1320. $this->markTestSkipped( 'Test is run only, when only mime magic extension is available.' );
  1321. }
  1322. $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
  1323. $newProperties = new ezcWebdavFlaggedPropertyStorage();
  1324. $newProperties->attach(
  1325. new ezcWebdavGetContentTypeProperty( 'text/xml' ),
  1326. ezcWebdavPropPatchRequest::SET
  1327. );
  1328. $request = new ezcWebdavPropPatchRequest( '/resource' );
  1329. $request->updates = $newProperties;
  1330. $request->validateHeaders();
  1331. $response = $backend->proppatch( $request );
  1332. $requestedProperties = new ezcWebdavBasicPropertyStorage();
  1333. $requestedProperties->attach(
  1334. new ezcWebdavGetContentTypeProperty()
  1335. );
  1336. $request = new ezcWebdavPropFindRequest( '/resource' );
  1337. $request->prop = $requestedProperties;
  1338. $request->validateHeaders();
  1339. $response = $backend->propfind( $request );
  1340. $responseProperty = new ezcWebdavBasicPropertyStorage();
  1341. $responseProperty->attach(
  1342. new ezcWebdavGetContentTypeProperty( 'text/plain' )
  1343. );
  1344. $responseProperty->rewind();
  1345. $expectedResponse = new ezcWebdavMultistatusResponse(
  1346. new ezcWebdavPropFindResponse(
  1347. new ezcWebdavResource( '/resource' ),
  1348. new ezcWebdavPropStatResponse(
  1349. $responseProperty
  1350. )
  1351. )
  1352. );
  1353. $this->assertEquals(
  1354. $expectedResponse,
  1355. $response,
  1356. 'Expected response does not match real response.',

Large files files are truncated, but you can click here to view the full file