server->addPlugin($locksPlugin); $this->locksPlugin = $locksPlugin; } function testNoConditions() { $serverVars = array( ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $this->assertEquals(array(),$conditions); } function testLockToken() { $serverVars = array( 'HTTP_IF' => '()', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => '', 'tokens' => array( array( 1, 'opaquelocktoken:token1', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function testNotLockToken() { $serverVars = array( 'HTTP_IF' => '(Not )', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => '', 'tokens' => array( array( 0, 'opaquelocktoken:token1', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function testLockTokenUrl() { $serverVars = array( 'HTTP_IF' => ' ()', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => 'http://www.example.com/', 'tokens' => array( array( 1, 'opaquelocktoken:token1', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function test2LockTokens() { $serverVars = array( 'HTTP_IF' => '() (Not )', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => '', 'tokens' => array( array( 1, 'opaquelocktoken:token1', '', ), array( 0, 'opaquelocktoken:token2', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function test2UriLockTokens() { $serverVars = array( 'HTTP_IF' => ' () (Not )', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => 'http://www.example.org/node1', 'tokens' => array( array( 1, 'opaquelocktoken:token1', '', ), ), ), array( 'uri' => 'http://www.example.org/node2', 'tokens' => array( array( 0, 'opaquelocktoken:token2', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function test2UriMultiLockTokens() { $serverVars = array( 'HTTP_IF' => ' () () (Not )', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => 'http://www.example.org/node1', 'tokens' => array( array( 1, 'opaquelocktoken:token1', '', ), array( 1, 'opaquelocktoken:token2', '', ), ), ), array( 'uri' => 'http://www.example.org/node2', 'tokens' => array( array( 0, 'opaquelocktoken:token3', '', ), ), ), ); $this->assertEquals($compare,$conditions); } function testEtag() { $serverVars = array( 'HTTP_IF' => '([etag1])', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => '', 'tokens' => array( array( 1, '', 'etag1', ), ), ), ); $this->assertEquals($compare,$conditions); } function test2Etags() { $serverVars = array( 'HTTP_IF' => ' ([etag1]) ([etag2])', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => 'http://www.example.org/', 'tokens' => array( array( 1, '', 'etag1', ), array( 1, '', 'etag2', ), ), ), ); $this->assertEquals($compare,$conditions); } function testComplexIf() { $serverVars = array( 'HTTP_IF' => ' ( [etag1]) ' . '(Not ) ([etag2]) ' . '() (Not ) ([etag3])', ); $request = new Sabre_HTTP_Request($serverVars); $this->server->httpRequest = ($request); $conditions = $this->locksPlugin->getIfConditions(); $compare = array( array( 'uri' => 'http://www.example.org/node1', 'tokens' => array( array( 1, 'opaquelocktoken:token1', 'etag1', ), array( 0, 'opaquelocktoken:token2', '', ), array( 1, '', 'etag2', ), ), ), array( 'uri' => 'http://www.example.org/node2', 'tokens' => array( array( 1, 'opaquelocktoken:token3', '', ), array( 0, 'opaquelocktoken:token4', '', ), array( 1, '', 'etag3', ), ), ), ); $this->assertEquals($compare,$conditions); } }