"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/CardDAV/VCFExportTest.php" (10 Jan 2020, 3565 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 "VCFExportTest.php": 4.0.2_vs_4.0.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\CardDAV;
    6 
    7 use Sabre\HTTP;
    8 
    9 class VCFExportTest extends \Sabre\DAVServerTest
   10 {
   11     protected $setupCardDAV = true;
   12     protected $autoLogin = 'user1';
   13     protected $setupACL = true;
   14 
   15     protected $carddavAddressBooks = [
   16         [
   17             'id' => 'book1',
   18             'uri' => 'book1',
   19             'principaluri' => 'principals/user1',
   20         ],
   21     ];
   22     protected $carddavCards = [
   23         'book1' => [
   24             'card1' => "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n",
   25             'card2' => "BEGIN:VCARD\r\nFN:Person2\r\nEND:VCARD",
   26             'card3' => "BEGIN:VCARD\r\nFN:Person3\r\nEND:VCARD\r\n",
   27             'card4' => "BEGIN:VCARD\nFN:Person4\nEND:VCARD\n",
   28         ],
   29     ];
   30 
   31     public function setUp()
   32     {
   33         parent::setUp();
   34         $plugin = new VCFExportPlugin();
   35         $this->server->addPlugin(
   36             $plugin
   37         );
   38     }
   39 
   40     public function testSimple()
   41     {
   42         $plugin = $this->server->getPlugin('vcf-export');
   43         $this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $plugin);
   44 
   45         $this->assertEquals(
   46             'vcf-export',
   47             $plugin->getPluginInfo()['name']
   48         );
   49     }
   50 
   51     public function testExport()
   52     {
   53         $request = HTTP\Sapi::createFromServerArray([
   54             'REQUEST_URI' => '/addressbooks/user1/book1?export',
   55             'QUERY_STRING' => 'export',
   56             'REQUEST_METHOD' => 'GET',
   57         ]);
   58 
   59         $response = $this->request($request);
   60         $this->assertEquals(200, $response->status, $response->getBodyAsString());
   61 
   62         $expected = 'BEGIN:VCARD
   63 FN:Person1
   64 END:VCARD
   65 BEGIN:VCARD
   66 FN:Person2
   67 END:VCARD
   68 BEGIN:VCARD
   69 FN:Person3
   70 END:VCARD
   71 BEGIN:VCARD
   72 FN:Person4
   73 END:VCARD
   74 ';
   75         // We actually expected windows line endings
   76         $expected = str_replace("\n", "\r\n", $expected);
   77 
   78         $this->assertEquals($expected, $response->getBodyAsString());
   79     }
   80 
   81     public function testBrowserIntegration()
   82     {
   83         $plugin = $this->server->getPlugin('vcf-export');
   84         $actions = '';
   85         $addressbook = new AddressBook($this->carddavBackend, []);
   86         $this->server->emit('browserButtonActions', ['/foo', $addressbook, &$actions]);
   87         $this->assertContains('/foo?export', $actions);
   88     }
   89 
   90     public function testContentDisposition()
   91     {
   92         $request = new HTTP\Request(
   93             'GET',
   94             '/addressbooks/user1/book1?export'
   95         );
   96 
   97         $response = $this->request($request, 200);
   98         $this->assertEquals('text/directory', $response->getHeader('Content-Type'));
   99         $this->assertEquals(
  100             'attachment; filename="book1-'.date('Y-m-d').'.vcf"',
  101             $response->getHeader('Content-Disposition')
  102         );
  103     }
  104 
  105     public function testContentDispositionBadChars()
  106     {
  107         $this->carddavBackend->createAddressBook(
  108             'principals/user1',
  109             'book-b_ad"(ch)ars',
  110             []
  111         );
  112         $this->carddavBackend->createCard(
  113             'book-b_ad"(ch)ars',
  114             'card1',
  115             "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n"
  116         );
  117 
  118         $request = new HTTP\Request(
  119             'GET',
  120             '/addressbooks/user1/book-b_ad"(ch)ars?export'
  121         );
  122 
  123         $response = $this->request($request, 200);
  124         $this->assertEquals('text/directory', $response->getHeader('Content-Type'));
  125         $this->assertEquals(
  126             'attachment; filename="book-b_adchars-'.date('Y-m-d').'.vcf"',
  127             $response->getHeader('Content-Disposition')
  128         );
  129     }
  130 }