xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAVACL;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV;
6*a1a3b679SAndreas Boehleruse Sabre\HTTP;
7*a1a3b679SAndreas Boehler
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehlerrequire_once 'Sabre/DAVACL/MockACLNode.php';
10*a1a3b679SAndreas Boehlerrequire_once 'Sabre/HTTP/ResponseMock.php';
11*a1a3b679SAndreas Boehler
12*a1a3b679SAndreas Boehlerclass PluginAdminTest extends \PHPUnit_Framework_TestCase {
13*a1a3b679SAndreas Boehler
14*a1a3b679SAndreas Boehler    function testNoAdminAccess() {
15*a1a3b679SAndreas Boehler
16*a1a3b679SAndreas Boehler        $principalBackend = new PrincipalBackend\Mock();
17*a1a3b679SAndreas Boehler
18*a1a3b679SAndreas Boehler        $tree = array(
19*a1a3b679SAndreas Boehler            new MockACLNode('adminonly', array()),
20*a1a3b679SAndreas Boehler            new PrincipalCollection($principalBackend),
21*a1a3b679SAndreas Boehler        );
22*a1a3b679SAndreas Boehler
23*a1a3b679SAndreas Boehler        $fakeServer = new DAV\Server($tree);
24*a1a3b679SAndreas Boehler        $fakeServer->sapi = new HTTP\SapiMock();
25*a1a3b679SAndreas Boehler        $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm');
26*a1a3b679SAndreas Boehler        $fakeServer->addPlugin($plugin);
27*a1a3b679SAndreas Boehler        $plugin = new Plugin();
28*a1a3b679SAndreas Boehler        $fakeServer->addPlugin($plugin);
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
31*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'OPTIONS',
32*a1a3b679SAndreas Boehler            'HTTP_DEPTH' => 1,
33*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/adminonly',
34*a1a3b679SAndreas Boehler        ));
35*a1a3b679SAndreas Boehler
36*a1a3b679SAndreas Boehler        $response = new HTTP\ResponseMock();
37*a1a3b679SAndreas Boehler
38*a1a3b679SAndreas Boehler        $fakeServer->httpRequest = $request;
39*a1a3b679SAndreas Boehler        $fakeServer->httpResponse = $response;
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler        $fakeServer->exec();
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler        $this->assertEquals(403, $response->status);
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler    }
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler    /**
48*a1a3b679SAndreas Boehler     * @depends testNoAdminAccess
49*a1a3b679SAndreas Boehler     */
50*a1a3b679SAndreas Boehler    function testAdminAccess() {
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler        $principalBackend = new PrincipalBackend\Mock();
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler        $tree = array(
55*a1a3b679SAndreas Boehler            new MockACLNode('adminonly', array()),
56*a1a3b679SAndreas Boehler            new PrincipalCollection($principalBackend),
57*a1a3b679SAndreas Boehler        );
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler        $fakeServer = new DAV\Server($tree);
60*a1a3b679SAndreas Boehler        $fakeServer->sapi = new HTTP\SapiMock();
61*a1a3b679SAndreas Boehler        $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm');
62*a1a3b679SAndreas Boehler        $fakeServer->addPlugin($plugin);
63*a1a3b679SAndreas Boehler        $plugin = new Plugin();
64*a1a3b679SAndreas Boehler        $plugin->adminPrincipals = array(
65*a1a3b679SAndreas Boehler            'principals/admin',
66*a1a3b679SAndreas Boehler        );
67*a1a3b679SAndreas Boehler        $fakeServer->addPlugin($plugin);
68*a1a3b679SAndreas Boehler
69*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
70*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'OPTIONS',
71*a1a3b679SAndreas Boehler            'HTTP_DEPTH' => 1,
72*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/adminonly',
73*a1a3b679SAndreas Boehler        ));
74*a1a3b679SAndreas Boehler
75*a1a3b679SAndreas Boehler        $response = new HTTP\ResponseMock();
76*a1a3b679SAndreas Boehler
77*a1a3b679SAndreas Boehler        $fakeServer->httpRequest = $request;
78*a1a3b679SAndreas Boehler        $fakeServer->httpResponse = $response;
79*a1a3b679SAndreas Boehler
80*a1a3b679SAndreas Boehler        $fakeServer->exec();
81*a1a3b679SAndreas Boehler
82*a1a3b679SAndreas Boehler        $this->assertEquals(200, $response->status);
83*a1a3b679SAndreas Boehler
84*a1a3b679SAndreas Boehler    }
85*a1a3b679SAndreas Boehler}
86