/**
  * @dataProvider addFieldProvider
  */
 public function testAddField($type, $columnType, $length, $internalType)
 {
     static::$_table->addField('New field', $type);
     $id = static::$_table->getLastInsertValue();
     $table = static::$_nada->getTable('accountinfo');
     $column = $table->getColumn('fields_' . $id);
     // Reset table before any assertions
     $table->dropColumn($column->getName());
     $this->assertEquals($columnType, $column->getDatatype());
     $this->assertThat($column->getLength(), $length);
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($this->_loadDataSet('AddField'));
     $dataSet->addFullReplacement("##ID##", $id);
     $dataSet->addFullReplacement("##TYPE##", $internalType);
     $this->assertTablesEqual($dataSet->getTable('accountinfo_config'), $this->getConnection()->createQueryTable('accountinfo_config', 'SELECT id, name, type, account_type, show_order FROM accountinfo_config'));
 }
예제 #2
0
파일: user_test.php 프로젝트: jamesmcq/elis
 /**
  * Test that a record can be modified, and that the corresponding Moodle
  * user is modified.
  */
 public function test_canupdaterecordandsynctomoodle()
 {
     global $DB;
     require_once elispm::lib('lib.php');
     $this->load_csv_data();
     // Read a record.
     $src = new user(103, null, array(), false, array());
     $src->reset_custom_field_list();
     // Modify the data.
     $src->firstname = 'Testuser';
     $src->lastname = 'One';
     $src->field_sometext = 'boo';
     $src->field_sometextfrompm = 'bla';
     $src->save();
     // Read it back.
     $retr = new user($src->id, null, array(), false, array());
     $this->assertEquals($src->firstname, $retr->firstname);
     $this->assertEquals($src->lastname, $retr->lastname);
     // Check the Moodle user.
     $retr = $DB->get_record('user', array('id' => 100));
     profile_load_data($retr);
     fix_moodle_profile_fields($retr);
     $this->assertEquals($src->firstname, $retr->firstname);
     $this->assertEquals($src->lastname, $retr->lastname);
     // Check custom fields.
     $result = new moodle_recordset_phpunit_datatable('user_info_data', $DB->get_records('user_info_data', null, '', 'id, userid, fieldid, data'));
     $dataset = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
     $dataset->addTable('user_info_data', elispm::file('tests/fixtures/user_info_data.csv'));
     $dataset = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($dataset);
     // Only the second text field should be changed; everything else should be the same.
     $dataset->addFullReplacement('Second text entry field', 'bla');
     $this->assertTablesEqual($dataset->getTable('user_info_data'), $result);
 }
예제 #3
0
 /**
  * @dataProvider addFieldProvider
  */
 public function testAddField($type, $columnType, $length, $internalType)
 {
     static::$_table->addField('New field', $type);
     // getLastInsertValue() is not portable. Query database instead. The
     // name filter is sufficient for this particular test case.
     $id = static::$_table->select(array('name' => 'New field'))->current()['id'];
     $table = static::$_nada->getTable('accountinfo');
     $column = $table->getColumn('fields_' . $id);
     // Reset table before any assertions
     $table->dropColumn($column->getName());
     $this->assertEquals($columnType, $column->getDatatype());
     $this->assertThat($column->getLength(), $length);
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($this->_loadDataSet('AddField'));
     $dataSet->addFullReplacement("##ID##", $id);
     $dataSet->addFullReplacement("##TYPE##", $internalType);
     $this->assertTablesEqual($dataSet->getTable('accountinfo_config'), $this->getConnection()->createQueryTable('accountinfo_config', 'SELECT id, name, type, account_type, show_order FROM accountinfo_config'));
 }
예제 #4
0
 /**
  * @dataProvider createGroupProvider
  */
 public function testCreateGroup($description, $expectedDescription)
 {
     $model = $this->_getModel(array('Database\\Table\\GroupInfo' => $this->_groupInfo, 'Library\\Now' => new \DateTime('2015-02-12 22:07:00')));
     $model->createGroup('name3', $description);
     $table = static::$serviceManager->get('Database\\Table\\ClientsAndGroups');
     $id = $table->select(array('name' => 'name3', 'deviceid' => '_SYSTEMGROUP_'))->current()['id'];
     $dataSet = new \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($this->_loadDataSet('CreateGroup'));
     $dataSet->addFullReplacement('#ID#', $id);
     $dataSet->addFullReplacement('#DESCRIPTION#', $expectedDescription);
     $connection = $this->getConnection();
     $this->assertTablesEqual($dataSet->getTable('hardware'), $connection->createQueryTable('hardware', 'SELECT id, deviceid, name, description, lastdate FROM hardware'));
     $this->assertTablesEqual($dataSet->getTable('groups'), $connection->createQueryTable('groups', 'SELECT hardware_id, request, create_time, revalidate_from FROM groups'));
 }
