| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * admin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @category    Tollwerk | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @package     Tollwerk\Admin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @subpackage  Tollwerk\Admin\Tests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author      Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license     http://opensource.org/licenses/MIT The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /*********************************************************************************** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  *  The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  *  Permission is hereby granted, free of charge, to any person obtaining a copy of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  *  this software and associated documentation files (the "Software"), to deal in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  *  the Software without restriction, including without limitation the rights to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  *  the Software, and to permit persons to whom the Software is furnished to do so, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  *  subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  *  The above copyright notice and this permission notice shall be included in all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  *  copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  ***********************************************************************************/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | namespace Tollwerk\Admin\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use mikehaertl\shellcommand\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use Tollwerk\Admin\Infrastructure\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | use Tollwerk\Admin\Infrastructure\Shell\Binary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * Command line tool tests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * @package Tollwerk\Admin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  * @subpackage Tollwerk\Admin\Tests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | class CliTest extends AbstractDatabaseTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * Admin CLI interface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     protected static $admincli; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * Home directory base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     protected static $homebase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * Temporary directories | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     protected static $tmpDirectories = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * This method is called before the first test of this test class is run. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     public static function setUpBeforeClass() | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         self::$admincli = | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'tollwerk-admin.php'; | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         // TODO: Make environment dependent | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         self::$homebase = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR; | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         // Ensure the account system group exists | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         App::bootstrap(); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         $command = Binary::sudo('groupadd'); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         $command->addArg('-f'); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         $command->addArg(App::getConfig('general.group')); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         if (!$command->execute()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |             echo $command->getOutput().' ('.$command->getExitCode().')'.PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |             throw new \RuntimeException($command->getOutput(), $command->getExitCode()); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * Performs operation returned by getTearDownOperation(). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     public function tearDown() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         parent::tearDown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         // Remove all temporary directories | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         foreach (self::$tmpDirectories as $tmpDirectory) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             Binary::sudo('rm')->addArg('-Rf')->addArg($tmpDirectory)->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * Test creating, modifying and deleting an account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     public function testAccount() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         // Create an account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:create')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $this->assertEquals(1, $this->getConnection()->getRowCount('account')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $queryTable = $this->getConnection()->createQueryTable('account', 'SELECT * FROM account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $expectedTable = $this->getFixtureDataSet('account_create.xml')->getTable('account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $this->assertDirectoryExists(self::$homebase.'test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $this->assertUserExists('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         // Enable the account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:enable')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $queryTable = $this->getConnection()->createQueryTable('account', 'SELECT * FROM account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $expectedTable = $this->getFixtureDataSet('account_enable.xml')->getTable('account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         // Disable the account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:disable')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $queryTable = $this->getConnection()->createQueryTable('account', 'SELECT * FROM account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $expectedTable = $this->getFixtureDataSet('account_create.xml')->getTable('account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         // Rename the account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:rename')->addArg('test')->addArg('renamed')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $queryTable = $this->getConnection()->createQueryTable('account', 'SELECT * FROM account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $expectedTable = $this->getFixtureDataSet('account_rename.xml')->getTable('account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $this->assertDirectoryExists(self::$homebase.'renamed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->assertDirectoryNotExists(self::$homebase.'test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $this->assertUserExists('renamed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $this->assertUserNotExists('tests'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         // Delete the account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:delete')->addArg('renamed')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $this->assertEquals(0, $this->getConnection()->getRowCount('account')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $this->assertDirectoryExists(self::$homebase.'renamed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         $this->assertUserNotExists('renamed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         // Register home directory for removal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         self::$tmpDirectories[] = self::$homebase.'renamed'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * Test creating, modifying and deleting a domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     public function testDomain() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         // Create an account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:create')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         // Create a domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:create')->addArg('test')->addArg('example.com') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $this->assertEquals(1, $this->getConnection()->getRowCount('domain')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $expectedTable = $this->getFixtureDataSet('domain_create.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         // Enable the domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:enable')->addArg('example.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $expectedTable = $this->getFixtureDataSet('domain_enable.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         // Enable the domain wildcard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:enable:wildcard')->addArg('example.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $expectedTable = $this->getFixtureDataSet('domain_enable_wildcard.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         // Disable the domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:disable')->addArg('example.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $expectedTable = $this->getFixtureDataSet('domain_disable.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         // Disable the domain wildcard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:disable:wildcard')->addArg('example.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $expectedTable = $this->getFixtureDataSet('domain_create.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         // Delete the domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:delete')->addArg('example.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         $this->assertEquals(0, $this->getConnection()->getRowCount('domain')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         // Delete the account and the home directory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:delete')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $this->assertEquals(0, $this->getConnection()->getRowCount('account')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         $this->assertUserNotExists('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         self::$tmpDirectories[] = self::$homebase.'test'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      * Test creating, modifying and deleting a virtual host | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |     public function testVhost() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         // Create an account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:create')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         // Create two domains | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:create')->addArg('test')->addArg('example.com') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('domain:create')->addArg('test')->addArg('test.com')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $this->assertEquals(2, $this->getConnection()->getRowCount('domain')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create_domain.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         // Create a virtual host | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:create')->addArg('test')->addArg('example.com') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         $this->assertEquals(1, $this->getConnection()->getRowCount('vhost')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         $queryTable = $this->getConnection()->createQueryTable('vhost', 'SELECT * FROM vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create.xml')->getTable('vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         // Enable the vhost | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:enable')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         $queryTable = $this->getConnection()->createQueryTable('vhost', 'SELECT * FROM vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_enable.xml')->getTable('vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         // Disable the vhost | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:disable')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         $queryTable = $this->getConnection()->createQueryTable('vhost', 'SELECT * FROM vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create.xml')->getTable('vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         // Configure PHP, the HTTP and the HTTPS ports, the redirect URL and status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:php')->addArg('test')->addArg('/')->addArg('7.0') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:port:http')->addArg('test')->addArg('/')->addArg('81') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:port:https')->addArg('test')->addArg('/')->addArg('444') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:redirect')->addArg('test')->addArg('/') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |             ->addArg('http://test.com')->addArg('302')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $queryTable = $this->getConnection()->createQueryTable('vhost', 'SELECT * FROM vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_php_ports_redirect.xml')->getTable('vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         // Reset PHP, the HTTP and the HTTPS ports, the redirect URL and status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:php')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:port:http')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:port:https')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:redirect')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         $queryTable = $this->getConnection()->createQueryTable('vhost', 'SELECT * FROM vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create.xml')->getTable('vhost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         // Add a secondary domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:domain:add')->addArg('test')->addArg('test.com') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_domain_add.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         // Remove a secondary domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:domain:remove')->addArg('test')->addArg('test.com') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |             ->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         // Delete the virtual host | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('vhost:delete')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         $this->assertEquals(0, $this->getConnection()->getRowCount('vhost')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         $queryTable = $this->getConnection()->createQueryTable('domain', 'SELECT * FROM domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         $expectedTable = $this->getFixtureDataSet('vhost_create_domain.xml')->getTable('domain'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         $this->assertTablesEqual($expectedTable, $queryTable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         // Delete the account and the home directory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |         $this->assertTrue($this->getAdminCmd()->addArg('account:delete')->addArg('test')->execute()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         $this->assertEquals(0, $this->getConnection()->getRowCount('account')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         $this->assertUserNotExists('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         self::$tmpDirectories[] = self::$homebase.'test'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      * Returns the test dataset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |      * @return \PHPUnit_Extensions_Database_DataSet_IDataSet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     protected function getDataSet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         return $this->createMySQLXMLDataSet( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |             __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'admin_test_cli.xml' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |      * Create and return an admin base command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |      * @return Command Admin base command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |     protected function getAdminCmd() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         $command = new Command(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |         $command->setCommand(Binary::get('php')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         $command->addArg(self::$admincli); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         return $command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |      * Assert that a system user exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      * @param string $user User name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     protected function assertUserExists($user) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |         $command = new Command(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         $command->setCommand(Binary::get('id')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         $command->addArg($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         return $command->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |      * Assert that a system user doesn't exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |      * @param string $user User name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |     protected function assertUserNotExists($user) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |         $command = new Command(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $command->setCommand(Binary::get('id')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         $command->addArg($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         return !$command->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 342 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 343 |  |  |  |