aboutsummaryrefslogblamecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php
blob: fb7516a78f84696acf9b00d2f32093bb58b987b2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                           


                      







                                                        







                                                                   
                               
                                          
 
                                                          






                                            

                                                
 
                              
 
                                                    







                                 



                                         
                                          
 
                                                          






                                            

                                                
 
                              
 
                                                    


     
<?php

namespace Sabre\DAVACL;

use Sabre\DAV;
use Sabre\HTTP;


require_once 'Sabre/DAVACL/MockACLNode.php';
require_once 'Sabre/HTTP/ResponseMock.php';

class PluginAdminTest extends \PHPUnit_Framework_TestCase {

    public $server;

    function setUp() {

        $principalBackend = new PrincipalBackend\Mock();

        $tree = array(
            new MockACLNode('adminonly', array()),
            new PrincipalCollection($principalBackend),
        );

        $this->server = new DAV\Server($tree);
        $this->server->sapi = new HTTP\SapiMock();
        $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock());
        $this->server->addPlugin($plugin);
    }

    function testNoAdminAccess() {

        $plugin = new Plugin();
        $this->server->addPlugin($plugin);

        $request = HTTP\Sapi::createFromServerArray(array(
            'REQUEST_METHOD' => 'OPTIONS',
            'HTTP_DEPTH' => 1,
            'REQUEST_URI' => '/adminonly',
        ));

        $response = new HTTP\ResponseMock();

        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;

        $this->server->exec();

        $this->assertEquals(403, $response->status);

    }

    /**
     * @depends testNoAdminAccess
     */
    function testAdminAccess() {

        $plugin = new Plugin();
        $plugin->adminPrincipals = array(
            'principals/admin',
        );
        $this->server->addPlugin($plugin);

        $request = HTTP\Sapi::createFromServerArray(array(
            'REQUEST_METHOD' => 'OPTIONS',
            'HTTP_DEPTH' => 1,
            'REQUEST_URI' => '/adminonly',
        ));

        $response = new HTTP\ResponseMock();

        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;

        $this->server->exec();

        $this->assertEquals(200, $response->status);

    }
}