예제 #5
0
 /**
  * Test buildPackage() method
  *
  * @param string $platform Internal platform descriptor (windows, linux, mac)
  * @param mixed $platformValue Database identifier (WINDOWS, LINUX, MacOSX)
  * @param string $content File content to validate (NULL to simulate no source file and no archive)
  * @param bool $createArchive Create archive, otherwise source file is assumed to be archive
  * @param string $hash Expected hash
  * @param integer $size Expected size
  * @param bool $deleteSource Passed to buildPackage()
  * @param bool $deleteArchive Expected argument for StorageInterface::write()
  * @dataProvider buildPackageProvider
  */
 public function testBuild($platform, $platformValue, $content, $createArchive, $hash, $size, $deleteSource, $deleteArchive)
 {
     // vfsStream is difficult to set up from a data provider, so the files are created here.
     $root = vfsStream::setup('root');
     if ($content) {
         if ($createArchive) {
             $fileLocation = 'source_file';
             $archive = vfsStream::newFile('archive')->withContent($content)->at($root)->url();
         } else {
             $fileLocation = vfsStream::newFile('test')->withContent($content)->at($root)->url();
             $archive = $fileLocation;
         }
     } else {
         $fileLocation = '';
         $archive = '';
     }
     // Input data. More fields are added and tested internally
     $data = array('Id' => 1423401452, 'Platform' => $platform, 'Name' => 'package_new', 'Priority' => '7', 'Comment' => 'New package', 'FileLocation' => $fileLocation);
     // Callback to test the static part of package data (input values)
     $checkStaticData = function ($testData) use($data) {
         unset($testData['Hash']);
         unset($testData['Size']);
         return $testData === $data;
     };
     // Callback to test the added file properties
     $checkFileProperties = function ($testData) use($hash, $size) {
         return $testData['Hash'] === $hash and $testData['Size'] === $size;
     };
     // Storage mock
     $storage = $this->createMock('Model\\Package\\Storage\\Direct');
     $storage->expects($this->once())->method('prepare')->with($this->callback($checkStaticData))->willReturn('Path');
     $storage->expects($this->once())->method('write')->with($this->logicalAnd($this->callback($checkStaticData), $this->callback($checkFileProperties)), $archive, $deleteArchive)->willReturn(23);
     $packages = static::$serviceManager->get('Database\\Table\\Packages');
     $serviceManager = $this->createMock('Zend\\ServiceManager\\ServiceManager');
     $serviceManager->method('get')->willReturnMap(array(array('Database\\Table\\Packages', $packages), array('Library\\Now', new \DateTime('2015-02-08 14:17:32')), array('Model\\Package\\Storage\\Direct', $storage)));
     // Model mock
     $model = $this->getMockBuilder($this->_getClass())->setMethods(array('packageExists', 'autoArchive', 'deletePackage'))->setConstructorArgs(array($serviceManager))->getMock();
     $model->expects($this->once())->method('packageExists')->willReturn(false);
     $model->expects($this->once())->method('autoArchive')->with($this->callback($checkStaticData), 'Path', $deleteSource)->willReturn($archive);
     $model->expects($this->never())->method('deletePackage');
     // Invoke buildPackage method
     $model->buildPackage($data, $deleteSource);
     // Test database results
     $connection = $this->getConnection();
     $dataset = new \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($this->_loadDataSet('Build'));
     $dataset->addFullReplacement('#PLATFORM#', $platformValue);
     $dataset->addFullReplacement('#SIZE#', $size);
     $this->assertTablesEqual($dataset->getTable('download_available'), $connection->createQueryTable('download_available', 'SELECT * FROM download_available ORDER BY fileid'));
     $this->assertTablesEqual($dataset->getTable('download_enable'), $connection->createQueryTable('download_enable', 'SELECT fileid, info_loc, pack_loc FROM download_enable ORDER BY fileid'));
 }