"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php" (10 Jan 2020, 6781 Bytes) of package /linux/www/dav-4.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "AbstractPDOTest.php": 4.0.2_vs_4.0.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\DAVACL\PrincipalBackend;
    6 
    7 use Sabre\DAV;
    8 
    9 abstract class AbstractPDOTest extends \PHPUnit\Framework\TestCase
   10 {
   11     use DAV\DbTestHelperTrait;
   12 
   13     public function setUp()
   14     {
   15         $this->dropTables(['principals', 'groupmembers']);
   16         $this->createSchema('principals');
   17 
   18         $pdo = $this->getPDO();
   19 
   20         $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/user','user@example.org','User')");
   21         $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/group','group@example.org','Group')");
   22 
   23         $pdo->query('INSERT INTO groupmembers (principal_id,member_id) VALUES (5,4)');
   24     }
   25 
   26     public function testConstruct()
   27     {
   28         $pdo = $this->getPDO();
   29         $backend = new PDO($pdo);
   30         $this->assertTrue($backend instanceof PDO);
   31     }
   32 
   33     /**
   34      * @depends testConstruct
   35      */
   36     public function testGetPrincipalsByPrefix()
   37     {
   38         $pdo = $this->getPDO();
   39         $backend = new PDO($pdo);
   40 
   41         $expected = [
   42             [
   43                 'uri' => 'principals/admin',
   44                 '{http://sabredav.org/ns}email-address' => 'admin@example.org',
   45                 '{DAV:}displayname' => 'Administrator',
   46             ],
   47             [
   48                 'uri' => 'principals/user',
   49                 '{http://sabredav.org/ns}email-address' => 'user@example.org',
   50                 '{DAV:}displayname' => 'User',
   51             ],
   52             [
   53                 'uri' => 'principals/group',
   54                 '{http://sabredav.org/ns}email-address' => 'group@example.org',
   55                 '{DAV:}displayname' => 'Group',
   56             ],
   57         ];
   58 
   59         $this->assertEquals($expected, $backend->getPrincipalsByPrefix('principals'));
   60         $this->assertEquals([], $backend->getPrincipalsByPrefix('foo'));
   61     }
   62 
   63     /**
   64      * @depends testConstruct
   65      */
   66     public function testGetPrincipalByPath()
   67     {
   68         $pdo = $this->getPDO();
   69         $backend = new PDO($pdo);
   70 
   71         $expected = [
   72             'id' => 4,
   73             'uri' => 'principals/user',
   74             '{http://sabredav.org/ns}email-address' => 'user@example.org',
   75             '{DAV:}displayname' => 'User',
   76         ];
   77 
   78         $this->assertEquals($expected, $backend->getPrincipalByPath('principals/user'));
   79         $this->assertEquals(null, $backend->getPrincipalByPath('foo'));
   80     }
   81 
   82     public function testGetGroupMemberSet()
   83     {
   84         $pdo = $this->getPDO();
   85         $backend = new PDO($pdo);
   86         $expected = ['principals/user'];
   87 
   88         $this->assertEquals($expected, $backend->getGroupMemberSet('principals/group'));
   89     }
   90 
   91     public function testGetGroupMembership()
   92     {
   93         $pdo = $this->getPDO();
   94         $backend = new PDO($pdo);
   95         $expected = ['principals/group'];
   96 
   97         $this->assertEquals($expected, $backend->getGroupMembership('principals/user'));
   98     }
   99 
  100     public function testSetGroupMemberSet()
  101     {
  102         $pdo = $this->getPDO();
  103 
  104         // Start situation
  105         $backend = new PDO($pdo);
  106         $this->assertEquals(['principals/user'], $backend->getGroupMemberSet('principals/group'));
  107 
  108         // Removing all principals
  109         $backend->setGroupMemberSet('principals/group', []);
  110         $this->assertEquals([], $backend->getGroupMemberSet('principals/group'));
  111 
  112         // Adding principals again
  113         $backend->setGroupMemberSet('principals/group', ['principals/user']);
  114         $this->assertEquals(['principals/user'], $backend->getGroupMemberSet('principals/group'));
  115     }
  116 
  117     public function testSearchPrincipals()
  118     {
  119         $pdo = $this->getPDO();
  120 
  121         $backend = new PDO($pdo);
  122 
  123         $result = $backend->searchPrincipals('principals', ['{DAV:}blabla' => 'foo']);
  124         $this->assertEquals([], $result);
  125 
  126         $result = $backend->searchPrincipals('principals', ['{DAV:}displayname' => 'ou']);
  127         $this->assertEquals(['principals/group'], $result);
  128 
  129         $result = $backend->searchPrincipals('principals', ['{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE']);
  130         $this->assertEquals(['principals/user'], $result);
  131 
  132         $result = $backend->searchPrincipals('mom', ['{DAV:}displayname' => 'UsEr', '{http://sabredav.org/ns}email-address' => 'USER@EXAMPLE']);
  133         $this->assertEquals([], $result);
  134     }
  135 
  136     public function testUpdatePrincipal()
  137     {
  138         $pdo = $this->getPDO();
  139         $backend = new PDO($pdo);
  140 
  141         $propPatch = new DAV\PropPatch([
  142             '{DAV:}displayname' => 'pietje',
  143         ]);
  144 
  145         $backend->updatePrincipal('principals/user', $propPatch);
  146         $result = $propPatch->commit();
  147 
  148         $this->assertTrue($result);
  149 
  150         $this->assertEquals([
  151             'id' => 4,
  152             'uri' => 'principals/user',
  153             '{DAV:}displayname' => 'pietje',
  154             '{http://sabredav.org/ns}email-address' => 'user@example.org',
  155         ], $backend->getPrincipalByPath('principals/user'));
  156     }
  157 
  158     public function testUpdatePrincipalUnknownField()
  159     {
  160         $pdo = $this->getPDO();
  161         $backend = new PDO($pdo);
  162 
  163         $propPatch = new DAV\PropPatch([
  164             '{DAV:}displayname' => 'pietje',
  165             '{DAV:}unknown' => 'foo',
  166         ]);
  167 
  168         $backend->updatePrincipal('principals/user', $propPatch);
  169         $result = $propPatch->commit();
  170 
  171         $this->assertFalse($result);
  172 
  173         $this->assertEquals([
  174             '{DAV:}displayname' => 424,
  175             '{DAV:}unknown' => 403,
  176         ], $propPatch->getResult());
  177 
  178         $this->assertEquals([
  179             'id' => '4',
  180             'uri' => 'principals/user',
  181             '{DAV:}displayname' => 'User',
  182             '{http://sabredav.org/ns}email-address' => 'user@example.org',
  183         ], $backend->getPrincipalByPath('principals/user'));
  184     }
  185 
  186     public function testFindByUriUnknownScheme()
  187     {
  188         $pdo = $this->getPDO();
  189         $backend = new PDO($pdo);
  190         $this->assertNull($backend->findByUri('http://foo', 'principals'));
  191     }
  192 
  193     public function testFindByUriWithMailtoAddress()
  194     {
  195         $pdo = $this->getPDO();
  196         $backend = new PDO($pdo);
  197         $this->assertEquals(
  198             'principals/user',
  199             $backend->findByUri('mailto:user@example.org', 'principals')
  200         );
  201     }
  202 
  203     public function testFindByUriWithUri()
  204     {
  205         $pdo = $this->getPDO();
  206         $backend = new PDO($pdo);
  207         $this->assertEquals(
  208             'principals/user',
  209             $backend->findByUri('principals/user', 'principals')
  210         );
  211     }
  212 
  213     public function testFindByUriWithUnknownUri()
  214     {
  215         $pdo = $this->getPDO();
  216         $backend = new PDO($pdo);
  217         $this->assertNull($backend->findByUri('principals/other', 'principals'));
  218     }
  219 }