~ubuntu-branches/debian/sid/php-horde-turba/sid

« back to all changes in this revision

Viewing changes to turba-4.1.0/test/Turba/Unit/Turba/Base.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-08-11 13:16:25 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130811131625-z91stjvq51jr9onv
Tags: 4.1.1-1
New upstream version 4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Test the core Turba class with various backends.
4
 
 *
5
 
 * PHP version 5
6
 
 *
7
 
 * @category   Horde
8
 
 * @package    Turba
9
 
 * @subpackage UnitTests
10
 
 * @author     Gunnar Wrobel <wrobel@pardus.de>
11
 
 * @link       http://www.horde.org/apps/turba
12
 
 * @license    http://www.horde.org/licenses/apache Apache-like
13
 
 */
14
 
 
15
 
/**
16
 
 * Prepare the test setup.
17
 
 */
18
 
require_once __DIR__ . '/../../TestCase.php';
19
 
 
20
 
/**
21
 
 * Test the core Turba class with various backends.
22
 
 *
23
 
 * Copyright 2011-2013 Horde LLC (http://www.horde.org/)
24
 
 *
25
 
 * See the enclosed file LICENSE for license information (ASL). If you
26
 
 * did not receive this file, see http://www.horde.org/licenses/apache.
27
 
 *
28
 
 * @category   Horde
29
 
 * @package    Turba
30
 
 * @subpackage UnitTests
31
 
 * @author     Gunnar Wrobel <wrobel@pardus.de>
32
 
 * @link       http://www.horde.org/apps/turba
33
 
 * @license    http://www.horde.org/licenses/apache Apache-like
34
 
 */
35
 
class Turba_Unit_Turba_Base extends Turba_TestCase
36
 
{
37
 
    /**
38
 
     * The test setup.
39
 
     *
40
 
     * @var Horde_Test_Setup
41
 
     */
42
 
    static $setup;
43
 
 
44
 
    /**
45
 
     * The default share name expected to be used.
46
 
     *
47
 
     * @var string
48
 
     */
49
 
    protected $default_name = 'Address book of test@example.com';
50
 
 
51
 
    public static function setUpBeforeClass()
52
 
    {
53
 
        self::createBasicTurbaSetup(self::$setup);
54
 
        parent::setUpBeforeClass();
55
 
    }
56
 
 
57
 
    public static function tearDownAfterClass()
58
 
    {
59
 
        self::tearDownBasicTurbaSetup();
60
 
        self::tearDownShares();
61
 
        parent::tearDownAfterClass();
62
 
    }
63
 
 
64
 
    public function setUp()
65
 
    {
66
 
        $error = self::$setup->getError();
67
 
        if (!empty($error)) {
68
 
            $this->markTestSkipped($error);
69
 
        }
70
 
    }
71
 
 
72
 
    public function tearDown()
73
 
    {
74
 
        $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
75
 
        foreach ($turba_shares->listShares('test@example.com') as $share) {
76
 
            $turba_shares->removeShare($share);
77
 
        }
78
 
        $GLOBALS['injector']->setInstance('Turba_Factory_Addressbooks', null);
79
 
        parent::tearDown();
80
 
    }
81
 
 
82
 
    public function testCreateDefaultShare()
83
 
    {
84
 
        $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
85
 
        $GLOBALS['conf']['share']['auto_create'] = true;
86
 
        Turba::getConfigFromShares(array('test' => array('use_shares' => true)));
87
 
        $this->assertEquals(
88
 
            1, count($turba_shares->listShares('test@example.com'))
89
 
        );
90
 
    }
91
 
 
92
 
    public function testDefaultShareName()
93
 
    {
94
 
        $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
95
 
        $GLOBALS['conf']['share']['auto_create'] = true;
96
 
        Turba::getConfigFromShares(array('test' => array('use_shares' => true)));
97
 
        $shares = $turba_shares->listShares('test@example.com');
98
 
        $default = array_pop($shares);
99
 
        $this->assertInstanceOf('Horde_Share_Object', $default);
100
 
        $this->assertEquals(
101
 
            $this->default_name,
102
 
            $default->get('name')
103
 
        );
104
 
    }
105
 
 
106
 
    public function testNoAutoCreate()
107
 
    {
108
 
        $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
109
 
        $GLOBALS['conf']['share']['auto_create'] = false;
110
 
        Turba::getConfigFromShares(array('test' => array('use_shares' => true)));
111
 
        $this->assertEquals(
112
 
            0, count($turba_shares->listShares('test@example.com'))
113
 
        );
114
 
    }
115
 
 
116
 
    public function testDefaultShareDeletePermission()
117
 
    {
118
 
        $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
119
 
        $GLOBALS['conf']['share']['auto_create'] = true;
120
 
        Turba::getConfigFromShares(array('test' => array('use_shares' => true)));
121
 
        $shares = $turba_shares->listShares('test@example.com');
122
 
        $default = array_pop($shares);
123
 
        $this->assertInstanceOf('Horde_Share_Object', $default);
124
 
        $this->assertTrue(
125
 
            $default->hasPermission(
126
 
                $GLOBALS['registry']->getAuth(), Horde_Perms::DELETE
127
 
            )
128
 
        );
129
 
    }
130
 
 
131
 
}