1: <?php
2: /**
3: * Generates test database connectors.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Test
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL
11: * @link http://www.horde.org/components/Horde_Test
12: */
13:
14: /**
15: * Generates test database connectors.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @since Horde_Test 1.2.0
23: *
24: * @category Horde
25: * @package Test
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL
28: * @link http://www.horde.org/components/Horde_Test
29: */
30: class Horde_Test_Factory_Share
31: {
32: /**
33: * The injector.
34: *
35: * @var Horde_Injector
36: */
37: private $_injector;
38:
39: /**
40: * Constructor.
41: *
42: * @param Horde_Injector $injector The injector.
43: */
44: public function __construct(Horde_Injector $injector)
45: {
46: $this->_injector = $injector;
47: }
48:
49: /**
50: * Create a SQL next generate share setup.
51: *
52: * @params array $params Additional options.
53: * <pre>
54: * 'app' - (string) The application name.
55: * 'user' - (string) The current user.
56: * </pre>
57: *
58: * @return Horde_Share_Sqlng The share setup.
59: */
60: public function create($params)
61: {
62: $shares = $this->_createShares('Horde_Share_Sqlng', $params);
63: try {
64: $db = $this->_injector->getInstance('Horde_Db_Adapter');
65: } catch (Exception $e) {
66: throw new Horde_Test_Exception(
67: sprintf(
68: 'Failed creating the "Horde_Db_Adapter" service: %s',
69: $e->getMessage()
70: )
71: );
72: }
73: $shares->setStorage($db);
74: return $shares;
75: }
76:
77: /**
78: * Create a Kolab share setup.
79: *
80: * @params array $params Additional options.
81: * <pre>
82: * 'app' - (string) The application name.
83: * 'user' - (string) The current user.
84: * </pre>
85: *
86: * @return Horde_Share_Sqlng The share setup.
87: */
88: public function createKolab($params)
89: {
90: $shares = $this->_createShares('Horde_Share_Kolab', $params);
91: try {
92: $storage = $this->_injector->getInstance('Horde_Kolab_Storage');
93: } catch (Exception $e) {
94: throw new Horde_Test_Exception(
95: sprintf(
96: 'Failed creating the "Horde_Kolab_Storage" service: %s',
97: $e->getMessage()
98: )
99: );
100: }
101: $shares->setStorage($storage);
102: return $shares;
103: }
104:
105: /**
106: * Create the share handler.
107: *
108: * @param string $class Class name of the share handler.
109: * @param array $params Additional options.
110: *
111: * @return mixed The share handler.
112: */
113: private function _createShares($class, $params)
114: {
115: if (!class_exists($class)) {
116: throw new Horde_Test_Exception("The \"$class\" class is unavailable!");
117: }
118: try {
119: $perms = $this->_injector->getInstance('Horde_Perms');
120: } catch (Exception $e) {
121: throw new Horde_Test_Exception(
122: sprintf(
123: 'Failed creating the "Horde_Perms" service: %s',
124: $e->getMessage()
125: )
126: );
127: }
128: try {
129: $group = $this->_injector->getInstance('Horde_Group');
130: } catch (Exception $e) {
131: throw new Horde_Test_Exception(
132: sprintf(
133: 'Failed creating the "Horde_Group" service: %s',
134: $e->getMessage()
135: )
136: );
137: }
138: return new $class($params['app'], $params['user'], $perms, $group);
139: }
140: }