/** * Tests to see if the language deletion is working correctly */ public function testDeleteLanguage() { $this->objFromFixture('Member', 'admin')->login(); //Login admin //Try deleting a default language $response = $this->getAMFResponse('Administration.deleteLanguage', array('id' => SnippetLanguage::get()->filter('Name', 'PHP')->first()->ID)); //Validate the response $this->assertEquals('EROR', $response['status'], 'Response status should have been EROR'); $this->assertEquals(_t('CodeBankAPI.LANGUAGE_DELETE_ERROR', '_Language cannot be deleted, it is either not a user language or has snippets attached to it'), $response['message'], 'Response message should have been that the language is not a user language or has children'); //Create a test language $lang = new SnippetLanguage(); $lang->Name = 'API Language'; $lang->FileExtension = 'api'; $lang->UserLanguage = true; $lang->write(); //Create a snippet for the language $snippet = new Snippet(); $snippet->Title = 'test snippet'; $snippet->Text = 'Hello World'; $snippet->LanguageID = $lang->ID; $snippet->write(); //Try deleting a the language $response = $this->getAMFResponse('Administration.deleteLanguage', array('id' => $lang->ID)); //Validate the response $this->assertEquals('EROR', $response['status'], 'Response status should have been EROR'); $this->assertEquals(_t('CodeBankAPI.LANGUAGE_DELETE_ERROR', '_Language cannot be deleted, it is either not a user language or has snippets attached to it'), $response['message'], 'Response message should have been that the language is not a user language or has children'); //Delete the snippet and try again $snippet->delete(); $response = $this->getAMFResponse('Administration.deleteLanguage', array('id' => $lang->ID)); //Validate the response $this->assertEquals('HELO', $response['status'], 'Response status should have been HELO'); }